mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-04-19 21:33:15 +02:00
Added EntityResourceDatas to the DataManager, also more refactorings.
This commit is contained in:
parent
ea06b2346b
commit
b3cb5b2def
@ -1553,16 +1553,16 @@ Ref<EntityResource> Entity::gets_resource(int index) {
|
||||
|
||||
return _s_resources.get(index);
|
||||
}
|
||||
Ref<EntityResource> Entity::gets_resource_type(int type) {
|
||||
Ref<EntityResource> Entity::gets_resource_type(int id) {
|
||||
for (int i = 0; i < _s_resources.size(); ++i) {
|
||||
Ref<EntityResource> r = _s_resources.get(i);
|
||||
|
||||
if (r->get_resource_type() == type) {
|
||||
if (r->get_data_id() == id) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return Ref<EntityResource>(NULL);
|
||||
return Ref<EntityResource>();
|
||||
}
|
||||
void Entity::adds_resource(Ref<EntityResource> resource) {
|
||||
ERR_FAIL_COND(!resource.is_valid());
|
||||
@ -1595,7 +1595,7 @@ Ref<EntityResource> Entity::getc_resource_type(int type) {
|
||||
for (int i = 0; i < _c_resources.size(); ++i) {
|
||||
Ref<EntityResource> r = _c_resources.get(i);
|
||||
|
||||
if (r->get_resource_type() == type) {
|
||||
if (r->get_data_id() == type) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "../entity.h"
|
||||
#include "../stats/stat.h"
|
||||
#include "entity_resource_data.h"
|
||||
|
||||
bool EntityResource::get_dirty() {
|
||||
return _dirty;
|
||||
@ -17,15 +18,27 @@ void EntityResource::set_should_process(bool value) {
|
||||
_should_process = value;
|
||||
}
|
||||
|
||||
int EntityResource::get_resource_type() {
|
||||
return _type;
|
||||
Ref<EntityResourceData> EntityResource::get_resource_data() {
|
||||
return _data;
|
||||
}
|
||||
void EntityResource::set_resource_type(int value) {
|
||||
_type = value;
|
||||
void EntityResource::set_resource_data(Ref<EntityResourceData> value) {
|
||||
_data = value;
|
||||
|
||||
if (_data.is_valid())
|
||||
_data_id = _data->get_id();
|
||||
else
|
||||
_data_id = 0;
|
||||
|
||||
emit_signal("changed", Ref<EntityResource>(this));
|
||||
}
|
||||
|
||||
int EntityResource::get_data_id() {
|
||||
return _data_id;
|
||||
}
|
||||
void EntityResource::set_data_id(int value) {
|
||||
_data_id = value;
|
||||
}
|
||||
|
||||
int EntityResource::get_current() {
|
||||
return _current;
|
||||
}
|
||||
@ -113,6 +126,12 @@ void EntityResource::receivec_update_string(String str) {
|
||||
call("_receivec_update_string", str);
|
||||
}
|
||||
|
||||
void EntityResource::resolve_references() {
|
||||
if (EntityDataManager::get_instance() != NULL) {
|
||||
_data = EntityDataManager::get_instance()->get_entity_resource(_data_id);
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary EntityResource::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
@ -126,7 +145,7 @@ Dictionary EntityResource::_to_dict() {
|
||||
dict["dirty"] = _dirty;
|
||||
dict["should_process"] = _should_process;
|
||||
|
||||
dict["type"] = _type;
|
||||
dict["data_id"] = _data_id;
|
||||
dict["current"] = _current;
|
||||
|
||||
dict["max"] = _max;
|
||||
@ -138,7 +157,7 @@ void EntityResource::_from_dict(const Dictionary &dict) {
|
||||
|
||||
_dirty = dict.get("dirty", false);
|
||||
_should_process = dict.get("should_process", false);
|
||||
_type = dict.get("type", 0);
|
||||
_data_id = dict.get("data_id", 0);
|
||||
_current = dict.get("current", 0);
|
||||
_max = dict.get("max", 0);
|
||||
}
|
||||
@ -148,7 +167,7 @@ EntityResource::EntityResource() {
|
||||
|
||||
_should_process = has_method("_process");
|
||||
|
||||
_type = 0;
|
||||
_data_id = 0;
|
||||
_current = 0;
|
||||
_max = 0;
|
||||
}
|
||||
@ -162,9 +181,13 @@ void EntityResource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_should_process", "value"), &EntityResource::set_should_process);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "should_process"), "set_should_process", "get_should_process");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_resource_type"), &EntityResource::get_resource_type);
|
||||
ClassDB::bind_method(D_METHOD("set_resource_type", "value"), &EntityResource::set_resource_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "resource_type"), "set_resource_type", "get_resource_type");
|
||||
ClassDB::bind_method(D_METHOD("get_resource_data"), &EntityResource::get_resource_data);
|
||||
ClassDB::bind_method(D_METHOD("set_resource_data", "value"), &EntityResource::set_resource_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "resource_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityResourceData"), "set_resource_data", "get_resource_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_data_id"), &EntityResource::get_data_id);
|
||||
ClassDB::bind_method(D_METHOD("set_data_id", "value"), &EntityResource::set_data_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_id"), "set_data_id", "get_data_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_current"), &EntityResource::get_current);
|
||||
ClassDB::bind_method(D_METHOD("set_current", "value"), &EntityResource::set_current);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
class Stat;
|
||||
class Entity;
|
||||
class EntityResourceData;
|
||||
|
||||
class EntityResource : public Reference {
|
||||
GDCLASS(EntityResource, Reference);
|
||||
@ -16,8 +17,11 @@ public:
|
||||
bool get_should_process();
|
||||
void set_should_process(bool value);
|
||||
|
||||
int get_resource_type();
|
||||
void set_resource_type(int value);
|
||||
Ref<EntityResourceData> get_resource_data();
|
||||
void set_resource_data(Ref<EntityResourceData> value);
|
||||
|
||||
int get_data_id();
|
||||
void set_data_id(int value);
|
||||
|
||||
int get_current();
|
||||
void set_current(int value);
|
||||
@ -44,6 +48,8 @@ public:
|
||||
String gets_update_string();
|
||||
void receivec_update_string(String str);
|
||||
|
||||
void resolve_references();
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
@ -59,7 +65,10 @@ private:
|
||||
Entity *_owner;
|
||||
bool _dirty;
|
||||
bool _should_process;
|
||||
int _type;
|
||||
|
||||
Ref<EntityResourceData> _data;
|
||||
int _data_id;
|
||||
|
||||
int _current;
|
||||
int _max;
|
||||
};
|
||||
|
@ -1,5 +1,12 @@
|
||||
#include "entity_resource_data.h"
|
||||
|
||||
int EntityResourceData::get_id() {
|
||||
return _id;
|
||||
}
|
||||
void EntityResourceData::set_id(int value) {
|
||||
_id = value;
|
||||
}
|
||||
|
||||
Ref<EntityResource> EntityResourceData::get_entity_resource_instance() {
|
||||
if (has_method("_get_entity_resource_instance")) {
|
||||
return call("_get_entity_resource_instance");
|
||||
@ -9,9 +16,14 @@ Ref<EntityResource> EntityResourceData::get_entity_resource_instance() {
|
||||
}
|
||||
|
||||
EntityResourceData::EntityResourceData() {
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
void EntityResourceData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_id"), &EntityResourceData::get_id);
|
||||
ClassDB::bind_method(D_METHOD("set_id", "value"), &EntityResourceData::set_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "res", PROPERTY_HINT_RESOURCE_TYPE, "EntityResource"), "_get_entity_resource_instance"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resource_instance"), &EntityResourceData::get_entity_resource_instance);
|
||||
|
@ -10,12 +10,18 @@ class EntityResourceData : public Resource {
|
||||
GDCLASS(EntityResourceData, Resource);
|
||||
|
||||
public:
|
||||
int get_id();
|
||||
void set_id(int value);
|
||||
|
||||
Ref<EntityResource> get_entity_resource_instance();
|
||||
|
||||
EntityResourceData();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _id;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -47,35 +47,59 @@ Ref<XPData> EntityDataManager::get_xp_data() {
|
||||
return _xp_data;
|
||||
}
|
||||
|
||||
String EntityDataManager::get_entity_resources_folder() {
|
||||
return _entity_resources_folder;
|
||||
}
|
||||
void EntityDataManager::set_entity_resources_folder(String folder) {
|
||||
_entity_resources_folder = folder;
|
||||
}
|
||||
Vector<Ref<EntityResourceData> > *EntityDataManager::get_entity_resources() {
|
||||
return &_entity_resources;
|
||||
}
|
||||
Ref<EntityResourceData> EntityDataManager::get_entity_resource(int class_id) {
|
||||
if (!_entity_resource_map.has(class_id))
|
||||
return Ref<EntityResourceData>(NULL);
|
||||
|
||||
return _entity_resource_map.get(class_id);
|
||||
}
|
||||
Ref<EntityResourceData> EntityDataManager::get_entity_resource_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref<EntityResourceData>(NULL));
|
||||
|
||||
return _entity_resources.get(index);
|
||||
}
|
||||
int EntityDataManager::get_entity_resource_count() {
|
||||
return _entity_resources.size();
|
||||
}
|
||||
void EntityDataManager::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);
|
||||
}
|
||||
|
||||
String EntityDataManager::get_entity_datas_folder() {
|
||||
return _entity_datas_folder;
|
||||
}
|
||||
|
||||
void EntityDataManager::set_entity_datas_folder(String folder) {
|
||||
_entity_datas_folder = folder;
|
||||
}
|
||||
|
||||
Vector<Ref<EntityData> > *EntityDataManager::get_entity_datas() {
|
||||
return &_entity_datas;
|
||||
}
|
||||
|
||||
Ref<EntityData> EntityDataManager::get_entity_data(int class_id) {
|
||||
if (!_entity_data_map.has(class_id))
|
||||
return Ref<EntityData>(NULL);
|
||||
|
||||
return _entity_data_map.get(class_id);
|
||||
}
|
||||
|
||||
Ref<EntityData> EntityDataManager::get_entity_data_index(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>(NULL));
|
||||
|
||||
return _entity_datas.get(index);
|
||||
}
|
||||
|
||||
int EntityDataManager::get_entity_data_count() {
|
||||
return _entity_datas.size();
|
||||
}
|
||||
|
||||
void EntityDataManager::add_entity_data(Ref<EntityData> cls) {
|
||||
ERR_FAIL_COND(!cls.is_valid());
|
||||
|
||||
@ -649,6 +673,16 @@ void EntityDataManager::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_xp_data"), &EntityDataManager::get_xp_data);
|
||||
|
||||
//EntityResourceData
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resources_folder"), &EntityDataManager::get_entity_resources_folder);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_resources_folder", "folder"), &EntityDataManager::set_entity_resources_folder);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "entity_resources_folder"), "set_entity_resources_folder", "get_entity_resources_folder");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_entity_resource", "cls"), &EntityDataManager::add_entity_resource);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resource", "class_id"), &EntityDataManager::get_entity_resource);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resource_index", "index"), &EntityDataManager::get_entity_resource_index);
|
||||
ClassDB::bind_method(D_METHOD("get_entity_resource_count"), &EntityDataManager::get_entity_resource_count);
|
||||
|
||||
//EntityData
|
||||
ClassDB::bind_method(D_METHOD("get_entity_datas_folder"), &EntityDataManager::get_entity_datas_folder);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_datas_folder", "folder"), &EntityDataManager::set_entity_datas_folder);
|
||||
@ -749,6 +783,9 @@ EntityDataManager::EntityDataManager() {
|
||||
EntityDataManager::~EntityDataManager() {
|
||||
instance = NULL;
|
||||
|
||||
_entity_resources.clear();
|
||||
_entity_resource_map.clear();
|
||||
|
||||
_entity_datas.clear();
|
||||
_entity_data_map.clear();
|
||||
|
||||
|
@ -22,6 +22,7 @@ class Spell;
|
||||
class EntityData;
|
||||
class CraftRecipe;
|
||||
class ItemTemplate;
|
||||
class EntityResourceData;
|
||||
|
||||
class EntityDataManager : public Node {
|
||||
GDCLASS(EntityDataManager, Node);
|
||||
@ -36,6 +37,14 @@ public:
|
||||
void set_xp_data_path(String path);
|
||||
Ref<XPData> get_xp_data();
|
||||
|
||||
String get_entity_resources_folder();
|
||||
void set_entity_resources_folder(String folder);
|
||||
Vector<Ref<EntityResourceData> > *get_entity_resources();
|
||||
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);
|
||||
|
||||
String get_entity_datas_folder();
|
||||
void set_entity_datas_folder(String folder);
|
||||
Vector<Ref<EntityData> > *get_entity_datas();
|
||||
@ -124,6 +133,10 @@ private:
|
||||
String _xp_data_path;
|
||||
Ref<XPData> _xp_data;
|
||||
|
||||
String _entity_resources_folder;
|
||||
Vector<Ref<EntityResourceData> > _entity_resources;
|
||||
HashMap<int, Ref<EntityResourceData> > _entity_resource_map;
|
||||
|
||||
String _entity_datas_folder;
|
||||
Vector<Ref<EntityData> > _entity_datas;
|
||||
HashMap<int, Ref<EntityData> > _entity_data_map;
|
||||
|
Loading…
Reference in New Issue
Block a user