/* Copyright (c) 2019-2022 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_map.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.h" #include "../entities/skills/entity_skill_data.h" Ref ESSResourceDBMap::get_entity_resource(int class_id) { //ERR_FAIL_COND_V_MSG(!_entity_resource_map.has(class_id), Ref(), "Could not find EntityResource! Id:" + String::num(class_id)); if (!_entity_resource_map.has(class_id)) { return Ref(); } return _entity_resource_map.get(class_id); } Ref ESSResourceDBMap::get_entity_resource_index(int index) { ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref(NULL)); return _entity_resources.get(index); } int ESSResourceDBMap::get_entity_resource_count() { return _entity_resources.size(); } void ESSResourceDBMap::add_entity_resource(Ref cls) { ERR_FAIL_COND(!cls.is_valid()); _entity_resources.push_back(cls); _entity_resource_map.set(cls->get_id(), cls); ESSResourceDB::add_entity_resource(cls); } Vector ESSResourceDBMap::get_entity_resources() const { VARIANT_ARRAY_GET(_entity_resources); } void ESSResourceDBMap::set_entity_resources(const Vector &data) { _entity_resources.clear(); _entity_resource_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_entity_resource(d); } } Ref ESSResourceDBMap::get_entity_skill(int class_id) { ERR_FAIL_COND_V_MSG(!_entity_skill_map.has(class_id), Ref(), "Could not find EntitySkillData! Id:" + String::num(class_id)); return _entity_skill_map.get(class_id); } Ref ESSResourceDBMap::get_entity_skill_index(int index) { ERR_FAIL_INDEX_V(index, _entity_skills.size(), Ref(NULL)); return _entity_skills.get(index); } int ESSResourceDBMap::get_entity_skill_count() { return _entity_skills.size(); } void ESSResourceDBMap::add_entity_skill(Ref cls) { ERR_FAIL_COND(!cls.is_valid()); _entity_skills.push_back(cls); _entity_skill_map.set(cls->get_id(), cls); ESSResourceDB::add_entity_skill(cls); } Vector ESSResourceDBMap::get_entity_skills() const { VARIANT_ARRAY_GET(_entity_skills); } void ESSResourceDBMap::set_entity_skills(const Vector &data) { _entity_skills.clear(); _entity_skill_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_entity_skill(d); } } Ref ESSResourceDBMap::get_entity_data(int class_id) { ERR_FAIL_COND_V_MSG(!_entity_data_map.has(class_id), Ref(), "Could not find EntityData! Id:" + String::num(class_id)); return _entity_data_map.get(class_id); } Ref ESSResourceDBMap::get_entity_data_index(int index) { ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref(NULL)); return _entity_datas.get(index); } int ESSResourceDBMap::get_entity_data_count() { return _entity_datas.size(); } void ESSResourceDBMap::add_entity_data(Ref cls) { ERR_FAIL_COND(!cls.is_valid()); _entity_datas.push_back(cls); _entity_data_map.set(cls->get_id(), cls); ESSResourceDB::add_entity_data(cls); } Vector ESSResourceDBMap::get_entity_datas() const { VARIANT_ARRAY_GET(_entity_datas); } void ESSResourceDBMap::set_entity_datas(const Vector &data) { _craft_recipes.clear(); _craft_recipe_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_entity_data(d); } } Ref ESSResourceDBMap::get_spell(int spell_id) { ERR_FAIL_COND_V_MSG(!_spell_map.has(spell_id), Ref(), "Could not find Spell! Id:" + String::num(spell_id)); return _spell_map.get(spell_id); } Ref ESSResourceDBMap::get_spell_index(int index) { ERR_FAIL_INDEX_V(index, _spells.size(), Ref(NULL)); return _spells.get(index); } int ESSResourceDBMap::get_spell_count() { return _spells.size(); } void ESSResourceDBMap::add_spell(Ref spell) { ERR_FAIL_COND(!spell.is_valid()); _spells.push_back(spell); _spell_map.set(spell->get_id(), spell); ESSResourceDB::add_spell(spell); } Vector ESSResourceDBMap::get_spells() const { VARIANT_ARRAY_GET(_spells); } void ESSResourceDBMap::set_spells(const Vector &data) { _spells.clear(); _spell_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_spell(d); } } //Craft Data void ESSResourceDBMap::add_craft_recipe(Ref cda) { ERR_FAIL_COND(!cda.is_valid()); _craft_recipes.push_back(cda); _craft_recipe_map.set(cda->get_id(), cda); ESSResourceDB::add_craft_recipe(cda); } Ref ESSResourceDBMap::get_craft_recipe(int craft_id) { ERR_FAIL_COND_V_MSG(!_craft_recipe_map.has(craft_id), Ref(), "Could not find CraftRecipe! Id:" + String::num(craft_id)); return _craft_recipe_map.get(craft_id); } Ref ESSResourceDBMap::get_craft_recipe_index(int index) { ERR_FAIL_INDEX_V(index, _craft_recipes.size(), Ref()); return _craft_recipes.get(index); } int ESSResourceDBMap::get_craft_recipe_count() { return _craft_recipes.size(); } Vector ESSResourceDBMap::get_craft_recipes() const { VARIANT_ARRAY_GET(_craft_recipes); } void ESSResourceDBMap::set_craft_recipes(const Vector &data) { _craft_recipes.clear(); _craft_recipe_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_craft_recipe(d); } } void ESSResourceDBMap::add_item_template(Ref cda) { ERR_FAIL_COND(!cda.is_valid()); _item_templates.push_back(cda); _item_template_map.set(cda->get_id(), cda); ESSResourceDB::add_item_template(cda); } Ref ESSResourceDBMap::get_item_template(int item_id) { ERR_FAIL_COND_V_MSG(!_item_template_map.has(item_id), Ref(), "Could not find ItemTemplate! Id:" + String::num(item_id)); return _item_template_map.get(item_id); } Ref ESSResourceDBMap::get_item_template_index(int index) { ERR_FAIL_INDEX_V(index, _item_templates.size(), Ref()); return _item_templates.get(index); } int ESSResourceDBMap::get_item_template_count() { return _item_templates.size(); } Vector ESSResourceDBMap::get_item_templates() const { VARIANT_ARRAY_GET(_item_templates); } void ESSResourceDBMap::set_item_templates(const Vector &data) { _item_templates.clear(); _item_template_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_item_template(d); } } void ESSResourceDBMap::add_entity_species_data(Ref cda) { ERR_FAIL_COND(!cda.is_valid()); _entity_species_datas.push_back(cda); _entity_species_data_map.set(cda->get_id(), cda); ESSResourceDB::add_entity_species_data(cda); } Ref ESSResourceDBMap::get_entity_species_data(int item_id) { if (!_entity_species_data_map.has(item_id)) return Ref(); return _entity_species_data_map.get(item_id); } Ref ESSResourceDBMap::get_entity_species_data_index(int index) { ERR_FAIL_INDEX_V(index, _entity_species_datas.size(), Ref()); return _entity_species_datas.get(index); } int ESSResourceDBMap::get_entity_species_data_count() { return _entity_species_datas.size(); } Vector ESSResourceDBMap::get_entity_species_datas() const { VARIANT_ARRAY_GET(_entity_species_datas); } void ESSResourceDBMap::set_entity_species_datas(const Vector &data) { _entity_species_datas.clear(); _entity_species_data_map.clear(); for (int i = 0; i < data.size(); i++) { Ref d = Ref(data[i]); ERR_CONTINUE(!d.is_valid()); add_item_template(d); } } ESSResourceDBMap::ESSResourceDBMap() { } ESSResourceDBMap::~ESSResourceDBMap() { _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(); _craft_recipes.clear(); _craft_recipe_map.clear(); _item_templates.clear(); _item_template_map.clear(); _entity_species_datas.clear(); _entity_species_data_map.clear(); } void ESSResourceDBMap::_bind_methods() { }