From e070031073a310a225e0d2e8f4d7446b5470b86f Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 8 Sep 2019 21:26:05 +0200 Subject: [PATCH] Started reworking CharacterClass to use variant vector properties. --- data/character_class.cpp | 99 +++++++++++++++++++--------------------- data/character_class.h | 37 +++++++-------- 2 files changed, 65 insertions(+), 71 deletions(-) diff --git a/data/character_class.cpp b/data/character_class.cpp index bda9b8b..aaa4dc1 100644 --- a/data/character_class.cpp +++ b/data/character_class.cpp @@ -47,66 +47,83 @@ void CharacterClass::set_stat_data(Ref value) { } int CharacterClass::get_num_spells() { - return _num_spells; + return _spells.size(); } - void CharacterClass::set_num_spells(int value) { - _num_spells = value; + _spells.resize(value); } -int CharacterClass::get_current_spell_page() { - return _current_spell_page; +Ref CharacterClass::get_spell(int index) { + ERR_FAIL_INDEX_V(index, _spells.size(), Ref()); + + return _spells[index]; } - -void CharacterClass::set_current_spell_page(int value) { - if (value < 0 || value > (int)(_num_spells / ITEMS_PER_PAGE)) { - return; - } - - _current_spell_page = value; -} - -Ref CharacterClass::get_spell(int id) { - ERR_FAIL_INDEX_V(id, MAX_SPELLS, Ref()); - - return _spells[id]; -} - void CharacterClass::set_spell(int index, Ref spell) { - ERR_FAIL_INDEX(index, MAX_SPELLS); + ERR_FAIL_INDEX(index, _spells.size()); - _spells[index] = Ref(spell); + _spells.set(index, Ref(spell)); +} + +Vector CharacterClass::get_spells() { + Vector r; + for (int i = 0; i < _spells.size(); i++) { + r.push_back(_spells[i].get_ref_ptr()); + } + return r; +} +void CharacterClass::set_spells(const Vector &spells) { + _spells.clear(); + for (int i = 0; i < spells.size(); i++) { + Ref spell = Ref(spells[i]); + + _spells.push_back(spell); + } } int CharacterClass::get_num_specs() { - return _num_specs; + return _specs.size(); } void CharacterClass::set_num_specs(int value) { - _num_specs = value; + _specs.resize(value); } Ref CharacterClass::get_spec(int index) const { - ERR_FAIL_INDEX_V(index, MAX_SPECS, Ref()); + ERR_FAIL_INDEX_V(index, _specs.size(), Ref()); return _specs[index]; } - void CharacterClass::set_spec(int index, Ref spec) { - ERR_FAIL_INDEX(index, MAX_SPECS); + ERR_FAIL_INDEX(index, _specs.size()); - _specs[index] = Ref(spec); + _specs.set(index, Ref(spec)); +} + +Vector CharacterClass::get_specs() { + Vector r; + for (int i = 0; i < _specs.size(); i++) { + r.push_back(_specs[i].get_ref_ptr()); + } + return r; +} +void CharacterClass::set_specs(const Vector &specs) { + _specs.clear(); + for (int i = 0; i < specs.size(); i++) { + Ref spec = Ref(specs[i]); + + _specs.push_back(spec); + } } Ref CharacterClass::get_aura(int index) { - ERR_FAIL_INDEX_V(index, MAX_AURAS, Ref()); + ERR_FAIL_INDEX_V(index, _auras.size(), Ref()); return _auras[index]; } void CharacterClass::set_aura(int index, Ref aura) { - ERR_FAIL_INDEX(index, MAX_AURAS); + ERR_FAIL_INDEX(index, _auras.size()); - _auras[index] = aura; + _auras.set(index, aura); } void CharacterClass::setup_resources(Entity *entity) { @@ -555,26 +572,6 @@ void CharacterClass::sai_attack_bind(Node *entity) { sai_attack(e); } -void CharacterClass::_validate_property(PropertyInfo &property) const { - - String prop = property.name; - if (prop.begins_with("Spell_")) { - int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); - if (frame >= _num_spells || frame < ITEMS_PER_PAGE * _current_spell_page || frame > ITEMS_PER_PAGE * (_current_spell_page + 1)) { - property.usage = 0; - } - } else if (prop.begins_with("Spec_")) { - int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); - if (frame >= _num_specs) { - property.usage = 0; - } - } else if (prop.begins_with("current_spell_page")) { - if (_num_spells <= ITEMS_PER_PAGE) { - property.usage = 0; - } - } -} - void CharacterClass::_bind_methods() { //EventHandlers ClassDB::bind_method(D_METHOD("son_before_cast", "info"), &CharacterClass::son_before_cast); diff --git a/data/character_class.h b/data/character_class.h index e7b1d1b..8c04487 100644 --- a/data/character_class.h +++ b/data/character_class.h @@ -52,21 +52,32 @@ public: int get_num_spells(); void set_num_spells(int value); - int get_current_spell_page(); - void set_current_spell_page(int value); - Ref get_spell(int index); void set_spell(int index, Ref spell); + Vector get_spells(); + void set_spells(const Vector &spells); + + int get_num_specs(); void set_num_specs(int value); Ref get_spec(int index) const; void set_spec(int index, Ref spec); + Vector get_specs(); + void set_specs(const Vector &specs); + + + int get_num_auras(); + void set_num_auras(int value); + Ref get_aura(int index); void set_aura(int index, Ref aura); + Vector get_auras(); + void set_auras(const Vector &auras); + void setup_resources(Entity *entity); //void _setup_resources(Entity *entity); @@ -167,15 +178,6 @@ public: protected: static void _bind_methods(); - void _validate_property(PropertyInfo &property) const; - -public: - enum { - MAX_SPELLS = 100, - MAX_SPECS = 5, - MAX_AURAS = 5, - ITEMS_PER_PAGE = 100, - }; private: int _id; @@ -186,14 +188,9 @@ private: Ref _stat_data; - int _num_spells; - int _current_spell_page; - Ref _spells[MAX_SPELLS]; - - int _num_specs; - Ref _specs[MAX_SPECS]; - - Ref _auras[MAX_AURAS]; + Vector > _spells; + Vector > _specs; + Vector > _auras; //Vector _mob_party_ids; //Vector _mob_dislike_ids;