mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Split ESSResourceDB into 2 classes and a base class.
This commit is contained in:
parent
5537bbe713
commit
0f823f4206
2
SCsub
2
SCsub
@ -119,6 +119,8 @@ sources = [
|
||||
"singletons/ess.cpp",
|
||||
|
||||
"database/ess_resource_db.cpp",
|
||||
"database/ess_resource_db_static.cpp",
|
||||
"database/ess_resource_db_folders.cpp",
|
||||
|
||||
"editor/ess_editor_plugin.cpp",
|
||||
]
|
||||
|
@ -30,20 +30,6 @@ SOFTWARE.
|
||||
#include "../entities/resources/entity_resource_data.h"
|
||||
#include "../entities/skills/entity_skill_data.h"
|
||||
|
||||
bool ESSResourceDB::get_automatic_load() const {
|
||||
return _automatic_load;
|
||||
}
|
||||
void ESSResourceDB::set_automatic_load(const bool load) {
|
||||
_automatic_load = load;
|
||||
}
|
||||
|
||||
bool ESSResourceDB::get_load_folders() const {
|
||||
return _load_folders;
|
||||
}
|
||||
void ESSResourceDB::set_load_folders(const bool load) {
|
||||
_load_folders = load;
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDB::get_skill_for_armor_type(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, ItemEnums::ARMOR_TYPE_MAX, Ref<Aura>());
|
||||
|
||||
@ -55,518 +41,21 @@ void ESSResourceDB::set_skill_for_armor_type(const int index, const Ref<Aura> &a
|
||||
_armor_type_skills[index] = aura;
|
||||
}
|
||||
|
||||
String ESSResourceDB::get_xp_data_path() {
|
||||
return _xp_data_path;
|
||||
}
|
||||
void ESSResourceDB::set_xp_data_path(String path) {
|
||||
_xp_data_path = path;
|
||||
}
|
||||
Ref<XPData> ESSResourceDB::get_xp_data() {
|
||||
return _xp_data;
|
||||
}
|
||||
|
||||
PoolStringArray ESSResourceDB::get_folders() const {
|
||||
return _folders;
|
||||
}
|
||||
void ESSResourceDB::set_folders(const PoolStringArray &data) {
|
||||
_folders = data;
|
||||
}
|
||||
|
||||
Ref<EntityResourceData> ESSResourceDB::get_entity_resource(int class_id) {
|
||||
//ERR_FAIL_COND_V_MSG(!_entity_resource_map.has(class_id), Ref<EntityResourceData>(), "Could not find EntityResourceData! Id:" + String::num(class_id));
|
||||
|
||||
if (!_entity_resource_map.has(class_id)) {
|
||||
return Ref<EntityResourceData>();
|
||||
}
|
||||
|
||||
return _entity_resource_map.get(class_id);
|
||||
}
|
||||
Ref<EntityResourceData> ESSResourceDB::get_entity_resource_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref<EntityResourceData>(NULL));
|
||||
|
||||
return _entity_resources.get(index);
|
||||
}
|
||||
int ESSResourceDB::get_entity_resource_count() {
|
||||
return _entity_resources.size();
|
||||
}
|
||||
void ESSResourceDB::add_entity_resource(const Ref<EntityResourceData> &cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_resources.push_back(cls);
|
||||
_entity_resource_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_entity_resources() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_resources.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_resources[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_resources[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_entity_resources(const Vector<Variant> &data) {
|
||||
_entity_resources.clear();
|
||||
_entity_resource_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityResource> d = Ref<EntityResource>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_resource(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntitySkillData> ESSResourceDB::get_entity_skill(int class_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_entity_skill_map.has(class_id), Ref<EntitySkillData>(), "Could not find EntitySkillData! Id:" + String::num(class_id));
|
||||
|
||||
return _entity_skill_map.get(class_id);
|
||||
}
|
||||
Ref<EntitySkillData> ESSResourceDB::get_entity_skill_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_skills.size(), Ref<EntitySkillData>(NULL));
|
||||
|
||||
return _entity_skills.get(index);
|
||||
}
|
||||
int ESSResourceDB::get_entity_skill_count() {
|
||||
return _entity_skills.size();
|
||||
}
|
||||
void ESSResourceDB::add_entity_skill(const Ref<EntitySkillData> &cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_skills.push_back(cls);
|
||||
_entity_skill_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_entity_skills() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_skills.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_skills[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_skills[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_entity_skills(const Vector<Variant> &data) {
|
||||
_entity_skills.clear();
|
||||
_entity_skill_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySkillData> d = Ref<EntitySkillData>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_skill(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntityData> ESSResourceDB::get_entity_data(int class_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_entity_data_map.has(class_id), Ref<EntityData>(), "Could not find EntityData! Id:" + String::num(class_id));
|
||||
|
||||
return _entity_data_map.get(class_id);
|
||||
}
|
||||
Ref<EntityData> ESSResourceDB::get_entity_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>(NULL));
|
||||
|
||||
return _entity_datas.get(index);
|
||||
}
|
||||
int ESSResourceDB::get_entity_data_count() {
|
||||
return _entity_datas.size();
|
||||
}
|
||||
void ESSResourceDB::add_entity_data(const Ref<EntityData> &cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_datas.push_back(cls);
|
||||
_entity_data_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_entity_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_entity_datas(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityResource> d = Ref<EntityResource>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_data(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDB::get_spell(int spell_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_spell_map.has(spell_id), Ref<Spell>(), "Could not find Spell! Id:" + String::num(spell_id));
|
||||
|
||||
return _spell_map.get(spell_id);
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDB::get_spell_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _spells.size(), Ref<Spell>(NULL));
|
||||
|
||||
return _spells.get(index);
|
||||
}
|
||||
int ESSResourceDB::get_spell_count() {
|
||||
return _spells.size();
|
||||
}
|
||||
void ESSResourceDB::add_spell(const Ref<Spell> &spell) {
|
||||
ERR_FAIL_COND(!spell.is_valid());
|
||||
|
||||
_spells.push_back(spell);
|
||||
_spell_map.set(spell->get_id(), spell);
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_spells() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _craft_recipes.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_craft_recipes[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_craft_recipes[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_spells(const Vector<Variant> &data) {
|
||||
_spells.clear();
|
||||
_spell_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Spell> d = Ref<Spell>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_spell(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::add_aura(const Ref<Aura> &aura) {
|
||||
ERR_FAIL_COND(!aura.is_valid());
|
||||
|
||||
_auras.push_back(aura);
|
||||
_aura_map.set(aura->get_id(), aura);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDB::get_aura(int aura_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_aura_map.has(aura_id), Ref<Aura>(), "Could not find Aura! Id:" + String::num(aura_id));
|
||||
|
||||
return _aura_map.get(aura_id);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDB::get_aura_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _auras.size(), Ref<Aura>());
|
||||
|
||||
return _auras.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDB::get_aura_count() {
|
||||
return _auras.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDB::get_auras() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _auras.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_auras[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_auras[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_auras(const Vector<Variant> &data) {
|
||||
_auras.clear();
|
||||
_aura_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Aura> d = Ref<Aura>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_aura(d);
|
||||
}
|
||||
}
|
||||
|
||||
//Craft Data
|
||||
void ESSResourceDB::add_craft_recipe(const Ref<CraftRecipe> &cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_craft_recipes.push_back(cda);
|
||||
_craft_recipe_map.set(cda->get_id(), cda);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDB::get_craft_recipe(int craft_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_craft_recipe_map.has(craft_id), Ref<CraftRecipe>(), "Could not find CraftRecipe! Id:" + String::num(craft_id));
|
||||
|
||||
return _craft_recipe_map.get(craft_id);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDB::get_craft_recipe_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _craft_recipes.size(), Ref<CraftRecipe>());
|
||||
|
||||
return _craft_recipes.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDB::get_craft_recipe_count() {
|
||||
return _craft_recipes.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDB::get_craft_recipes() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _craft_recipes.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_craft_recipes[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_craft_recipes[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_craft_recipes(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<CraftRecipe> d = Ref<CraftRecipe>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_craft_recipe(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::add_item_template(const Ref<ItemTemplate> &cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_item_templates.push_back(cda);
|
||||
_item_template_map.set(cda->get_id(), cda);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDB::get_item_template(int item_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_item_template_map.has(item_id), Ref<ItemTemplate>(), "Could not find ItemTemplate! Id:" + String::num(item_id));
|
||||
|
||||
return _item_template_map.get(item_id);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDB::get_item_template_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _item_templates.size(), Ref<ItemTemplate>());
|
||||
|
||||
return _item_templates.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDB::get_item_template_count() {
|
||||
return _item_templates.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_item_templates() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _item_templates.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_item_templates[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_item_templates[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_item_templates(const Vector<Variant> &data) {
|
||||
_item_templates.clear();
|
||||
_item_template_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<ItemTemplate> d = Ref<ItemTemplate>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_item_template(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::add_entity_species_data(const Ref<EntitySpeciesData> &cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_entity_species_datas.push_back(cda);
|
||||
_entity_species_data_map.set(cda->get_id(), cda);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDB::get_entity_species_data(int item_id) {
|
||||
if (!_entity_species_data_map.has(item_id))
|
||||
return Ref<EntitySpeciesData>();
|
||||
|
||||
return _entity_species_data_map.get(item_id);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDB::get_entity_species_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_species_datas.size(), Ref<EntitySpeciesData>());
|
||||
|
||||
return _entity_species_datas.get(index);
|
||||
}
|
||||
int ESSResourceDB::get_entity_species_data_count() {
|
||||
return _entity_species_datas.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDB::get_entity_species_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_species_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_species_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_species_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDB::set_entity_species_datas(const Vector<Variant> &data) {
|
||||
_entity_species_datas.clear();
|
||||
_entity_species_data_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySpeciesData> d = Ref<EntitySpeciesData>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_item_template(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::load_all() {
|
||||
load_xp_data();
|
||||
load_folders();
|
||||
}
|
||||
|
||||
void ESSResourceDB::load_xp_data() {
|
||||
_Directory dir;
|
||||
|
||||
ERR_FAIL_COND(_xp_data_path == "");
|
||||
|
||||
Ref<XPData> d = load_resource(_xp_data_path, "XPData");
|
||||
|
||||
ERR_FAIL_COND(!d.is_valid());
|
||||
|
||||
_xp_data = d;
|
||||
}
|
||||
|
||||
void ESSResourceDB::load_folders() {
|
||||
for (int i = 0; i < _folders.size(); ++i) {
|
||||
load_folder(_folders[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::load_folder(const String &folder) {
|
||||
_Directory dir;
|
||||
|
||||
bool ew = folder.ends_with("/");
|
||||
|
||||
if (dir.open(folder) == OK) {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
if (!dir.current_is_dir()) {
|
||||
String path;
|
||||
|
||||
if (ew)
|
||||
path = folder + filename;
|
||||
else
|
||||
path = folder + "/" + filename;
|
||||
|
||||
Ref<Resource> res = load_resource(path);
|
||||
|
||||
ERR_CONTINUE(!res.is_valid());
|
||||
|
||||
add_resource(res);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDB::add_resource(const Ref<Resource> &resource) {
|
||||
StringName cls = resource->get_class_name();
|
||||
|
||||
if (cls == "EntityResourceData") {
|
||||
add_entity_resource(resource);
|
||||
} else if (cls == "EntitySkillData") {
|
||||
add_entity_skill(resource);
|
||||
} else if (cls == "EntityData") {
|
||||
add_entity_data(resource);
|
||||
} else if (cls == "Spell") {
|
||||
add_spell(resource);
|
||||
} else if (cls == "Aura") {
|
||||
add_aura(resource);
|
||||
} else if (cls == "CraftRecipe") {
|
||||
add_craft_recipe(resource);
|
||||
} else if (cls == "ItemTemplate") {
|
||||
add_item_template(resource);
|
||||
} else if (cls == "EntitySpeciesData") {
|
||||
add_entity_species_data(resource);
|
||||
} else if (cls == "XPData") {
|
||||
_xp_data = resource;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Resource> ESSResourceDB::load_resource(const String &path, const String &type_hint) {
|
||||
_ResourceLoader *rl = _ResourceLoader::get_singleton();
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, type_hint);
|
||||
|
||||
ERR_FAIL_COND_V(!resl.is_valid(), Ref<Resource>());
|
||||
|
||||
resl->wait();
|
||||
|
||||
return resl->get_resource();
|
||||
#else
|
||||
return rl->load(path, type_hint);
|
||||
#endif
|
||||
void ESSResourceDB::set_xp_data(const Ref<XPData> &data) {
|
||||
_xp_data = data;
|
||||
}
|
||||
|
||||
ESSResourceDB::ESSResourceDB() {
|
||||
_automatic_load = false;
|
||||
|
||||
_xp_data_path = "";
|
||||
|
||||
if (_automatic_load) {
|
||||
call_deferred("load_all");
|
||||
}
|
||||
}
|
||||
|
||||
ESSResourceDB::~ESSResourceDB() {
|
||||
_entity_resources.clear();
|
||||
_entity_resource_map.clear();
|
||||
|
||||
_entity_skills.clear();
|
||||
_entity_skill_map.clear();
|
||||
|
||||
_entity_datas.clear();
|
||||
_entity_data_map.clear();
|
||||
|
||||
_spells.clear();
|
||||
_spell_map.clear();
|
||||
|
||||
_auras.clear();
|
||||
_aura_map.clear();
|
||||
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
|
||||
_item_templates.clear();
|
||||
_item_template_map.clear();
|
||||
|
||||
_entity_species_datas.clear();
|
||||
_entity_species_data_map.clear();
|
||||
_xp_data.unref();
|
||||
}
|
||||
|
||||
void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_automatic_load"), &ESSResourceDB::get_automatic_load);
|
||||
ClassDB::bind_method(D_METHOD("set_automatic_load", "load"), &ESSResourceDB::set_automatic_load);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_load"), "set_automatic_load", "get_automatic_load");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_skill_for_armor_type", "index"), &ESSResourceDB::get_skill_for_armor_type);
|
||||
ClassDB::bind_method(D_METHOD("set_skill_for_armor_type", "index", "aura"), &ESSResourceDB::set_skill_for_armor_type);
|
||||
|
||||
@ -575,15 +64,9 @@ void ESSResourceDB::_bind_methods() {
|
||||
}
|
||||
|
||||
//XPData
|
||||
ClassDB::bind_method(D_METHOD("get_xp_data_path"), &ESSResourceDB::get_xp_data_path);
|
||||
ClassDB::bind_method(D_METHOD("set_xp_data_path", "path"), &ESSResourceDB::set_xp_data_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "xp_data_path"), "set_xp_data_path", "get_xp_data_path");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_xp_data"), &ESSResourceDB::get_xp_data);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_folders"), &ESSResourceDB::get_folders);
|
||||
ClassDB::bind_method(D_METHOD("set_folders", "recipe"), &ESSResourceDB::set_folders);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "folders"), "set_folders", "get_folders");
|
||||
ClassDB::bind_method(D_METHOD("set_xp_data", "data"), &ESSResourceDB::set_xp_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "xp_data"), "set_xp_data", "get_xp_data");
|
||||
|
||||
//EntityResourceData
|
||||
ClassDB::bind_method(D_METHOD("add_entity_resource", "cls"), &ESSResourceDB::add_entity_resource);
|
||||
@ -592,7 +75,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resource_count"), &ESSResourceDB::get_entity_resource_count);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resources"), &ESSResourceDB::get_entity_resources);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_resources", "recipe"), &ESSResourceDB::set_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");
|
||||
|
||||
//EntitySkills
|
||||
ClassDB::bind_method(D_METHOD("add_entity_skill", "cls"), &ESSResourceDB::add_entity_skill);
|
||||
@ -601,7 +83,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_entity_skill_count"), &ESSResourceDB::get_entity_skill_count);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_skills"), &ESSResourceDB::get_entity_skills);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_skills", "recipe"), &ESSResourceDB::set_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");
|
||||
|
||||
//EntityData
|
||||
ClassDB::bind_method(D_METHOD("add_entity_data", "cls"), &ESSResourceDB::add_entity_data);
|
||||
@ -610,7 +91,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_entity_data_count"), &ESSResourceDB::get_entity_data_count);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_datas"), &ESSResourceDB::get_entity_datas);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_datas", "recipe"), &ESSResourceDB::set_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");
|
||||
|
||||
//Spell
|
||||
ClassDB::bind_method(D_METHOD("add_spell", "spell"), &ESSResourceDB::add_spell);
|
||||
@ -619,7 +99,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_spell_count"), &ESSResourceDB::get_spell_count);
|
||||
ClassDB::bind_method(D_METHOD("get_spells"), &ESSResourceDB::get_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_spells", "recipe"), &ESSResourceDB::set_spells);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_spells", "get_spells");
|
||||
|
||||
//Aura
|
||||
ClassDB::bind_method(D_METHOD("add_aura", "spell"), &ESSResourceDB::add_aura);
|
||||
@ -628,7 +107,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_aura_count"), &ESSResourceDB::get_aura_count);
|
||||
ClassDB::bind_method(D_METHOD("get_auras"), &ESSResourceDB::get_auras);
|
||||
ClassDB::bind_method(D_METHOD("set_auras", "recipe"), &ESSResourceDB::set_auras);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "auras", PROPERTY_HINT_NONE, "17/17:Aura", PROPERTY_USAGE_DEFAULT, "Aura"), "set_auras", "get_auras");
|
||||
|
||||
//Craft Data
|
||||
ClassDB::bind_method(D_METHOD("add_craft_recipe", "craft_recipe"), &ESSResourceDB::add_craft_recipe);
|
||||
@ -637,7 +115,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_craft_recipe_count"), &ESSResourceDB::get_craft_recipe_count);
|
||||
ClassDB::bind_method(D_METHOD("get_craft_recipes"), &ESSResourceDB::get_craft_recipes);
|
||||
ClassDB::bind_method(D_METHOD("set_craft_recipes", "recipe"), &ESSResourceDB::set_craft_recipes);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "craft_recipes", PROPERTY_HINT_NONE, "17/17:CraftRecipe", PROPERTY_USAGE_DEFAULT, "CraftRecipe"), "set_craft_recipes", "get_craft_recipes");
|
||||
|
||||
//Item Templates
|
||||
ClassDB::bind_method(D_METHOD("add_item_template", "item_template"), &ESSResourceDB::add_item_template);
|
||||
@ -646,7 +123,6 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_item_template_count"), &ESSResourceDB::get_item_template_count);
|
||||
ClassDB::bind_method(D_METHOD("get_item_templates"), &ESSResourceDB::get_item_templates);
|
||||
ClassDB::bind_method(D_METHOD("set_item_templates", "recipe"), &ESSResourceDB::set_item_templates);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "item_templates", PROPERTY_HINT_NONE, "17/17:ItemTemplate", PROPERTY_USAGE_DEFAULT, "ItemTemplate"), "set_item_templates", "get_item_templates");
|
||||
|
||||
//Player Character Data
|
||||
ClassDB::bind_method(D_METHOD("add_entity_species_data", "pcd"), &ESSResourceDB::add_entity_species_data);
|
||||
@ -655,14 +131,4 @@ void ESSResourceDB::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_entity_species_data_count"), &ESSResourceDB::get_entity_species_data_count);
|
||||
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);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_species_datas", PROPERTY_HINT_NONE, "17/17:EntitySpeciesData", PROPERTY_USAGE_DEFAULT, "EntitySpeciesData"), "set_entity_species_datas", "get_entity_species_datas");
|
||||
|
||||
//load
|
||||
ClassDB::bind_method(D_METHOD("load_all"), &ESSResourceDB::load_all);
|
||||
ClassDB::bind_method(D_METHOD("load_xp_data"), &ESSResourceDB::load_xp_data);
|
||||
ClassDB::bind_method(D_METHOD("load_folders"), &ESSResourceDB::load_folders);
|
||||
ClassDB::bind_method(D_METHOD("load_folder", "folder"), &ESSResourceDB::load_folder);
|
||||
ClassDB::bind_method(D_METHOD("add_resource", "resource"), &ESSResourceDB::add_resource);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_resource", "path", "type_hint"), &ESSResourceDB::load_resource, DEFVAL(""));
|
||||
}
|
||||
|
@ -25,15 +25,10 @@ SOFTWARE.
|
||||
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/hash_map.h"
|
||||
#include "core/io/json.h"
|
||||
#include "core/variant.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "core/ustring.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#include "core/bind/core_bind.h"
|
||||
|
||||
@ -41,14 +36,6 @@ SOFTWARE.
|
||||
|
||||
#include "../data/entities/xp_data.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define PoolStringArray PackedStringArray
|
||||
|
||||
#define POOL_STRING_ARRAY PACKED_STRING_ARRAY
|
||||
#endif
|
||||
|
||||
class Aura;
|
||||
class Spell;
|
||||
class EntityData;
|
||||
@ -64,85 +51,67 @@ class ESSResourceDB : public Resource {
|
||||
GDCLASS(ESSResourceDB, Resource);
|
||||
|
||||
public:
|
||||
bool get_automatic_load() const;
|
||||
void set_automatic_load(const bool load);
|
||||
|
||||
bool get_load_folders() const;
|
||||
void set_load_folders(const bool load);
|
||||
|
||||
Ref<Aura> get_skill_for_armor_type(const int index);
|
||||
void set_skill_for_armor_type(const int index, const Ref<Aura> &aura);
|
||||
|
||||
String get_xp_data_path();
|
||||
void set_xp_data_path(String path);
|
||||
Ref<XPData> get_xp_data();
|
||||
void set_xp_data(const Ref<XPData> &data);
|
||||
|
||||
PoolStringArray get_folders() const;
|
||||
void set_folders(const PoolStringArray &folders);
|
||||
virtual Ref<EntityResourceData> get_entity_resource(int class_id) = 0;
|
||||
virtual Ref<EntityResourceData> get_entity_resource_index(int index) = 0;
|
||||
virtual int get_entity_resource_count() = 0;
|
||||
virtual void add_entity_resource(Ref<EntityResourceData> cls) = 0;
|
||||
virtual Vector<Variant> get_entity_resources() const = 0;
|
||||
virtual void set_entity_resources(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<EntityResourceData> get_entity_resource(int class_id);
|
||||
Ref<EntityResourceData> get_entity_resource_index(int index);
|
||||
int get_entity_resource_count();
|
||||
void add_entity_resource(const Ref<EntityResourceData> &cls);
|
||||
Vector<Variant> get_entity_resources() const;
|
||||
void set_entity_resources(const Vector<Variant> &data);
|
||||
virtual Ref<EntitySkillData> get_entity_skill(int class_id) = 0;
|
||||
virtual Ref<EntitySkillData> get_entity_skill_index(int index) = 0;
|
||||
virtual int get_entity_skill_count() = 0;
|
||||
virtual void add_entity_skill(Ref<EntitySkillData> cls) = 0;
|
||||
virtual Vector<Variant> get_entity_skills() const = 0;
|
||||
virtual void set_entity_skills(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<EntitySkillData> get_entity_skill(int class_id);
|
||||
Ref<EntitySkillData> get_entity_skill_index(int index);
|
||||
int get_entity_skill_count();
|
||||
void add_entity_skill(const Ref<EntitySkillData> &cls);
|
||||
Vector<Variant> get_entity_skills() const;
|
||||
void set_entity_skills(const Vector<Variant> &data);
|
||||
virtual Ref<EntityData> get_entity_data(int class_id) = 0;
|
||||
virtual Ref<EntityData> get_entity_data_index(int index) = 0;
|
||||
virtual int get_entity_data_count() = 0;
|
||||
virtual void add_entity_data(Ref<EntityData> cls) = 0;
|
||||
virtual Vector<Variant> get_entity_datas() const = 0;
|
||||
virtual void set_entity_datas(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<EntityData> get_entity_data(int class_id);
|
||||
Ref<EntityData> get_entity_data_index(int index);
|
||||
int get_entity_data_count();
|
||||
void add_entity_data(const Ref<EntityData> &cls);
|
||||
Vector<Variant> get_entity_datas() const;
|
||||
void set_entity_datas(const Vector<Variant> &data);
|
||||
virtual Ref<Spell> get_spell(int spell_id) = 0;
|
||||
virtual Ref<Spell> get_spell_index(int index) = 0;
|
||||
virtual int get_spell_count() = 0;
|
||||
virtual void add_spell(Ref<Spell> spell) = 0;
|
||||
virtual Vector<Variant> get_spells() const = 0;
|
||||
virtual void set_spells(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<Spell> get_spell(int spell_id);
|
||||
Ref<Spell> get_spell_index(int index);
|
||||
int get_spell_count();
|
||||
void add_spell(const Ref<Spell> &spell);
|
||||
Vector<Variant> get_spells() const;
|
||||
void set_spells(const Vector<Variant> &data);
|
||||
virtual Ref<Aura> get_aura(int aura_id) = 0;
|
||||
virtual Ref<Aura> get_aura_index(int index) = 0;
|
||||
virtual int get_aura_count() = 0;
|
||||
virtual void add_aura(Ref<Aura> aura) = 0;
|
||||
virtual Vector<Variant> get_auras() const = 0;
|
||||
virtual void set_auras(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<Aura> get_aura(int aura_id);
|
||||
Ref<Aura> get_aura_index(int index);
|
||||
int get_aura_count();
|
||||
void add_aura(const Ref<Aura> &aura);
|
||||
Vector<Variant> get_auras() const;
|
||||
void set_auras(const Vector<Variant> &data);
|
||||
virtual Ref<CraftRecipe> get_craft_recipe(int craft_id) = 0;
|
||||
virtual Ref<CraftRecipe> get_craft_recipe_index(int index) = 0;
|
||||
virtual int get_craft_recipe_count() = 0;
|
||||
virtual void add_craft_recipe(Ref<CraftRecipe> aura) = 0;
|
||||
virtual Vector<Variant> get_craft_recipes() const = 0;
|
||||
virtual void set_craft_recipes(const Vector<Variant> &data) = 0;
|
||||
|
||||
Ref<CraftRecipe> get_craft_recipe(int craft_id);
|
||||
Ref<CraftRecipe> get_craft_recipe_index(int index);
|
||||
int get_craft_recipe_count();
|
||||
void add_craft_recipe(const Ref<CraftRecipe> &aura);
|
||||
Vector<Variant> get_craft_recipes() const;
|
||||
void set_craft_recipes(const Vector<Variant> &data);
|
||||
virtual void add_item_template(Ref<ItemTemplate> aura) = 0;
|
||||
virtual Ref<ItemTemplate> get_item_template(int item_id) = 0;
|
||||
virtual Ref<ItemTemplate> get_item_template_index(int index) = 0;
|
||||
virtual int get_item_template_count() = 0;
|
||||
virtual Vector<Variant> get_item_templates() const = 0;
|
||||
virtual void set_item_templates(const Vector<Variant> &data) = 0;
|
||||
|
||||
void add_item_template(const Ref<ItemTemplate> &aura);
|
||||
Ref<ItemTemplate> get_item_template(int item_id);
|
||||
Ref<ItemTemplate> get_item_template_index(int index);
|
||||
int get_item_template_count();
|
||||
Vector<Variant> get_item_templates() const;
|
||||
void set_item_templates(const Vector<Variant> &data);
|
||||
|
||||
void add_entity_species_data(const Ref<EntitySpeciesData> &aura);
|
||||
Ref<EntitySpeciesData> get_entity_species_data(int item_id);
|
||||
Ref<EntitySpeciesData> get_entity_species_data_index(int index);
|
||||
int get_entity_species_data_count();
|
||||
Vector<Variant> get_entity_species_datas() const;
|
||||
void set_entity_species_datas(const Vector<Variant> &data);
|
||||
|
||||
void load_all();
|
||||
void load_xp_data();
|
||||
void load_folders();
|
||||
void load_folder(const String &folder);
|
||||
void add_resource(const Ref<Resource> &resource);
|
||||
|
||||
Ref<Resource> load_resource(const String &path, const String &type_hint = "");
|
||||
virtual void add_entity_species_data(Ref<EntitySpeciesData> aura) = 0;
|
||||
virtual Ref<EntitySpeciesData> get_entity_species_data(int item_id) = 0;
|
||||
virtual Ref<EntitySpeciesData> get_entity_species_data_index(int index) = 0;
|
||||
virtual int get_entity_species_data_count() = 0;
|
||||
virtual Vector<Variant> get_entity_species_datas() const = 0;
|
||||
virtual void set_entity_species_datas(const Vector<Variant> &data) = 0;
|
||||
|
||||
ESSResourceDB();
|
||||
~ESSResourceDB();
|
||||
@ -151,39 +120,9 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
String _xp_data_path;
|
||||
Ref<XPData> _xp_data;
|
||||
|
||||
PoolStringArray _folders;
|
||||
|
||||
Vector<Ref<EntityResourceData>> _entity_resources;
|
||||
HashMap<int, Ref<EntityResourceData>> _entity_resource_map;
|
||||
|
||||
Vector<Ref<EntitySkillData>> _entity_skills;
|
||||
HashMap<int, Ref<EntitySkillData>> _entity_skill_map;
|
||||
|
||||
Vector<Ref<EntityData>> _entity_datas;
|
||||
HashMap<int, Ref<EntityData>> _entity_data_map;
|
||||
|
||||
Vector<Ref<Spell>> _spells;
|
||||
HashMap<int, Ref<Spell>> _spell_map;
|
||||
|
||||
Vector<Ref<Aura>> _auras;
|
||||
HashMap<int, Ref<Aura>> _aura_map;
|
||||
|
||||
Vector<Ref<CraftRecipe>> _craft_recipes;
|
||||
HashMap<int, Ref<CraftRecipe>> _craft_recipe_map;
|
||||
|
||||
Vector<Ref<ItemTemplate>> _item_templates;
|
||||
HashMap<int, Ref<ItemTemplate>> _item_template_map;
|
||||
|
||||
Vector<Ref<EntitySpeciesData>> _entity_species_datas;
|
||||
HashMap<int, Ref<EntitySpeciesData>> _entity_species_data_map;
|
||||
|
||||
Ref<Aura> _armor_type_skills[ItemEnums::ARMOR_TYPE_MAX];
|
||||
|
||||
bool _automatic_load;
|
||||
bool _load_folders;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
573
database/ess_resource_db_folders.cpp
Normal file
573
database/ess_resource_db_folders.cpp
Normal file
@ -0,0 +1,573 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "ess_resource_db_folders.h"
|
||||
|
||||
#include "../data/auras/aura.h"
|
||||
#include "../data/items/craft_recipe.h"
|
||||
#include "../data/species/entity_species_data.h"
|
||||
#include "../data/spells/spell.h"
|
||||
#include "../entities/data/entity_data.h"
|
||||
#include "../entities/resources/entity_resource_data.h"
|
||||
#include "../entities/skills/entity_skill_data.h"
|
||||
|
||||
bool ESSResourceDBFolders::get_automatic_load() const {
|
||||
return _automatic_load;
|
||||
}
|
||||
void ESSResourceDBFolders::set_automatic_load(const bool load) {
|
||||
_automatic_load = load;
|
||||
}
|
||||
|
||||
bool ESSResourceDBFolders::get_load_folders() const {
|
||||
return _load_folders;
|
||||
}
|
||||
void ESSResourceDBFolders::set_load_folders(const bool load) {
|
||||
_load_folders = load;
|
||||
}
|
||||
|
||||
String ESSResourceDBFolders::get_xp_data_path() {
|
||||
return _xp_data_path;
|
||||
}
|
||||
void ESSResourceDBFolders::set_xp_data_path(String path) {
|
||||
_xp_data_path = path;
|
||||
}
|
||||
|
||||
PoolStringArray ESSResourceDBFolders::get_folders() const {
|
||||
return _folders;
|
||||
}
|
||||
void ESSResourceDBFolders::set_folders(const PoolStringArray &data) {
|
||||
_folders = data;
|
||||
}
|
||||
|
||||
Ref<EntityResourceData> ESSResourceDBFolders::get_entity_resource(int class_id) {
|
||||
//ERR_FAIL_COND_V_MSG(!_entity_resource_map.has(class_id), Ref<EntityResourceData>(), "Could not find EntityResourceData! Id:" + String::num(class_id));
|
||||
|
||||
if (!_entity_resource_map.has(class_id)) {
|
||||
return Ref<EntityResourceData>();
|
||||
}
|
||||
|
||||
return _entity_resource_map.get(class_id);
|
||||
}
|
||||
Ref<EntityResourceData> ESSResourceDBFolders::get_entity_resource_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref<EntityResourceData>(NULL));
|
||||
|
||||
return _entity_resources.get(index);
|
||||
}
|
||||
int ESSResourceDBFolders::get_entity_resource_count() {
|
||||
return _entity_resources.size();
|
||||
}
|
||||
void ESSResourceDBFolders::add_entity_resource(Ref<EntityResourceData> cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_resources.push_back(cls);
|
||||
_entity_resource_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_entity_resources() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_resources.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_resources[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_resources[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_entity_resources(const Vector<Variant> &data) {
|
||||
_entity_resources.clear();
|
||||
_entity_resource_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityResource> d = Ref<EntityResource>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_resource(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntitySkillData> ESSResourceDBFolders::get_entity_skill(int class_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_entity_skill_map.has(class_id), Ref<EntitySkillData>(), "Could not find EntitySkillData! Id:" + String::num(class_id));
|
||||
|
||||
return _entity_skill_map.get(class_id);
|
||||
}
|
||||
Ref<EntitySkillData> ESSResourceDBFolders::get_entity_skill_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_skills.size(), Ref<EntitySkillData>(NULL));
|
||||
|
||||
return _entity_skills.get(index);
|
||||
}
|
||||
int ESSResourceDBFolders::get_entity_skill_count() {
|
||||
return _entity_skills.size();
|
||||
}
|
||||
void ESSResourceDBFolders::add_entity_skill(Ref<EntitySkillData> cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_skills.push_back(cls);
|
||||
_entity_skill_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_entity_skills() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_skills.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_skills[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_skills[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_entity_skills(const Vector<Variant> &data) {
|
||||
_entity_skills.clear();
|
||||
_entity_skill_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySkillData> d = Ref<EntitySkillData>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_skill(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntityData> ESSResourceDBFolders::get_entity_data(int class_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_entity_data_map.has(class_id), Ref<EntityData>(), "Could not find EntityData! Id:" + String::num(class_id));
|
||||
|
||||
return _entity_data_map.get(class_id);
|
||||
}
|
||||
Ref<EntityData> ESSResourceDBFolders::get_entity_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>(NULL));
|
||||
|
||||
return _entity_datas.get(index);
|
||||
}
|
||||
int ESSResourceDBFolders::get_entity_data_count() {
|
||||
return _entity_datas.size();
|
||||
}
|
||||
void ESSResourceDBFolders::add_entity_data(Ref<EntityData> cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_entity_datas.push_back(cls);
|
||||
_entity_data_map.set(cls->get_id(), cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_entity_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_entity_datas(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityResource> d = Ref<EntityResource>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_entity_data(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDBFolders::get_spell(int spell_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_spell_map.has(spell_id), Ref<Spell>(), "Could not find Spell! Id:" + String::num(spell_id));
|
||||
|
||||
return _spell_map.get(spell_id);
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDBFolders::get_spell_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _spells.size(), Ref<Spell>(NULL));
|
||||
|
||||
return _spells.get(index);
|
||||
}
|
||||
int ESSResourceDBFolders::get_spell_count() {
|
||||
return _spells.size();
|
||||
}
|
||||
void ESSResourceDBFolders::add_spell(Ref<Spell> spell) {
|
||||
ERR_FAIL_COND(!spell.is_valid());
|
||||
|
||||
_spells.push_back(spell);
|
||||
_spell_map.set(spell->get_id(), spell);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_spells() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _spells.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_spells[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_spells[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_spells(const Vector<Variant> &data) {
|
||||
_spells.clear();
|
||||
_spell_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Spell> d = Ref<Spell>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_spell(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::add_aura(Ref<Aura> aura) {
|
||||
ERR_FAIL_COND(!aura.is_valid());
|
||||
|
||||
_auras.push_back(aura);
|
||||
_aura_map.set(aura->get_id(), aura);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDBFolders::get_aura(int aura_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_aura_map.has(aura_id), Ref<Aura>(), "Could not find Aura! Id:" + String::num(aura_id));
|
||||
|
||||
return _aura_map.get(aura_id);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDBFolders::get_aura_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _auras.size(), Ref<Aura>());
|
||||
|
||||
return _auras.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBFolders::get_aura_count() {
|
||||
return _auras.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDBFolders::get_auras() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _auras.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_auras[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_auras[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_auras(const Vector<Variant> &data) {
|
||||
_auras.clear();
|
||||
_aura_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Aura> d = Ref<Aura>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_aura(d);
|
||||
}
|
||||
}
|
||||
|
||||
//Craft Data
|
||||
void ESSResourceDBFolders::add_craft_recipe(Ref<CraftRecipe> cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_craft_recipes.push_back(cda);
|
||||
_craft_recipe_map.set(cda->get_id(), cda);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDBFolders::get_craft_recipe(int craft_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_craft_recipe_map.has(craft_id), Ref<CraftRecipe>(), "Could not find CraftRecipe! Id:" + String::num(craft_id));
|
||||
|
||||
return _craft_recipe_map.get(craft_id);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDBFolders::get_craft_recipe_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _craft_recipes.size(), Ref<CraftRecipe>());
|
||||
|
||||
return _craft_recipes.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBFolders::get_craft_recipe_count() {
|
||||
return _craft_recipes.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDBFolders::get_craft_recipes() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _craft_recipes.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_craft_recipes[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_craft_recipes[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_craft_recipes(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<CraftRecipe> d = Ref<CraftRecipe>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_craft_recipe(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::add_item_template(Ref<ItemTemplate> cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_item_templates.push_back(cda);
|
||||
_item_template_map.set(cda->get_id(), cda);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDBFolders::get_item_template(int item_id) {
|
||||
ERR_FAIL_COND_V_MSG(!_item_template_map.has(item_id), Ref<ItemTemplate>(), "Could not find ItemTemplate! Id:" + String::num(item_id));
|
||||
|
||||
return _item_template_map.get(item_id);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDBFolders::get_item_template_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _item_templates.size(), Ref<ItemTemplate>());
|
||||
|
||||
return _item_templates.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBFolders::get_item_template_count() {
|
||||
return _item_templates.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_item_templates() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _item_templates.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_item_templates[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_item_templates[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_item_templates(const Vector<Variant> &data) {
|
||||
_item_templates.clear();
|
||||
_item_template_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<ItemTemplate> d = Ref<ItemTemplate>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_item_template(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::add_entity_species_data(Ref<EntitySpeciesData> cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
|
||||
_entity_species_datas.push_back(cda);
|
||||
_entity_species_data_map.set(cda->get_id(), cda);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDBFolders::get_entity_species_data(int item_id) {
|
||||
if (!_entity_species_data_map.has(item_id))
|
||||
return Ref<EntitySpeciesData>();
|
||||
|
||||
return _entity_species_data_map.get(item_id);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDBFolders::get_entity_species_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_species_datas.size(), Ref<EntitySpeciesData>());
|
||||
|
||||
return _entity_species_datas.get(index);
|
||||
}
|
||||
int ESSResourceDBFolders::get_entity_species_data_count() {
|
||||
return _entity_species_datas.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDBFolders::get_entity_species_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_species_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_species_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_species_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBFolders::set_entity_species_datas(const Vector<Variant> &data) {
|
||||
_entity_species_datas.clear();
|
||||
_entity_species_data_map.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySpeciesData> d = Ref<EntitySpeciesData>(data[i]);
|
||||
|
||||
ERR_CONTINUE(!d.is_valid());
|
||||
|
||||
add_item_template(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::load_all() {
|
||||
load_xp_data();
|
||||
load_folders();
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::load_xp_data() {
|
||||
_Directory dir;
|
||||
|
||||
ERR_FAIL_COND(_xp_data_path == "");
|
||||
|
||||
Ref<XPData> d = load_resource(_xp_data_path, "XPData");
|
||||
|
||||
ERR_FAIL_COND(!d.is_valid());
|
||||
|
||||
set_xp_data(d);
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::load_folders() {
|
||||
for (int i = 0; i < _folders.size(); ++i) {
|
||||
load_folder(_folders[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::load_folder(const String &folder) {
|
||||
_Directory dir;
|
||||
|
||||
bool ew = folder.ends_with("/");
|
||||
|
||||
if (dir.open(folder) == OK) {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
if (!dir.current_is_dir()) {
|
||||
String path;
|
||||
|
||||
if (ew)
|
||||
path = folder + filename;
|
||||
else
|
||||
path = folder + "/" + filename;
|
||||
|
||||
Ref<Resource> res = load_resource(path);
|
||||
|
||||
ERR_CONTINUE(!res.is_valid());
|
||||
|
||||
add_resource(res);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::add_resource(const Ref<Resource> &resource) {
|
||||
StringName cls = resource->get_class_name();
|
||||
|
||||
if (cls == "EntityResourceData") {
|
||||
add_entity_resource(resource);
|
||||
} else if (cls == "EntitySkillData") {
|
||||
add_entity_skill(resource);
|
||||
} else if (cls == "EntityData") {
|
||||
add_entity_data(resource);
|
||||
} else if (cls == "Spell") {
|
||||
add_spell(resource);
|
||||
} else if (cls == "Aura") {
|
||||
add_aura(resource);
|
||||
} else if (cls == "CraftRecipe") {
|
||||
add_craft_recipe(resource);
|
||||
} else if (cls == "ItemTemplate") {
|
||||
add_item_template(resource);
|
||||
} else if (cls == "EntitySpeciesData") {
|
||||
add_entity_species_data(resource);
|
||||
} else if (cls == "XPData") {
|
||||
set_xp_data(resource);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Resource> ESSResourceDBFolders::load_resource(const String &path, const String &type_hint) {
|
||||
_ResourceLoader *rl = _ResourceLoader::get_singleton();
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, type_hint);
|
||||
|
||||
ERR_FAIL_COND_V(!resl.is_valid(), Ref<Resource>());
|
||||
|
||||
resl->wait();
|
||||
|
||||
return resl->get_resource();
|
||||
#else
|
||||
return rl->load(path, type_hint);
|
||||
#endif
|
||||
}
|
||||
|
||||
ESSResourceDBFolders::ESSResourceDBFolders() {
|
||||
_automatic_load = false;
|
||||
|
||||
_xp_data_path = "";
|
||||
|
||||
if (_automatic_load) {
|
||||
call_deferred("load_all");
|
||||
}
|
||||
}
|
||||
|
||||
ESSResourceDBFolders::~ESSResourceDBFolders() {
|
||||
_entity_resources.clear();
|
||||
_entity_resource_map.clear();
|
||||
|
||||
_entity_skills.clear();
|
||||
_entity_skill_map.clear();
|
||||
|
||||
_entity_datas.clear();
|
||||
_entity_data_map.clear();
|
||||
|
||||
_spells.clear();
|
||||
_spell_map.clear();
|
||||
|
||||
_auras.clear();
|
||||
_aura_map.clear();
|
||||
|
||||
_craft_recipes.clear();
|
||||
_craft_recipe_map.clear();
|
||||
|
||||
_item_templates.clear();
|
||||
_item_template_map.clear();
|
||||
|
||||
_entity_species_datas.clear();
|
||||
_entity_species_data_map.clear();
|
||||
}
|
||||
|
||||
void ESSResourceDBFolders::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_automatic_load"), &ESSResourceDBFolders::get_automatic_load);
|
||||
ClassDB::bind_method(D_METHOD("set_automatic_load", "load"), &ESSResourceDBFolders::set_automatic_load);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_load"), "set_automatic_load", "get_automatic_load");
|
||||
|
||||
//XPData
|
||||
ClassDB::bind_method(D_METHOD("get_xp_data_path"), &ESSResourceDBFolders::get_xp_data_path);
|
||||
ClassDB::bind_method(D_METHOD("set_xp_data_path", "path"), &ESSResourceDBFolders::set_xp_data_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "xp_data_path"), "set_xp_data_path", "get_xp_data_path");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_folders"), &ESSResourceDBFolders::get_folders);
|
||||
ClassDB::bind_method(D_METHOD("set_folders", "recipe"), &ESSResourceDBFolders::set_folders);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "folders"), "set_folders", "get_folders");
|
||||
|
||||
//load
|
||||
ClassDB::bind_method(D_METHOD("load_all"), &ESSResourceDBFolders::load_all);
|
||||
ClassDB::bind_method(D_METHOD("load_xp_data"), &ESSResourceDBFolders::load_xp_data);
|
||||
ClassDB::bind_method(D_METHOD("load_folders"), &ESSResourceDBFolders::load_folders);
|
||||
ClassDB::bind_method(D_METHOD("load_folder", "folder"), &ESSResourceDBFolders::load_folder);
|
||||
ClassDB::bind_method(D_METHOD("add_resource", "resource"), &ESSResourceDBFolders::add_resource);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_resource", "path", "type_hint"), &ESSResourceDBFolders::load_resource, DEFVAL(""));
|
||||
}
|
182
database/ess_resource_db_folders.h
Normal file
182
database/ess_resource_db_folders.h
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ESS_RESOURCE_DB_FOLDERS_H
|
||||
#define ESS_RESOURCE_DB_FOLDERS_H
|
||||
|
||||
#include "ess_resource_db.h"
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/hash_map.h"
|
||||
|
||||
#include "core/variant.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "core/ustring.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#include "core/bind/core_bind.h"
|
||||
|
||||
#include "../item_enums.h"
|
||||
|
||||
#include "../data/entities/xp_data.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define PoolStringArray PackedStringArray
|
||||
|
||||
#define POOL_STRING_ARRAY PACKED_STRING_ARRAY
|
||||
#endif
|
||||
|
||||
class Aura;
|
||||
class Spell;
|
||||
class EntityData;
|
||||
class CraftRecipe;
|
||||
class ItemTemplate;
|
||||
class EntityResourceData;
|
||||
class EntitySkillData;
|
||||
class EntityCreateInfo;
|
||||
class SpellCastInfo;
|
||||
class EntitySpeciesData;
|
||||
|
||||
class ESSResourceDBFolders : public ESSResourceDB {
|
||||
GDCLASS(ESSResourceDBFolders, ESSResourceDB);
|
||||
|
||||
public:
|
||||
bool get_automatic_load() const;
|
||||
void set_automatic_load(const bool load);
|
||||
|
||||
bool get_load_folders() const;
|
||||
void set_load_folders(const bool load);
|
||||
|
||||
String get_xp_data_path();
|
||||
void set_xp_data_path(String path);
|
||||
|
||||
PoolStringArray get_folders() const;
|
||||
void set_folders(const PoolStringArray &folders);
|
||||
|
||||
Ref<EntityResourceData> get_entity_resource(int class_id);
|
||||
Ref<EntityResourceData> get_entity_resource_index(int index);
|
||||
int get_entity_resource_count();
|
||||
void add_entity_resource(Ref<EntityResourceData> cls);
|
||||
Vector<Variant> get_entity_resources() const;
|
||||
void set_entity_resources(const Vector<Variant> &data);
|
||||
|
||||
Ref<EntitySkillData> get_entity_skill(int class_id);
|
||||
Ref<EntitySkillData> get_entity_skill_index(int index);
|
||||
int get_entity_skill_count();
|
||||
void add_entity_skill(Ref<EntitySkillData> cls);
|
||||
Vector<Variant> get_entity_skills() const;
|
||||
void set_entity_skills(const Vector<Variant> &data);
|
||||
|
||||
Ref<EntityData> get_entity_data(int class_id);
|
||||
Ref<EntityData> get_entity_data_index(int index);
|
||||
int get_entity_data_count();
|
||||
void add_entity_data(Ref<EntityData> cls);
|
||||
Vector<Variant> get_entity_datas() const;
|
||||
void set_entity_datas(const Vector<Variant> &data);
|
||||
|
||||
Ref<Spell> get_spell(int spell_id);
|
||||
Ref<Spell> get_spell_index(int index);
|
||||
int get_spell_count();
|
||||
void add_spell(Ref<Spell> spell);
|
||||
Vector<Variant> get_spells() const;
|
||||
void set_spells(const Vector<Variant> &data);
|
||||
|
||||
Ref<Aura> get_aura(int aura_id);
|
||||
Ref<Aura> get_aura_index(int index);
|
||||
int get_aura_count();
|
||||
void add_aura(Ref<Aura> aura);
|
||||
Vector<Variant> get_auras() const;
|
||||
void set_auras(const Vector<Variant> &data);
|
||||
|
||||
Ref<CraftRecipe> get_craft_recipe(int craft_id);
|
||||
Ref<CraftRecipe> get_craft_recipe_index(int index);
|
||||
int get_craft_recipe_count();
|
||||
void add_craft_recipe(Ref<CraftRecipe> aura);
|
||||
Vector<Variant> get_craft_recipes() const;
|
||||
void set_craft_recipes(const Vector<Variant> &data);
|
||||
|
||||
void add_item_template(Ref<ItemTemplate> aura);
|
||||
Ref<ItemTemplate> get_item_template(int item_id);
|
||||
Ref<ItemTemplate> get_item_template_index(int index);
|
||||
int get_item_template_count();
|
||||
Vector<Variant> get_item_templates() const;
|
||||
void set_item_templates(const Vector<Variant> &data);
|
||||
|
||||
void add_entity_species_data(Ref<EntitySpeciesData> aura);
|
||||
Ref<EntitySpeciesData> get_entity_species_data(int item_id);
|
||||
Ref<EntitySpeciesData> get_entity_species_data_index(int index);
|
||||
int get_entity_species_data_count();
|
||||
Vector<Variant> get_entity_species_datas() const;
|
||||
void set_entity_species_datas(const Vector<Variant> &data);
|
||||
|
||||
void load_all();
|
||||
void load_xp_data();
|
||||
void load_folders();
|
||||
void load_folder(const String &folder);
|
||||
void add_resource(const Ref<Resource> &resource);
|
||||
|
||||
Ref<Resource> load_resource(const String &path, const String &type_hint = "");
|
||||
|
||||
ESSResourceDBFolders();
|
||||
~ESSResourceDBFolders();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
String _xp_data_path;
|
||||
|
||||
PoolStringArray _folders;
|
||||
|
||||
Vector<Ref<EntityResourceData>> _entity_resources;
|
||||
HashMap<int, Ref<EntityResourceData>> _entity_resource_map;
|
||||
|
||||
Vector<Ref<EntitySkillData>> _entity_skills;
|
||||
HashMap<int, Ref<EntitySkillData>> _entity_skill_map;
|
||||
|
||||
Vector<Ref<EntityData>> _entity_datas;
|
||||
HashMap<int, Ref<EntityData>> _entity_data_map;
|
||||
|
||||
Vector<Ref<Spell>> _spells;
|
||||
HashMap<int, Ref<Spell>> _spell_map;
|
||||
|
||||
Vector<Ref<Aura>> _auras;
|
||||
HashMap<int, Ref<Aura>> _aura_map;
|
||||
|
||||
Vector<Ref<CraftRecipe>> _craft_recipes;
|
||||
HashMap<int, Ref<CraftRecipe>> _craft_recipe_map;
|
||||
|
||||
Vector<Ref<ItemTemplate>> _item_templates;
|
||||
HashMap<int, Ref<ItemTemplate>> _item_template_map;
|
||||
|
||||
Vector<Ref<EntitySpeciesData>> _entity_species_datas;
|
||||
HashMap<int, Ref<EntitySpeciesData>> _entity_species_data_map;
|
||||
|
||||
bool _automatic_load;
|
||||
bool _load_folders;
|
||||
};
|
||||
|
||||
#endif
|
389
database/ess_resource_db_static.cpp
Normal file
389
database/ess_resource_db_static.cpp
Normal file
@ -0,0 +1,389 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "ess_resource_db_static.h"
|
||||
|
||||
#include "../data/auras/aura.h"
|
||||
#include "../data/items/craft_recipe.h"
|
||||
#include "../data/species/entity_species_data.h"
|
||||
#include "../data/spells/spell.h"
|
||||
#include "../entities/data/entity_data.h"
|
||||
#include "../entities/resources/entity_resource_data.h"
|
||||
#include "../entities/skills/entity_skill_data.h"
|
||||
|
||||
Ref<EntityResourceData> ESSResourceDBStatic::get_entity_resource(int id) {
|
||||
if (id < 0 || id > _entity_resources.size())
|
||||
return Ref<EntityResourceData>();
|
||||
|
||||
return _entity_resources.get(id);
|
||||
}
|
||||
Ref<EntityResourceData> ESSResourceDBStatic::get_entity_resource_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref<EntityResourceData>(NULL));
|
||||
|
||||
return _entity_resources.get(index);
|
||||
}
|
||||
int ESSResourceDBStatic::get_entity_resource_count() {
|
||||
return _entity_resources.size();
|
||||
}
|
||||
void ESSResourceDBStatic::add_entity_resource(Ref<EntityResourceData> cls) {
|
||||
if (cls.is_valid())
|
||||
cls->set_id(_entity_resources.size());
|
||||
|
||||
_entity_resources.push_back(cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_entity_resources() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_resources.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_resources[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_resources[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_entity_resources(const Vector<Variant> &data) {
|
||||
_entity_resources.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityResource> d = Ref<EntityResource>(data[i]);
|
||||
|
||||
add_entity_resource(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntitySkillData> ESSResourceDBStatic::get_entity_skill(int id) {
|
||||
if (id < 0 || id > _entity_skills.size())
|
||||
return Ref<EntitySkillData>();
|
||||
|
||||
return _entity_skills.get(id);
|
||||
}
|
||||
Ref<EntitySkillData> ESSResourceDBStatic::get_entity_skill_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_skills.size(), Ref<EntitySkillData>(NULL));
|
||||
|
||||
return _entity_skills.get(index);
|
||||
}
|
||||
int ESSResourceDBStatic::get_entity_skill_count() {
|
||||
return _entity_skills.size();
|
||||
}
|
||||
void ESSResourceDBStatic::add_entity_skill(Ref<EntitySkillData> cls) {
|
||||
if (cls.is_valid())
|
||||
cls->set_id(_entity_skills.size());
|
||||
|
||||
_entity_skills.push_back(cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_entity_skills() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_skills.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_skills[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_skills[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_entity_skills(const Vector<Variant> &data) {
|
||||
_entity_skills.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySkillData> d = Ref<EntitySkillData>(data[i]);
|
||||
|
||||
add_entity_skill(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntityData> ESSResourceDBStatic::get_entity_data(int id) {
|
||||
if (id < 0 || id > _entity_datas.size())
|
||||
return Ref<EntityData>();
|
||||
|
||||
return _entity_datas.get(id);
|
||||
}
|
||||
Ref<EntityData> ESSResourceDBStatic::get_entity_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>(NULL));
|
||||
|
||||
return _entity_datas.get(index);
|
||||
}
|
||||
int ESSResourceDBStatic::get_entity_data_count() {
|
||||
return _entity_datas.size();
|
||||
}
|
||||
void ESSResourceDBStatic::add_entity_data(Ref<EntityData> cls) {
|
||||
if (cls.is_valid())
|
||||
cls->set_id(_entity_datas.size());
|
||||
|
||||
_entity_datas.push_back(cls);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_entity_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_entity_datas(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntityData> d = Ref<EntityData>(data[i]);
|
||||
|
||||
add_entity_data(d);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDBStatic::get_spell(int id) {
|
||||
if (id < 0 || id > _spells.size())
|
||||
return Ref<Spell>();
|
||||
|
||||
return _spells.get(id);
|
||||
}
|
||||
|
||||
Ref<Spell> ESSResourceDBStatic::get_spell_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _spells.size(), Ref<Spell>(NULL));
|
||||
|
||||
return _spells.get(index);
|
||||
}
|
||||
int ESSResourceDBStatic::get_spell_count() {
|
||||
return _spells.size();
|
||||
}
|
||||
void ESSResourceDBStatic::add_spell(Ref<Spell> spell) {
|
||||
if (spell.is_valid())
|
||||
spell->set_id(_spells.size());
|
||||
|
||||
_spells.push_back(spell);
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_spells() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _spells.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_spells[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_spells[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_spells(const Vector<Variant> &data) {
|
||||
_spells.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Spell> d = Ref<Spell>(data[i]);
|
||||
|
||||
add_spell(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBStatic::add_aura(Ref<Aura> aura) {
|
||||
if (aura.is_valid())
|
||||
aura->set_id(_auras.size());
|
||||
|
||||
_auras.push_back(aura);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDBStatic::get_aura(int id) {
|
||||
if (id < 0 || id > _auras.size())
|
||||
return Ref<Aura>();
|
||||
|
||||
return _auras.get(id);
|
||||
}
|
||||
|
||||
Ref<Aura> ESSResourceDBStatic::get_aura_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _auras.size(), Ref<Aura>());
|
||||
|
||||
return _auras.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBStatic::get_aura_count() {
|
||||
return _auras.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDBStatic::get_auras() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _auras.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_auras[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_auras[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_auras(const Vector<Variant> &data) {
|
||||
_auras.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<Aura> d = Ref<Aura>(data[i]);
|
||||
|
||||
add_aura(d);
|
||||
}
|
||||
}
|
||||
|
||||
//Craft Data
|
||||
void ESSResourceDBStatic::add_craft_recipe(Ref<CraftRecipe> cda) {
|
||||
if (cda.is_valid())
|
||||
cda->set_id(_craft_recipes.size());
|
||||
|
||||
_craft_recipes.push_back(cda);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDBStatic::get_craft_recipe(int id) {
|
||||
if (id < 0 || id > _craft_recipes.size())
|
||||
return Ref<CraftRecipe>();
|
||||
|
||||
return _craft_recipes.get(id);
|
||||
}
|
||||
|
||||
Ref<CraftRecipe> ESSResourceDBStatic::get_craft_recipe_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _craft_recipes.size(), Ref<CraftRecipe>());
|
||||
|
||||
return _craft_recipes.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBStatic::get_craft_recipe_count() {
|
||||
return _craft_recipes.size();
|
||||
}
|
||||
|
||||
Vector<Variant> ESSResourceDBStatic::get_craft_recipes() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _craft_recipes.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_craft_recipes[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_craft_recipes[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_craft_recipes(const Vector<Variant> &data) {
|
||||
_craft_recipes.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<CraftRecipe> d = Ref<CraftRecipe>(data[i]);
|
||||
|
||||
add_craft_recipe(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBStatic::add_item_template(Ref<ItemTemplate> cda) {
|
||||
if (cda.is_valid())
|
||||
cda->set_id(_item_templates.size());
|
||||
|
||||
_item_templates.push_back(cda);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDBStatic::get_item_template(int item_id) {
|
||||
if (item_id < 0 || item_id > _item_templates.size())
|
||||
return Ref<ItemTemplate>();
|
||||
|
||||
return _item_templates.get(item_id);
|
||||
}
|
||||
|
||||
Ref<ItemTemplate> ESSResourceDBStatic::get_item_template_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _item_templates.size(), Ref<ItemTemplate>());
|
||||
|
||||
return _item_templates.get(index);
|
||||
}
|
||||
|
||||
int ESSResourceDBStatic::get_item_template_count() {
|
||||
return _item_templates.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_item_templates() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _item_templates.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_item_templates[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_item_templates[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_item_templates(const Vector<Variant> &data) {
|
||||
_item_templates.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<ItemTemplate> d = Ref<ItemTemplate>(data[i]);
|
||||
|
||||
add_item_template(d);
|
||||
}
|
||||
}
|
||||
|
||||
void ESSResourceDBStatic::add_entity_species_data(Ref<EntitySpeciesData> cda) {
|
||||
if (cda.is_valid())
|
||||
cda->set_id(_entity_species_datas.size());
|
||||
|
||||
_entity_species_datas.push_back(cda);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDBStatic::get_entity_species_data(int id) {
|
||||
if (id < 0 || id > _entity_species_datas.size())
|
||||
return Ref<EntitySpeciesData>();
|
||||
|
||||
return _entity_species_datas.get(id);
|
||||
}
|
||||
Ref<EntitySpeciesData> ESSResourceDBStatic::get_entity_species_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_species_datas.size(), Ref<EntitySpeciesData>());
|
||||
|
||||
return _entity_species_datas.get(index);
|
||||
}
|
||||
int ESSResourceDBStatic::get_entity_species_data_count() {
|
||||
return _entity_species_datas.size();
|
||||
}
|
||||
Vector<Variant> ESSResourceDBStatic::get_entity_species_datas() const {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _entity_species_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_entity_species_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_entity_species_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void ESSResourceDBStatic::set_entity_species_datas(const Vector<Variant> &data) {
|
||||
_entity_species_datas.clear();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Ref<EntitySpeciesData> d = Ref<EntitySpeciesData>(data[i]);
|
||||
|
||||
add_entity_species_data(d);
|
||||
}
|
||||
}
|
||||
|
||||
ESSResourceDBStatic::ESSResourceDBStatic() {
|
||||
}
|
||||
|
||||
ESSResourceDBStatic::~ESSResourceDBStatic() {
|
||||
_entity_resources.clear();
|
||||
_entity_skills.clear();
|
||||
_entity_datas.clear();
|
||||
_spells.clear();
|
||||
_auras.clear();
|
||||
_craft_recipes.clear();
|
||||
_item_templates.clear();
|
||||
_entity_species_datas.clear();
|
||||
}
|
||||
|
||||
void ESSResourceDBStatic::_bind_methods() {
|
||||
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_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_spells", "get_spells");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "auras", PROPERTY_HINT_NONE, "17/17:Aura", PROPERTY_USAGE_DEFAULT, "Aura"), "set_auras", "get_auras");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "craft_recipes", PROPERTY_HINT_NONE, "17/17:CraftRecipe", PROPERTY_USAGE_DEFAULT, "CraftRecipe"), "set_craft_recipes", "get_craft_recipes");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "item_templates", PROPERTY_HINT_NONE, "17/17:ItemTemplate", PROPERTY_USAGE_DEFAULT, "ItemTemplate"), "set_item_templates", "get_item_templates");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_species_datas", PROPERTY_HINT_NONE, "17/17:EntitySpeciesData", PROPERTY_USAGE_DEFAULT, "EntitySpeciesData"), "set_entity_species_datas", "get_entity_species_datas");
|
||||
}
|
136
database/ess_resource_db_static.h
Normal file
136
database/ess_resource_db_static.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ESS_RESOURCE_DB_STATIC_H
|
||||
#define ESS_RESOURCE_DB_STATIC_H
|
||||
|
||||
#include "ess_resource_db.h"
|
||||
|
||||
#include "core/hash_map.h"
|
||||
|
||||
#include "../item_enums.h"
|
||||
|
||||
#include "../data/entities/xp_data.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define PoolStringArray PackedStringArray
|
||||
|
||||
#define POOL_STRING_ARRAY PACKED_STRING_ARRAY
|
||||
#endif
|
||||
|
||||
class Aura;
|
||||
class Spell;
|
||||
class EntityData;
|
||||
class CraftRecipe;
|
||||
class ItemTemplate;
|
||||
class EntityResourceData;
|
||||
class EntitySkillData;
|
||||
class EntityCreateInfo;
|
||||
class SpellCastInfo;
|
||||
class EntitySpeciesData;
|
||||
|
||||
class ESSResourceDBStatic : public ESSResourceDB {
|
||||
GDCLASS(ESSResourceDBStatic, ESSResourceDB);
|
||||
|
||||
public:
|
||||
String get_xp_data_path();
|
||||
void set_xp_data_path(String path);
|
||||
|
||||
PoolStringArray get_folders() const;
|
||||
void set_folders(const PoolStringArray &folders);
|
||||
|
||||
Ref<EntityResourceData> get_entity_resource(int class_id);
|
||||
Ref<EntityResourceData> get_entity_resource_index(int index);
|
||||
int get_entity_resource_count();
|
||||
void add_entity_resource(Ref<EntityResourceData> cls);
|
||||
Vector<Variant> get_entity_resources() const;
|
||||
void set_entity_resources(const Vector<Variant> &data);
|
||||
|
||||
Ref<EntitySkillData> get_entity_skill(int class_id);
|
||||
Ref<EntitySkillData> get_entity_skill_index(int index);
|
||||
int get_entity_skill_count();
|
||||
void add_entity_skill(Ref<EntitySkillData> cls);
|
||||
Vector<Variant> get_entity_skills() const;
|
||||
void set_entity_skills(const Vector<Variant> &data);
|
||||
|
||||
Ref<EntityData> get_entity_data(int class_id);
|
||||
Ref<EntityData> get_entity_data_index(int index);
|
||||
int get_entity_data_count();
|
||||
void add_entity_data(Ref<EntityData> cls);
|
||||
Vector<Variant> get_entity_datas() const;
|
||||
void set_entity_datas(const Vector<Variant> &data);
|
||||
|
||||
Ref<Spell> get_spell(int spell_id);
|
||||
Ref<Spell> get_spell_index(int index);
|
||||
int get_spell_count();
|
||||
void add_spell(Ref<Spell> spell);
|
||||
Vector<Variant> get_spells() const;
|
||||
void set_spells(const Vector<Variant> &data);
|
||||
|
||||
Ref<Aura> get_aura(int aura_id);
|
||||
Ref<Aura> get_aura_index(int index);
|
||||
int get_aura_count();
|
||||
void add_aura( Ref<Aura> aura);
|
||||
Vector<Variant> get_auras() const;
|
||||
void set_auras(const Vector<Variant> &data);
|
||||
|
||||
Ref<CraftRecipe> get_craft_recipe(int craft_id);
|
||||
Ref<CraftRecipe> get_craft_recipe_index(int index);
|
||||
int get_craft_recipe_count();
|
||||
void add_craft_recipe(Ref<CraftRecipe> aura);
|
||||
Vector<Variant> get_craft_recipes() const;
|
||||
void set_craft_recipes(const Vector<Variant> &data);
|
||||
|
||||
void add_item_template(Ref<ItemTemplate> aura);
|
||||
Ref<ItemTemplate> get_item_template(int item_id);
|
||||
Ref<ItemTemplate> get_item_template_index(int index);
|
||||
int get_item_template_count();
|
||||
Vector<Variant> get_item_templates() const;
|
||||
void set_item_templates(const Vector<Variant> &data);
|
||||
|
||||
void add_entity_species_data(Ref<EntitySpeciesData> aura);
|
||||
Ref<EntitySpeciesData> get_entity_species_data(int item_id);
|
||||
Ref<EntitySpeciesData> get_entity_species_data_index(int index);
|
||||
int get_entity_species_data_count();
|
||||
Vector<Variant> get_entity_species_datas() const;
|
||||
void set_entity_species_datas(const Vector<Variant> &data);
|
||||
|
||||
ESSResourceDBStatic();
|
||||
~ESSResourceDBStatic();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Vector<Ref<EntityResourceData>> _entity_resources;
|
||||
Vector<Ref<EntitySkillData>> _entity_skills;
|
||||
Vector<Ref<EntityData>> _entity_datas;
|
||||
Vector<Ref<Spell>> _spells;
|
||||
Vector<Ref<Aura>> _auras;
|
||||
Vector<Ref<CraftRecipe>> _craft_recipes;
|
||||
Vector<Ref<ItemTemplate>> _item_templates;
|
||||
Vector<Ref<EntitySpeciesData>> _entity_species_datas;
|
||||
};
|
||||
|
||||
#endif
|
@ -27,6 +27,7 @@ SOFTWARE.
|
||||
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#include "core/io/json.h"
|
||||
#include "../data/entities/xp_data.h"
|
||||
#include "../data/items/craft_recipe.h"
|
||||
#include "../data/items/item_instance.h"
|
||||
|
@ -136,6 +136,8 @@ SOFTWARE.
|
||||
#include "editor/ess_editor_plugin.h"
|
||||
|
||||
#include "database/ess_resource_db.cpp"
|
||||
#include "database/ess_resource_db_static.h"
|
||||
#include "database/ess_resource_db_folders.h"
|
||||
|
||||
static ESS *entity_data_manager = NULL;
|
||||
static ProfileManager *profile_manager = NULL;
|
||||
@ -251,7 +253,9 @@ void register_entity_spell_system_types() {
|
||||
ClassDB::register_class<AIFormation>();
|
||||
|
||||
//Resources
|
||||
ClassDB::register_class<ESSResourceDB>();
|
||||
ClassDB::register_virtual_class<ESSResourceDB>();
|
||||
ClassDB::register_class<ESSResourceDBStatic>();
|
||||
ClassDB::register_class<ESSResourceDBFolders>();
|
||||
|
||||
//ProfileManager
|
||||
ClassDB::register_class<InputProfileModifier>();
|
||||
|
Loading…
Reference in New Issue
Block a user