mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-11 22:42:10 +02:00
Improvements to the EssResourceDB's api, also add a missing bind to the ESS singleton.
This commit is contained in:
parent
6c9bea09bc
commit
b5ed3b16c8
@ -48,6 +48,50 @@ void ESSResourceDB::set_xp_data(const Ref<XPData> &data) {
|
|||||||
_xp_data = data;
|
_xp_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESSResourceDB::clear() {
|
||||||
|
_xp_data.unref();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESSResourceDB::add_entity_resource_db(Ref<ESSResourceDB> other) {
|
||||||
|
if (!other.is_valid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_xp_data.is_valid() && other->_xp_data.is_valid())
|
||||||
|
_xp_data = other->_xp_data;
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_entity_resource_count(); ++i) {
|
||||||
|
add_entity_resource(other->get_entity_resource_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_entity_skill_count(); ++i) {
|
||||||
|
add_entity_skill(other->get_entity_skill_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_entity_data_count(); ++i) {
|
||||||
|
add_entity_data(other->get_entity_data_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_spell_count(); ++i) {
|
||||||
|
add_spell(other->get_spell_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_aura_count(); ++i) {
|
||||||
|
add_aura(other->get_aura_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_craft_recipe_count(); ++i) {
|
||||||
|
add_craft_recipe(other->get_craft_recipe_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_item_template_count(); ++i) {
|
||||||
|
add_item_template(other->get_item_template_index(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < other->get_entity_species_data_count(); ++i) {
|
||||||
|
add_entity_species_data(other->get_entity_species_data_index(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ESSResourceDB::initialize() {
|
void ESSResourceDB::initialize() {
|
||||||
if (has_method("_initialize"))
|
if (has_method("_initialize"))
|
||||||
call("_initialize");
|
call("_initialize");
|
||||||
@ -137,6 +181,9 @@ void ESSResourceDB::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("get_entity_species_datas"), &ESSResourceDB::get_entity_species_datas);
|
ClassDB::bind_method(D_METHOD("get_entity_species_datas"), &ESSResourceDB::get_entity_species_datas);
|
||||||
ClassDB::bind_method(D_METHOD("set_entity_species_datas", "recipe"), &ESSResourceDB::set_entity_species_datas);
|
ClassDB::bind_method(D_METHOD("set_entity_species_datas", "recipe"), &ESSResourceDB::set_entity_species_datas);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("clear"), &ESSResourceDB::clear);
|
||||||
|
ClassDB::bind_method(D_METHOD("add_entity_resource_db", "other"), &ESSResourceDB::add_entity_resource_db);
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_initialize"));
|
BIND_VMETHOD(MethodInfo("_initialize"));
|
||||||
ClassDB::bind_method(D_METHOD("initialize"), &ESSResourceDB::initialize);
|
ClassDB::bind_method(D_METHOD("initialize"), &ESSResourceDB::initialize);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,10 @@ public:
|
|||||||
virtual Vector<Variant> get_entity_species_datas() const = 0;
|
virtual Vector<Variant> get_entity_species_datas() const = 0;
|
||||||
virtual void set_entity_species_datas(const Vector<Variant> &data) = 0;
|
virtual void set_entity_species_datas(const Vector<Variant> &data) = 0;
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
void add_entity_resource_db(Ref<ESSResourceDB> other);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
ESSResourceDB();
|
ESSResourceDB();
|
||||||
|
@ -30,8 +30,15 @@ SOFTWARE.
|
|||||||
#include "../entities/resources/entity_resource_data.h"
|
#include "../entities/resources/entity_resource_data.h"
|
||||||
#include "../entities/skills/entity_skill_data.h"
|
#include "../entities/skills/entity_skill_data.h"
|
||||||
|
|
||||||
|
bool ESSResourceDBStatic::get_remap_ids() const {
|
||||||
|
return _remap_ids;
|
||||||
|
}
|
||||||
|
void ESSResourceDBStatic::set_remap_ids(const bool value) {
|
||||||
|
_remap_ids = value;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<EntityResourceData> ESSResourceDBStatic::get_entity_resource(int id) {
|
Ref<EntityResourceData> ESSResourceDBStatic::get_entity_resource(int id) {
|
||||||
if (id < 0 || id > _entity_resources.size())
|
if (id < 0 || id >= _entity_resources.size())
|
||||||
return Ref<EntityResourceData>();
|
return Ref<EntityResourceData>();
|
||||||
|
|
||||||
return _entity_resources.get(id);
|
return _entity_resources.get(id);
|
||||||
@ -45,7 +52,7 @@ int ESSResourceDBStatic::get_entity_resource_count() {
|
|||||||
return _entity_resources.size();
|
return _entity_resources.size();
|
||||||
}
|
}
|
||||||
void ESSResourceDBStatic::add_entity_resource(Ref<EntityResourceData> cls) {
|
void ESSResourceDBStatic::add_entity_resource(Ref<EntityResourceData> cls) {
|
||||||
if (cls.is_valid())
|
if (_remap_ids && cls.is_valid())
|
||||||
cls->set_id(_entity_resources.size());
|
cls->set_id(_entity_resources.size());
|
||||||
|
|
||||||
_entity_resources.push_back(cls);
|
_entity_resources.push_back(cls);
|
||||||
@ -71,7 +78,7 @@ void ESSResourceDBStatic::set_entity_resources(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ref<EntitySkillData> ESSResourceDBStatic::get_entity_skill(int id) {
|
Ref<EntitySkillData> ESSResourceDBStatic::get_entity_skill(int id) {
|
||||||
if (id < 0 || id > _entity_skills.size())
|
if (id < 0 || id >= _entity_skills.size())
|
||||||
return Ref<EntitySkillData>();
|
return Ref<EntitySkillData>();
|
||||||
|
|
||||||
return _entity_skills.get(id);
|
return _entity_skills.get(id);
|
||||||
@ -85,7 +92,7 @@ int ESSResourceDBStatic::get_entity_skill_count() {
|
|||||||
return _entity_skills.size();
|
return _entity_skills.size();
|
||||||
}
|
}
|
||||||
void ESSResourceDBStatic::add_entity_skill(Ref<EntitySkillData> cls) {
|
void ESSResourceDBStatic::add_entity_skill(Ref<EntitySkillData> cls) {
|
||||||
if (cls.is_valid())
|
if (_remap_ids && cls.is_valid())
|
||||||
cls->set_id(_entity_skills.size());
|
cls->set_id(_entity_skills.size());
|
||||||
|
|
||||||
_entity_skills.push_back(cls);
|
_entity_skills.push_back(cls);
|
||||||
@ -111,7 +118,7 @@ void ESSResourceDBStatic::set_entity_skills(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ref<EntityData> ESSResourceDBStatic::get_entity_data(int id) {
|
Ref<EntityData> ESSResourceDBStatic::get_entity_data(int id) {
|
||||||
if (id < 0 || id > _entity_datas.size())
|
if (id < 0 || id >= _entity_datas.size())
|
||||||
return Ref<EntityData>();
|
return Ref<EntityData>();
|
||||||
|
|
||||||
return _entity_datas.get(id);
|
return _entity_datas.get(id);
|
||||||
@ -125,7 +132,7 @@ int ESSResourceDBStatic::get_entity_data_count() {
|
|||||||
return _entity_datas.size();
|
return _entity_datas.size();
|
||||||
}
|
}
|
||||||
void ESSResourceDBStatic::add_entity_data(Ref<EntityData> cls) {
|
void ESSResourceDBStatic::add_entity_data(Ref<EntityData> cls) {
|
||||||
if (cls.is_valid())
|
if (_remap_ids && cls.is_valid())
|
||||||
cls->set_id(_entity_datas.size());
|
cls->set_id(_entity_datas.size());
|
||||||
|
|
||||||
_entity_datas.push_back(cls);
|
_entity_datas.push_back(cls);
|
||||||
@ -151,7 +158,7 @@ void ESSResourceDBStatic::set_entity_datas(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ref<Spell> ESSResourceDBStatic::get_spell(int id) {
|
Ref<Spell> ESSResourceDBStatic::get_spell(int id) {
|
||||||
if (id < 0 || id > _spells.size())
|
if (id < 0 || id >= _spells.size())
|
||||||
return Ref<Spell>();
|
return Ref<Spell>();
|
||||||
|
|
||||||
return _spells.get(id);
|
return _spells.get(id);
|
||||||
@ -166,7 +173,7 @@ int ESSResourceDBStatic::get_spell_count() {
|
|||||||
return _spells.size();
|
return _spells.size();
|
||||||
}
|
}
|
||||||
void ESSResourceDBStatic::add_spell(Ref<Spell> spell) {
|
void ESSResourceDBStatic::add_spell(Ref<Spell> spell) {
|
||||||
if (spell.is_valid())
|
if (_remap_ids && spell.is_valid())
|
||||||
spell->set_id(_spells.size());
|
spell->set_id(_spells.size());
|
||||||
|
|
||||||
_spells.push_back(spell);
|
_spells.push_back(spell);
|
||||||
@ -192,14 +199,14 @@ void ESSResourceDBStatic::set_spells(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESSResourceDBStatic::add_aura(Ref<Aura> aura) {
|
void ESSResourceDBStatic::add_aura(Ref<Aura> aura) {
|
||||||
if (aura.is_valid())
|
if (_remap_ids && aura.is_valid())
|
||||||
aura->set_id(_auras.size());
|
aura->set_id(_auras.size());
|
||||||
|
|
||||||
_auras.push_back(aura);
|
_auras.push_back(aura);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Aura> ESSResourceDBStatic::get_aura(int id) {
|
Ref<Aura> ESSResourceDBStatic::get_aura(int id) {
|
||||||
if (id < 0 || id > _auras.size())
|
if (id < 0 || id >= _auras.size())
|
||||||
return Ref<Aura>();
|
return Ref<Aura>();
|
||||||
|
|
||||||
return _auras.get(id);
|
return _auras.get(id);
|
||||||
@ -237,14 +244,14 @@ void ESSResourceDBStatic::set_auras(const Vector<Variant> &data) {
|
|||||||
|
|
||||||
//Craft Data
|
//Craft Data
|
||||||
void ESSResourceDBStatic::add_craft_recipe(Ref<CraftRecipe> cda) {
|
void ESSResourceDBStatic::add_craft_recipe(Ref<CraftRecipe> cda) {
|
||||||
if (cda.is_valid())
|
if (_remap_ids && cda.is_valid())
|
||||||
cda->set_id(_craft_recipes.size());
|
cda->set_id(_craft_recipes.size());
|
||||||
|
|
||||||
_craft_recipes.push_back(cda);
|
_craft_recipes.push_back(cda);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<CraftRecipe> ESSResourceDBStatic::get_craft_recipe(int id) {
|
Ref<CraftRecipe> ESSResourceDBStatic::get_craft_recipe(int id) {
|
||||||
if (id < 0 || id > _craft_recipes.size())
|
if (id < 0 || id >= _craft_recipes.size())
|
||||||
return Ref<CraftRecipe>();
|
return Ref<CraftRecipe>();
|
||||||
|
|
||||||
return _craft_recipes.get(id);
|
return _craft_recipes.get(id);
|
||||||
@ -281,14 +288,14 @@ void ESSResourceDBStatic::set_craft_recipes(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESSResourceDBStatic::add_item_template(Ref<ItemTemplate> cda) {
|
void ESSResourceDBStatic::add_item_template(Ref<ItemTemplate> cda) {
|
||||||
if (cda.is_valid())
|
if (_remap_ids && cda.is_valid())
|
||||||
cda->set_id(_item_templates.size());
|
cda->set_id(_item_templates.size());
|
||||||
|
|
||||||
_item_templates.push_back(cda);
|
_item_templates.push_back(cda);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ItemTemplate> ESSResourceDBStatic::get_item_template(int item_id) {
|
Ref<ItemTemplate> ESSResourceDBStatic::get_item_template(int item_id) {
|
||||||
if (item_id < 0 || item_id > _item_templates.size())
|
if (item_id < 0 || item_id >= _item_templates.size())
|
||||||
return Ref<ItemTemplate>();
|
return Ref<ItemTemplate>();
|
||||||
|
|
||||||
return _item_templates.get(item_id);
|
return _item_templates.get(item_id);
|
||||||
@ -324,7 +331,7 @@ void ESSResourceDBStatic::set_item_templates(const Vector<Variant> &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESSResourceDBStatic::add_entity_species_data(Ref<EntitySpeciesData> cda) {
|
void ESSResourceDBStatic::add_entity_species_data(Ref<EntitySpeciesData> cda) {
|
||||||
if (cda.is_valid())
|
if (_remap_ids && cda.is_valid())
|
||||||
cda->set_id(_entity_species_datas.size());
|
cda->set_id(_entity_species_datas.size());
|
||||||
|
|
||||||
_entity_species_datas.push_back(cda);
|
_entity_species_datas.push_back(cda);
|
||||||
@ -363,7 +370,19 @@ void ESSResourceDBStatic::set_entity_species_datas(const Vector<Variant> &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESSResourceDBStatic::clear() {
|
||||||
|
_entity_resources.clear();
|
||||||
|
_entity_skills.clear();
|
||||||
|
_entity_datas.clear();
|
||||||
|
_spells.clear();
|
||||||
|
_auras.clear();
|
||||||
|
_craft_recipes.clear();
|
||||||
|
_item_templates.clear();
|
||||||
|
_entity_species_datas.clear();
|
||||||
|
}
|
||||||
|
|
||||||
ESSResourceDBStatic::ESSResourceDBStatic() {
|
ESSResourceDBStatic::ESSResourceDBStatic() {
|
||||||
|
_remap_ids = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESSResourceDBStatic::~ESSResourceDBStatic() {
|
ESSResourceDBStatic::~ESSResourceDBStatic() {
|
||||||
@ -378,6 +397,10 @@ ESSResourceDBStatic::~ESSResourceDBStatic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESSResourceDBStatic::_bind_methods() {
|
void ESSResourceDBStatic::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("get_remap_ids"), &ESSResourceDBStatic::get_remap_ids);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_remap_ids", "value"), &ESSResourceDBStatic::set_remap_ids);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "remap_ids"), "set_remap_ids", "get_remap_ids");
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_resources", PROPERTY_HINT_NONE, "17/17:EntityResourceData", PROPERTY_USAGE_DEFAULT, "EntityResourceData"), "set_entity_resources", "get_entity_resources");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_resources", PROPERTY_HINT_NONE, "17/17:EntityResourceData", PROPERTY_USAGE_DEFAULT, "EntityResourceData"), "set_entity_resources", "get_entity_resources");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_skills", PROPERTY_HINT_NONE, "17/17:EntitySkillData", PROPERTY_USAGE_DEFAULT, "EntitySkillData"), "set_entity_skills", "get_entity_skills");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_skills", PROPERTY_HINT_NONE, "17/17:EntitySkillData", PROPERTY_USAGE_DEFAULT, "EntitySkillData"), "set_entity_skills", "get_entity_skills");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
|
||||||
|
@ -54,6 +54,9 @@ class ESSResourceDBStatic : public ESSResourceDB {
|
|||||||
GDCLASS(ESSResourceDBStatic, ESSResourceDB);
|
GDCLASS(ESSResourceDBStatic, ESSResourceDB);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool get_remap_ids() const;
|
||||||
|
void set_remap_ids(const bool value);
|
||||||
|
|
||||||
String get_xp_data_path();
|
String get_xp_data_path();
|
||||||
void set_xp_data_path(String path);
|
void set_xp_data_path(String path);
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ public:
|
|||||||
Ref<Aura> get_aura(int aura_id);
|
Ref<Aura> get_aura(int aura_id);
|
||||||
Ref<Aura> get_aura_index(int index);
|
Ref<Aura> get_aura_index(int index);
|
||||||
int get_aura_count();
|
int get_aura_count();
|
||||||
void add_aura( Ref<Aura> aura);
|
void add_aura(Ref<Aura> aura);
|
||||||
Vector<Variant> get_auras() const;
|
Vector<Variant> get_auras() const;
|
||||||
void set_auras(const Vector<Variant> &data);
|
void set_auras(const Vector<Variant> &data);
|
||||||
|
|
||||||
@ -116,6 +119,8 @@ public:
|
|||||||
Vector<Variant> get_entity_species_datas() const;
|
Vector<Variant> get_entity_species_datas() const;
|
||||||
void set_entity_species_datas(const Vector<Variant> &data);
|
void set_entity_species_datas(const Vector<Variant> &data);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
ESSResourceDBStatic();
|
ESSResourceDBStatic();
|
||||||
~ESSResourceDBStatic();
|
~ESSResourceDBStatic();
|
||||||
|
|
||||||
@ -123,14 +128,16 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Ref<EntityResourceData>> _entity_resources;
|
bool _remap_ids;
|
||||||
Vector<Ref<EntitySkillData>> _entity_skills;
|
|
||||||
Vector<Ref<EntityData>> _entity_datas;
|
Vector<Ref<EntityResourceData> > _entity_resources;
|
||||||
Vector<Ref<Spell>> _spells;
|
Vector<Ref<EntitySkillData> > _entity_skills;
|
||||||
Vector<Ref<Aura>> _auras;
|
Vector<Ref<EntityData> > _entity_datas;
|
||||||
Vector<Ref<CraftRecipe>> _craft_recipes;
|
Vector<Ref<Spell> > _spells;
|
||||||
Vector<Ref<ItemTemplate>> _item_templates;
|
Vector<Ref<Aura> > _auras;
|
||||||
Vector<Ref<EntitySpeciesData>> _entity_species_datas;
|
Vector<Ref<CraftRecipe> > _craft_recipes;
|
||||||
|
Vector<Ref<ItemTemplate> > _item_templates;
|
||||||
|
Vector<Ref<EntitySpeciesData> > _entity_species_datas;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -228,6 +228,7 @@ void ESS::_bind_methods() {
|
|||||||
|
|
||||||
//load
|
//load
|
||||||
ClassDB::bind_method(D_METHOD("load_resource_db"), &ESS::load_resource_db);
|
ClassDB::bind_method(D_METHOD("load_resource_db"), &ESS::load_resource_db);
|
||||||
|
ClassDB::bind_method(D_METHOD("load_entity_spawner"), &ESS::load_entity_spawner);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("load_resource", "path", "type_hint"), &ESS::load_resource, DEFVAL(""));
|
ClassDB::bind_method(D_METHOD("load_resource", "path", "type_hint"), &ESS::load_resource, DEFVAL(""));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user