mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-22 17:18:12 +01:00
Added WorldSpells to the DataManager. Also fixed logic for loading if ERR_CONTINUEs happen.
This commit is contained in:
parent
ba1a170fc0
commit
8826258852
@ -19,7 +19,8 @@ void EntityDataManager::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (get_automatic_load()) {
|
||||
load_all();
|
||||
if (!Engine::get_singleton()->is_editor_hint())
|
||||
load_all();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
@ -205,6 +206,37 @@ int EntityDataManager::get_aura_count() {
|
||||
return _auras.size();
|
||||
}
|
||||
|
||||
//WorldSpellsDatas
|
||||
String EntityDataManager::get_world_spell_datas_folder() {
|
||||
return _world_spell_datas_folder;
|
||||
}
|
||||
void EntityDataManager::set_world_spell_datas_folder(String folder) {
|
||||
_world_spell_datas_folder = folder;
|
||||
}
|
||||
Vector<Ref<WorldSpellData> > *EntityDataManager::get_world_spell_datas() {
|
||||
return &_world_spell_datas;
|
||||
}
|
||||
Ref<WorldSpellData> EntityDataManager::get_world_spell_data(int class_id) {
|
||||
if (!_world_spell_data_map.has(class_id))
|
||||
return Ref<WorldSpellData>(NULL);
|
||||
|
||||
return _world_spell_data_map.get(class_id);
|
||||
}
|
||||
Ref<WorldSpellData> EntityDataManager::get_world_spell_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _world_spell_datas.size(), Ref<WorldSpellData>(NULL));
|
||||
|
||||
return _world_spell_datas.get(index);
|
||||
}
|
||||
int EntityDataManager::get_world_spell_data_count() {
|
||||
return _world_spell_datas.size();
|
||||
}
|
||||
void EntityDataManager::add_world_spell_data(Ref<WorldSpellData> cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
_world_spell_datas.push_back(cls);
|
||||
_world_spell_data_map.set(cls->get_id(), cls);
|
||||
}
|
||||
|
||||
//Craft Data
|
||||
void EntityDataManager::add_craft_data(Ref<CraftRecipe> cda) {
|
||||
ERR_FAIL_COND(!cda.is_valid());
|
||||
@ -344,6 +376,7 @@ void EntityDataManager::load_all() {
|
||||
load_entity_skills();
|
||||
load_spells();
|
||||
load_auras();
|
||||
load_world_spell_datas();
|
||||
load_characters();
|
||||
load_craft_datas();
|
||||
load_item_templates();
|
||||
@ -360,6 +393,8 @@ void EntityDataManager::load_xp_data() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(_xp_data_path, "XPData");
|
||||
|
||||
ERR_FAIL_COND(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -382,9 +417,14 @@ void EntityDataManager::load_entity_resources() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _entity_resources_folder + "/" + filename;
|
||||
|
||||
@ -392,6 +432,8 @@ void EntityDataManager::load_entity_resources() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "EntityResourceData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -404,8 +446,6 @@ void EntityDataManager::load_entity_resources() {
|
||||
|
||||
add_entity_resource(eresd);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -421,9 +461,14 @@ void EntityDataManager::load_entity_skills() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _entity_skills_folder + "/" + filename;
|
||||
|
||||
@ -431,6 +476,8 @@ void EntityDataManager::load_entity_skills() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "EntitySkillData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -443,8 +490,6 @@ void EntityDataManager::load_entity_skills() {
|
||||
|
||||
add_entity_skill(eskilld);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -461,9 +506,14 @@ void EntityDataManager::load_spells() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _spells_folder + "/" + filename;
|
||||
|
||||
@ -471,6 +521,8 @@ void EntityDataManager::load_spells() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "Spell");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -483,8 +535,6 @@ void EntityDataManager::load_spells() {
|
||||
|
||||
add_spell(spell);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -500,9 +550,14 @@ void EntityDataManager::load_auras() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _auras_folder + "/" + filename;
|
||||
|
||||
@ -510,6 +565,8 @@ void EntityDataManager::load_auras() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "Aura");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -522,8 +579,50 @@ void EntityDataManager::load_auras() {
|
||||
|
||||
add_aura(aura);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
}
|
||||
}
|
||||
|
||||
void EntityDataManager::load_world_spell_datas() {
|
||||
_Directory dir;
|
||||
|
||||
ERR_FAIL_COND(_world_spell_datas_folder.ends_with("/"));
|
||||
|
||||
if (dir.open(_world_spell_datas_folder) == OK) {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _world_spell_datas_folder + "/" + filename;
|
||||
|
||||
_ResourceLoader *rl = _ResourceLoader::get_singleton();
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "WorldSpellData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
|
||||
ERR_CONTINUE(!s.is_valid());
|
||||
|
||||
Ref<WorldSpellData> wsp = s;
|
||||
|
||||
ERR_CONTINUE(!wsp.is_valid());
|
||||
|
||||
add_world_spell_data(wsp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -539,9 +638,14 @@ void EntityDataManager::load_characters() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _entity_datas_folder + "/" + filename;
|
||||
|
||||
@ -549,6 +653,8 @@ void EntityDataManager::load_characters() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "EntityData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -561,8 +667,6 @@ void EntityDataManager::load_characters() {
|
||||
|
||||
add_entity_data(cls);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -578,9 +682,14 @@ void EntityDataManager::load_craft_datas() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _craft_data_folder + "/" + filename;
|
||||
|
||||
@ -588,6 +697,8 @@ void EntityDataManager::load_craft_datas() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "CraftRecipe");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -600,8 +711,6 @@ void EntityDataManager::load_craft_datas() {
|
||||
|
||||
add_craft_data(cda);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -617,9 +726,14 @@ void EntityDataManager::load_item_templates() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _item_template_folder + "/" + filename;
|
||||
|
||||
@ -627,6 +741,8 @@ void EntityDataManager::load_item_templates() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "ItemTemplate");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -639,8 +755,6 @@ void EntityDataManager::load_item_templates() {
|
||||
|
||||
add_item_template(it);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -656,9 +770,14 @@ void EntityDataManager::load_mob_datas() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _mob_data_folder + "/" + filename;
|
||||
|
||||
@ -666,6 +785,8 @@ void EntityDataManager::load_mob_datas() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "EntityData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -678,8 +799,6 @@ void EntityDataManager::load_mob_datas() {
|
||||
|
||||
add_mob_data(mob_data);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -695,9 +814,14 @@ void EntityDataManager::load_player_character_datas() {
|
||||
|
||||
dir.list_dir_begin();
|
||||
|
||||
String filename = dir.get_next();
|
||||
String filename;
|
||||
|
||||
while (true) {
|
||||
filename = dir.get_next();
|
||||
|
||||
if (filename == "")
|
||||
break;
|
||||
|
||||
while (filename != "") {
|
||||
if (!dir.current_is_dir()) {
|
||||
String path = _player_character_data_folder + "/" + filename;
|
||||
|
||||
@ -705,6 +829,8 @@ void EntityDataManager::load_player_character_datas() {
|
||||
|
||||
Ref<ResourceInteractiveLoader> resl = rl->load_interactive(path, "EntityData");
|
||||
|
||||
ERR_CONTINUE(!resl.is_valid());
|
||||
|
||||
resl->wait();
|
||||
|
||||
Ref<Resource> s = resl->get_resource();
|
||||
@ -717,8 +843,6 @@ void EntityDataManager::load_player_character_datas() {
|
||||
|
||||
add_player_character_data(pcd);
|
||||
}
|
||||
|
||||
filename = dir.get_next();
|
||||
}
|
||||
} else {
|
||||
print_error("An error occurred when trying to access the path.");
|
||||
@ -794,6 +918,16 @@ void EntityDataManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_aura_index", "index"), &EntityDataManager::get_aura_index);
|
||||
ClassDB::bind_method(D_METHOD("get_aura_count"), &EntityDataManager::get_aura_count);
|
||||
|
||||
//WorldSpellData
|
||||
ClassDB::bind_method(D_METHOD("get_world_spell_datas_folder"), &EntityDataManager::get_world_spell_datas_folder);
|
||||
ClassDB::bind_method(D_METHOD("set_world_spell_datas_folder", "folder"), &EntityDataManager::set_world_spell_datas_folder);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "world_spell_datas_folder"), "set_world_spell_datas_folder", "get_world_spell_datas_folder");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_world_spell_data", "cls"), &EntityDataManager::add_world_spell_data);
|
||||
ClassDB::bind_method(D_METHOD("get_world_spell_data", "class_id"), &EntityDataManager::get_world_spell_data);
|
||||
ClassDB::bind_method(D_METHOD("get_world_spell_data_index", "index"), &EntityDataManager::get_world_spell_data_index);
|
||||
ClassDB::bind_method(D_METHOD("get_world_spell_data_count"), &EntityDataManager::get_world_spell_data_count);
|
||||
|
||||
//Craft Data
|
||||
ClassDB::bind_method(D_METHOD("get_craft_data_folder"), &EntityDataManager::get_craft_data_folder);
|
||||
ClassDB::bind_method(D_METHOD("set_craft_data_folder", "folder"), &EntityDataManager::set_craft_data_folder);
|
||||
@ -841,6 +975,7 @@ void EntityDataManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("load_xp_data"), &EntityDataManager::load_xp_data);
|
||||
ClassDB::bind_method(D_METHOD("load_spells"), &EntityDataManager::load_spells);
|
||||
ClassDB::bind_method(D_METHOD("load_auras"), &EntityDataManager::load_auras);
|
||||
ClassDB::bind_method(D_METHOD("load_world_spell_datas"), &EntityDataManager::load_world_spell_datas);
|
||||
ClassDB::bind_method(D_METHOD("load_characters"), &EntityDataManager::load_characters);
|
||||
ClassDB::bind_method(D_METHOD("load_craft_datas"), &EntityDataManager::load_craft_datas);
|
||||
ClassDB::bind_method(D_METHOD("load_item_templates"), &EntityDataManager::load_item_templates);
|
||||
@ -872,6 +1007,9 @@ EntityDataManager::~EntityDataManager() {
|
||||
_auras.clear();
|
||||
_aura_map.clear();
|
||||
|
||||
_world_spell_datas.clear();
|
||||
_world_spell_data_map.clear();
|
||||
|
||||
_craft_datas.clear();
|
||||
_craft_data_map.clear();
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "core/io/json.h"
|
||||
#include "core/variant.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/engine.h"
|
||||
|
||||
#include "core/resource.h"
|
||||
#include "core/ustring.h"
|
||||
@ -17,6 +18,8 @@
|
||||
|
||||
#include "../data/xp_data.h"
|
||||
|
||||
#include "../world_spells/world_spell_data.h"
|
||||
|
||||
class Aura;
|
||||
class Spell;
|
||||
class EntityData;
|
||||
@ -25,6 +28,7 @@ class ItemTemplate;
|
||||
class EntityResourceData;
|
||||
class EntitySkillData;
|
||||
|
||||
|
||||
class EntityDataManager : public Node {
|
||||
GDCLASS(EntityDataManager, Node);
|
||||
|
||||
@ -78,6 +82,14 @@ public:
|
||||
int get_aura_count();
|
||||
void add_aura(Ref<Aura> aura);
|
||||
|
||||
String get_world_spell_datas_folder();
|
||||
void set_world_spell_datas_folder(String folder);
|
||||
Vector<Ref<WorldSpellData> > *get_world_spell_datas();
|
||||
Ref<WorldSpellData> get_world_spell_data(int class_id);
|
||||
Ref<WorldSpellData> get_world_spell_data_index(int index);
|
||||
int get_world_spell_data_count();
|
||||
void add_world_spell_data(Ref<WorldSpellData> cls);
|
||||
|
||||
String get_craft_data_folder();
|
||||
void set_craft_data_folder(String folder);
|
||||
Vector<Ref<CraftRecipe> > *get_craft_datas();
|
||||
@ -116,6 +128,7 @@ public:
|
||||
void load_xp_data();
|
||||
void load_spells();
|
||||
void load_auras();
|
||||
void load_world_spell_datas();
|
||||
void load_characters();
|
||||
void load_craft_datas();
|
||||
void load_item_templates();
|
||||
@ -156,6 +169,10 @@ private:
|
||||
Vector<Ref<Aura> > _auras;
|
||||
HashMap<int, Ref<Aura> > _aura_map;
|
||||
|
||||
String _world_spell_datas_folder;
|
||||
Vector<Ref<WorldSpellData> > _world_spell_datas;
|
||||
HashMap<int, Ref<WorldSpellData> > _world_spell_data_map;
|
||||
|
||||
String _craft_data_folder;
|
||||
Vector<Ref<CraftRecipe> > _craft_datas;
|
||||
HashMap<int, Ref<CraftRecipe> > _craft_data_map;
|
||||
|
Loading…
Reference in New Issue
Block a user