mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
More work on entity serialization.
This commit is contained in:
parent
7756cf51ec
commit
62b5df080a
@ -3,26 +3,6 @@
|
||||
#include "../../data/aura.h"
|
||||
#include "../entity.h"
|
||||
|
||||
AuraData::AuraData() {
|
||||
_owner = NULL;
|
||||
_aura_id = 0;
|
||||
_remaining_time = 0;
|
||||
_caster = NULL;
|
||||
_caster_guid = 0;
|
||||
_spell_scale = 0;
|
||||
_aura_group = 0;
|
||||
|
||||
_is_timed = false;
|
||||
_damage = 0;
|
||||
_heal = 0;
|
||||
_slow = 0;
|
||||
_remaining_absorb = 0;
|
||||
_tick = 0;
|
||||
_time_since_last_tick = 0;
|
||||
_damage_already_taken = 0;
|
||||
_unhandled_ticks = 0;
|
||||
}
|
||||
|
||||
float AuraData::get_damage_count() {
|
||||
return _damage_already_taken;
|
||||
}
|
||||
@ -241,6 +221,62 @@ void AuraData::set_slow(float value) {
|
||||
_slow = value;
|
||||
}
|
||||
|
||||
Dictionary AuraData::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
void AuraData::from_dict(const Dictionary &dict) {
|
||||
call("_from_dict", dict);
|
||||
}
|
||||
|
||||
Dictionary AuraData::_to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
dict["aura_id"] = _aura_id;
|
||||
dict["remaining_time"] = _remaining_time;
|
||||
dict["caster_name"] = _caster->get_name();
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
dict["aura_group"] = _aura_group;
|
||||
dict["aura_id"] = _aura->get_id();
|
||||
|
||||
dict["is_timed"] = _is_timed;
|
||||
dict["damage"] = _damage;
|
||||
dict["heal"] = _heal;
|
||||
dict["slow"] = _slow;
|
||||
dict["remaining_absorb"] = _remaining_absorb;
|
||||
dict["tick"] = _tick;
|
||||
dict["time_since_last_tick"] = _time_since_last_tick;
|
||||
dict["damage_already_taken"] = _damage_already_taken;
|
||||
dict["unhandled_ticks"] = _unhandled_ticks;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void AuraData::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
}
|
||||
|
||||
AuraData::AuraData() {
|
||||
_owner = NULL;
|
||||
_aura_id = 0;
|
||||
_remaining_time = 0;
|
||||
_caster = NULL;
|
||||
_caster_guid = 0;
|
||||
_spell_scale = 0;
|
||||
_aura_group = 0;
|
||||
|
||||
_is_timed = false;
|
||||
_damage = 0;
|
||||
_heal = 0;
|
||||
_slow = 0;
|
||||
_remaining_absorb = 0;
|
||||
_tick = 0;
|
||||
_time_since_last_tick = 0;
|
||||
_damage_already_taken = 0;
|
||||
_unhandled_ticks = 0;
|
||||
}
|
||||
|
||||
|
||||
void AuraData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_aura_id"), &AuraData::get_aura_id);
|
||||
ClassDB::bind_method(D_METHOD("set_aura_id", "value"), &AuraData::set_aura_id);
|
||||
@ -307,4 +343,14 @@ void AuraData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_slow"), &AuraData::get_slow);
|
||||
ClassDB::bind_method(D_METHOD("set_slow", "value"), &AuraData::set_slow);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "slow"), "set_slow", "get_slow");
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &AuraData::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &AuraData::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &AuraData::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &AuraData::_to_dict);
|
||||
}
|
||||
|
@ -67,6 +67,12 @@ public:
|
||||
float get_slow();
|
||||
void set_slow(float value);
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
Dictionary _to_dict();
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
AuraData();
|
||||
|
||||
protected:
|
||||
|
@ -299,7 +299,6 @@ Dictionary Entity::_to_dict() {
|
||||
Dictionary stated;
|
||||
|
||||
for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) {
|
||||
int _s_states[EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX];
|
||||
stated[i] = _s_states[i];
|
||||
}
|
||||
|
||||
@ -307,58 +306,74 @@ Dictionary Entity::_to_dict() {
|
||||
|
||||
dict["state"] = _s_state;
|
||||
|
||||
/*
|
||||
//// SpellCastData ////
|
||||
|
||||
Ref<SpellCastInfo> _s_spell_cast_info;
|
||||
Ref<SpellCastInfo> _c_spell_cast_info;
|
||||
//Not needed
|
||||
//Ref<SpellCastInfo> _s_spell_cast_info;
|
||||
//Ref<SpellCastInfo> _c_spell_cast_info;
|
||||
|
||||
//// AuraComponent ////
|
||||
|
||||
Vector<Ref<AuraData> > _s_auras;
|
||||
Vector<Ref<AuraData> > _c_auras;
|
||||
Dictionary auras;
|
||||
|
||||
EntityEnums::EntityType _s_entity_type;
|
||||
EntityEnums::EntityType _c_entity_type;
|
||||
for (int i = 0; i < _s_auras.size(); ++i) {
|
||||
auras[i] = _s_auras.get(i)->to_dict();
|
||||
}
|
||||
|
||||
int _s_immunity_flags;
|
||||
dict["auras"] = auras;
|
||||
|
||||
int _s_entity_flags;
|
||||
int _c_entity_flags;
|
||||
|
||||
EntityEnums::EntityController _s_entity_controller;
|
||||
dict["entity_type"] = _s_entity_type;
|
||||
dict["immunity_flags"] = _s_immunity_flags;
|
||||
dict["entity_flags"] = _s_entity_flags;
|
||||
dict["entity_controller"] = _s_entity_controller;
|
||||
|
||||
|
||||
//// Cooldowns ////
|
||||
Vector<Ref<Cooldown> > _s_cooldowns;
|
||||
Vector<Ref<Cooldown> > _c_cooldowns;
|
||||
|
||||
HashMap<int, Ref<Cooldown> > _s_cooldown_map;
|
||||
HashMap<int, Ref<Cooldown> > _c_cooldown_map;
|
||||
Dictionary cds;
|
||||
|
||||
for (int i = 0; i < _s_cooldowns.size(); ++i) {
|
||||
cds[i] = _s_cooldowns.get(i)->to_dict();
|
||||
}
|
||||
|
||||
dict["cooldowns"] = cds;
|
||||
|
||||
Vector<Ref<CategoryCooldown> > _s_category_cooldowns;
|
||||
Vector<Ref<CategoryCooldown> > _c_category_cooldowns;
|
||||
|
||||
int _s_active_category_cooldowns;
|
||||
int _c_active_category_cooldowns;
|
||||
Dictionary ccds;
|
||||
|
||||
//// targetComponent ////
|
||||
for (int i = 0; i < _s_category_cooldowns.size(); ++i) {
|
||||
ccds[i] = _s_category_cooldowns.get(i)->to_dict();
|
||||
}
|
||||
|
||||
int _s_target_guid;
|
||||
Entity *_s_target;
|
||||
Entity *_c_target;
|
||||
dict["category_cooldowns"] = ccds;
|
||||
|
||||
dict["active_category_cooldowns"] = _s_active_category_cooldowns;
|
||||
|
||||
//// Data ////
|
||||
Vector<Ref<EntityDataContainer> > _s_data;
|
||||
Vector<Ref<EntityDataContainer> > _c_data;
|
||||
|
||||
//// Known Spells ////
|
||||
Vector<Ref<Spell> > _s_spells;
|
||||
Vector<Ref<Spell> > _c_spells;
|
||||
|
||||
Dictionary known_spells;
|
||||
|
||||
for (int i = 0; i < _s_spells.size(); ++i) {
|
||||
known_spells[i] = _s_spells.get(i)->get_spell_id();
|
||||
}
|
||||
|
||||
dict["known_spells"] = known_spells;
|
||||
|
||||
//// Skills ////
|
||||
Vector<Ref<EntitySkill> > _s_skills;
|
||||
Vector<Ref<EntitySkill> > _c_skills;
|
||||
*/
|
||||
|
||||
Dictionary skills;
|
||||
|
||||
for (int i = 0; i < _s_skills.size(); ++i) {
|
||||
skills[i] = _s_skills.get(i)->to_dict();
|
||||
}
|
||||
|
||||
dict["skills"] = skills;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void Entity::_from_dict(const Dictionary &dict) {
|
||||
|
@ -36,6 +36,27 @@ void EntitySkill::set_disabled(bool value) {
|
||||
emit_signal("skill_changed", Ref<EntitySkill>(this));
|
||||
}
|
||||
|
||||
Dictionary EntitySkill::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
void EntitySkill::from_dict(const Dictionary &dict) {
|
||||
call("_from_dict", dict);
|
||||
}
|
||||
|
||||
Dictionary EntitySkill::_to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
dict["skill_id"] = _skill_id;
|
||||
dict["current"] = _current;
|
||||
dict["max"] = _max;
|
||||
dict["disabled"] = _disabled;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void EntitySkill::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
}
|
||||
|
||||
EntitySkill::EntitySkill() {
|
||||
_skill_id = 0;
|
||||
_current = 0;
|
||||
@ -61,4 +82,14 @@ void EntitySkill::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_disabled"), &EntitySkill::get_disabled);
|
||||
ClassDB::bind_method(D_METHOD("set_disabled", "value"), &EntitySkill::set_disabled);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "get_disabled");
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &EntitySkill::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &EntitySkill::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &EntitySkill::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &EntitySkill::_to_dict);
|
||||
}
|
||||
|
@ -19,6 +19,12 @@ public:
|
||||
bool get_disabled();
|
||||
void set_disabled(bool value);
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
Dictionary _to_dict();
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
EntitySkill();
|
||||
|
||||
protected:
|
||||
|
@ -39,7 +39,6 @@ void StatModifier::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_mod"), "set_percent_mod", "get_percent_mod");
|
||||
|
||||
//Serialization
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
|
@ -33,6 +33,25 @@ bool CategoryCooldown::update(const float delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Dictionary CategoryCooldown::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
void CategoryCooldown::from_dict(const Dictionary &dict) {
|
||||
call("_from_dict", dict);
|
||||
}
|
||||
|
||||
Dictionary CategoryCooldown::_to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
dict["category_id"] = _category_id;
|
||||
dict["remaining"] = _remaining;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void CategoryCooldown::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
}
|
||||
|
||||
|
||||
void CategoryCooldown::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_category_id"), &CategoryCooldown::get_category_id);
|
||||
@ -44,4 +63,14 @@ void CategoryCooldown::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "remaining"), "set_remaining", "get_remaining");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("update", "delta"), &CategoryCooldown::update);
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &CategoryCooldown::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &CategoryCooldown::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &CategoryCooldown::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &CategoryCooldown::_to_dict);
|
||||
}
|
||||
|
@ -15,6 +15,12 @@ public:
|
||||
|
||||
bool update(const float delta);
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
Dictionary _to_dict();
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
|
@ -33,6 +33,24 @@ bool Cooldown::update(const float delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Dictionary Cooldown::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
void Cooldown::from_dict(const Dictionary &dict) {
|
||||
call("_from_dict", dict);
|
||||
}
|
||||
|
||||
Dictionary Cooldown::_to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
dict["spell_id"] = _spell_id;
|
||||
dict["remaining"] = _remaining;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void Cooldown::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
}
|
||||
|
||||
void Cooldown::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_spell_id"), &Cooldown::get_spell_id);
|
||||
@ -44,4 +62,14 @@ void Cooldown::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "remaining"), "set_remaining", "get_remaining");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("update", "delta"), &Cooldown::update);
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &Cooldown::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &Cooldown::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Cooldown::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &Cooldown::_to_dict);
|
||||
}
|
||||
|
@ -15,6 +15,12 @@ public:
|
||||
|
||||
bool update(const float delta);
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
Dictionary _to_dict();
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user