Started reworking CharacterClass to use variant vector properties.

This commit is contained in:
Relintai 2019-09-08 21:26:05 +02:00
parent 1f83d7ac6c
commit e070031073
2 changed files with 65 additions and 71 deletions

View File

@ -47,66 +47,83 @@ void CharacterClass::set_stat_data(Ref<StatData> 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<Spell> CharacterClass::get_spell(int index) {
ERR_FAIL_INDEX_V(index, _spells.size(), Ref<Spell>());
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<Spell> CharacterClass::get_spell(int id) {
ERR_FAIL_INDEX_V(id, MAX_SPELLS, Ref<Spell>());
return _spells[id];
}
void CharacterClass::set_spell(int index, Ref<Spell> spell) {
ERR_FAIL_INDEX(index, MAX_SPELLS);
ERR_FAIL_INDEX(index, _spells.size());
_spells[index] = Ref<Spell>(spell);
_spells.set(index, Ref<Spell>(spell));
}
Vector<Variant> CharacterClass::get_spells() {
Vector<Variant> 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<Variant> &spells) {
_spells.clear();
for (int i = 0; i < spells.size(); i++) {
Ref<Spell> spell = Ref<Spell>(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<CharacterSpec> CharacterClass::get_spec(int index) const {
ERR_FAIL_INDEX_V(index, MAX_SPECS, Ref<CharacterSpec>());
ERR_FAIL_INDEX_V(index, _specs.size(), Ref<CharacterSpec>());
return _specs[index];
}
void CharacterClass::set_spec(int index, Ref<CharacterSpec> spec) {
ERR_FAIL_INDEX(index, MAX_SPECS);
ERR_FAIL_INDEX(index, _specs.size());
_specs[index] = Ref<CharacterSpec>(spec);
_specs.set(index, Ref<CharacterSpec>(spec));
}
Vector<Variant> CharacterClass::get_specs() {
Vector<Variant> 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<Variant> &specs) {
_specs.clear();
for (int i = 0; i < specs.size(); i++) {
Ref<Spell> spec = Ref<Spell>(specs[i]);
_specs.push_back(spec);
}
}
Ref<Aura> CharacterClass::get_aura(int index) {
ERR_FAIL_INDEX_V(index, MAX_AURAS, Ref<Aura>());
ERR_FAIL_INDEX_V(index, _auras.size(), Ref<Aura>());
return _auras[index];
}
void CharacterClass::set_aura(int index, Ref<Aura> 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);

View File

@ -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<Spell> get_spell(int index);
void set_spell(int index, Ref<Spell> spell);
Vector<Variant> get_spells();
void set_spells(const Vector<Variant> &spells);
int get_num_specs();
void set_num_specs(int value);
Ref<CharacterSpec> get_spec(int index) const;
void set_spec(int index, Ref<CharacterSpec> spec);
Vector<Variant> get_specs();
void set_specs(const Vector<Variant> &specs);
int get_num_auras();
void set_num_auras(int value);
Ref<Aura> get_aura(int index);
void set_aura(int index, Ref<Aura> aura);
Vector<Variant> get_auras();
void set_auras(const Vector<Variant> &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<StatData> _stat_data;
int _num_spells;
int _current_spell_page;
Ref<Spell> _spells[MAX_SPELLS];
int _num_specs;
Ref<CharacterSpec> _specs[MAX_SPECS];
Ref<Aura> _auras[MAX_AURAS];
Vector<Ref<Spell> > _spells;
Vector<Ref<CharacterSpec> > _specs;
Vector<Ref<Aura> > _auras;
//Vector<int> _mob_party_ids;
//Vector<int> _mob_dislike_ids;