diff --git a/data/species/entity_species_data.cpp b/data/species/entity_species_data.cpp index 3a22268..80bebcc 100644 --- a/data/species/entity_species_data.cpp +++ b/data/species/entity_species_data.cpp @@ -48,11 +48,49 @@ void EntitySpeciesData::set_text_description(const String &value) { _text_description = value; } -Ref EntitySpeciesData::get_model_data() { - return _model_data; +//ModelData + +Ref EntitySpeciesData::get_model_data(const int index) const { + ERR_FAIL_INDEX_V(index, _model_datas.size(), Ref()); + + return _model_datas.get(index); } -void EntitySpeciesData::set_model_data(const Ref &data) { - _model_data = data; +void EntitySpeciesData::set_model_data(const int index, const Ref &model_data) { + ERR_FAIL_INDEX(index, _model_datas.size()); + + _model_datas.set(index, model_data); +} +void EntitySpeciesData::add_model_data(const Ref &model_data) { + _model_datas.push_back(model_data); +} +void EntitySpeciesData::remove_model_data(const int index) { + ERR_FAIL_INDEX(index, _model_datas.size()); + + _model_datas.remove(index); +} + +int EntitySpeciesData::get_model_data_count() const { + return _model_datas.size(); +} + +Vector EntitySpeciesData::get_model_datas() { + Vector r; + for (int i = 0; i < _model_datas.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_model_datas[i].get_ref_ptr()); +#else + r.push_back(_model_datas[i]); +#endif + } + return r; +} +void EntitySpeciesData::set_model_datas(const Vector &model_datas) { + _model_datas.clear(); + for (int i = 0; i < model_datas.size(); i++) { + Ref model_data = Ref(model_datas[i]); + + _model_datas.push_back(model_data); + } } //Spells @@ -158,7 +196,7 @@ EntitySpeciesData::EntitySpeciesData() { _type = 0; } EntitySpeciesData::~EntitySpeciesData() { - _model_data.unref(); + _model_datas.clear(); _spells.clear(); _auras.clear(); @@ -189,9 +227,17 @@ void EntitySpeciesData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_text_description", "value"), &EntitySpeciesData::set_text_description); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_description"), "set_text_description", "get_text_description"); - ClassDB::bind_method(D_METHOD("get_model_data"), &EntitySpeciesData::get_model_data); - ClassDB::bind_method(D_METHOD("set_model_data", "value"), &EntitySpeciesData::set_model_data); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "model_data", PROPERTY_HINT_RESOURCE_TYPE, "SpeciesModelData"), "set_model_data", "get_model_data"); + //ModelData + ClassDB::bind_method(D_METHOD("get_model_data", "index"), &EntitySpeciesData::get_model_data); + ClassDB::bind_method(D_METHOD("set_model_data", "index", "data"), &EntitySpeciesData::set_model_data); + ClassDB::bind_method(D_METHOD("add_model_data", "model_data"), &EntitySpeciesData::add_model_data); + ClassDB::bind_method(D_METHOD("remove_model_data", "index"), &EntitySpeciesData::remove_model_data); + + ClassDB::bind_method(D_METHOD("get_model_data_count"), &EntitySpeciesData::get_model_data_count); + + ClassDB::bind_method(D_METHOD("get_model_datas"), &EntitySpeciesData::get_model_datas); + ClassDB::bind_method(D_METHOD("set_model_datas", "model_datas"), &EntitySpeciesData::set_model_datas); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "model_datas", PROPERTY_HINT_NONE, "17/17:SpeciesModelData", PROPERTY_USAGE_DEFAULT, "SpeciesModelData"), "set_model_datas", "get_model_datas"); //Spells ClassDB::bind_method(D_METHOD("get_spell", "index"), &EntitySpeciesData::get_spell); diff --git a/data/species/entity_species_data.h b/data/species/entity_species_data.h index aa6c94b..3304333 100644 --- a/data/species/entity_species_data.h +++ b/data/species/entity_species_data.h @@ -47,8 +47,16 @@ public: String get_text_description() const; void set_text_description(const String &value); - Ref get_model_data(); - void set_model_data(const Ref &data); + //ModelData + Ref get_model_data(const int index) const; + void set_model_data(const int index, const Ref &data); + void add_model_data(const Ref &data); + void remove_model_data(const int index); + + int get_model_data_count() const; + + Vector get_model_datas(); + void set_model_datas(const Vector &datas); //Spells Ref get_spell(const int index) const; @@ -86,8 +94,7 @@ private: int _type; String _text_description; - Ref _model_data; - + Vector > _model_datas; Vector > _spells; Vector > _auras; }; diff --git a/entities/entity.cpp b/entities/entity.cpp index 9e530ec..4f3fe57 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -474,9 +474,10 @@ void Entity::sets_entity_data(Ref value) { //setup(); if (get_body() == NULL && value.is_valid() && value->get_entity_species_data().is_valid() && - value->get_entity_species_data()->get_model_data().is_valid() && - value->get_entity_species_data()->get_model_data()->get_body().is_valid()) { - Node *node = value->get_entity_species_data()->get_model_data()->get_body()->instance(); + value->get_entity_species_data()->get_model_data_count() > _s_gender && + value->get_entity_species_data()->get_model_data(_s_gender).is_valid() && + value->get_entity_species_data()->get_model_data(_s_gender)->get_body().is_valid()) { + Node *node = value->get_entity_species_data()->get_model_data(_s_gender)->get_body()->instance(); add_child(node); set_body(node); @@ -495,9 +496,10 @@ void Entity::setc_entity_data(Ref value) { _c_entity_data = value; if (get_body() == NULL && value.is_valid() && value->get_entity_species_data().is_valid() && - value->get_entity_species_data()->get_model_data().is_valid() && - value->get_entity_species_data()->get_model_data()->get_body().is_valid()) { - Node *node = value->get_entity_species_data()->get_model_data()->get_body()->instance(); + value->get_entity_species_data()->get_model_data_count() > _c_gender && + value->get_entity_species_data()->get_model_data(_c_gender).is_valid() && + value->get_entity_species_data()->get_model_data(_c_gender)->get_body().is_valid()) { + Node *node = value->get_entity_species_data()->get_model_data(_c_gender)->get_body()->instance(); add_child(node); set_body(node); diff --git a/singletons/ess.cpp b/singletons/ess.cpp index 0189c1f..cd10141 100644 --- a/singletons/ess.cpp +++ b/singletons/ess.cpp @@ -438,6 +438,14 @@ void ESS::skeletons_bones_set(const PoolStringArray &value) { _skeletons_bones = value; } +//ModelVisualGroups +String ESS::model_visual_groups_get() const { + return _model_visual_groups; +} +void ESS::model_visual_groups_set(const String &value) { + _model_visual_groups = value; +} + void ESS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_use_spell_points"), &ESS::get_use_spell_points); ClassDB::bind_method(D_METHOD("set_use_spell_points", "value"), &ESS::set_use_spell_points); @@ -559,6 +567,11 @@ void ESS::_bind_methods() { ClassDB::bind_method(D_METHOD("skeletons_bones_get"), &ESS::skeletons_bones_get); ClassDB::bind_method(D_METHOD("skeletons_bones_set", "value"), &ESS::skeletons_bones_set); ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "skeletons_bones"), "skeletons_bones_set", "skeletons_bones_get"); + + //ModelVisualGroups + ClassDB::bind_method(D_METHOD("model_visual_groups_get"), &ESS::model_visual_groups_get); + ClassDB::bind_method(D_METHOD("model_visual_groups_set", "value"), &ESS::model_visual_groups_set); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "model_visual_groups"), "model_visual_groups_set", "model_visual_groups_get"); } ESS::ESS() { @@ -589,6 +602,8 @@ ESS::ESS() { _entity_types = GLOBAL_DEF("ess/enums/entity_types", "None,Creature,Totem,Idol,Humanoid,Mechanical,Beast,Dragonkin,Elemental,Ghost,Energy,Anomaly,Demon,Object"); _skeletons_bones = GLOBAL_DEF("ess/enums/skeletons_bones", PoolStringArray()); + _model_visual_groups = GLOBAL_DEF("ess/enums/model_visual_groups", "None,Bodypart,Alt Bodypart,Attachment"); + if (!Engine::get_singleton()->is_editor_hint() && _automatic_load) { call_deferred("load_all"); } diff --git a/singletons/ess.h b/singletons/ess.h index 621367c..1ec060b 100644 --- a/singletons/ess.h +++ b/singletons/ess.h @@ -152,6 +152,10 @@ public: PoolStringArray skeletons_bones_get() const; void skeletons_bones_set(const PoolStringArray &value); + //ModelVisualGroups + String model_visual_groups_get() const; + void model_visual_groups_set(const String &value); + ESS(); ~ESS(); @@ -201,6 +205,9 @@ private: //Entity Types String _entity_types; PoolStringArray _skeletons_bones; + + //ModelVisualGroups + String _model_visual_groups; }; #endif