From df8331e07ff9da3bbd423c90c61ffe8e63e08c02 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 14 Oct 2019 19:49:40 +0200 Subject: [PATCH] Now entities have an action bar profile aswell. Also fixed small deserialization issues. --- entities/entity.cpp | 52 ++++++++++++++++--- entities/entity.h | 14 +++++ entities/player.cpp | 42 +++++++++++++-- entities/player.h | 10 ++++ .../actionbar/action_bar_entry.cpp | 6 +-- .../actionbar/action_bar_profile.cpp | 15 +++++- .../actionbar/action_bar_profile.h | 3 ++ profile_manager/class_profile.cpp | 3 -- 8 files changed, 124 insertions(+), 21 deletions(-) diff --git a/entities/entity.cpp b/entities/entity.cpp index e6c257b..a558331 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -305,10 +305,10 @@ Dictionary Entity::to_dict() { return call("_to_dict"); } void Entity::from_dict(const Dictionary &dict) { - call("_from_dict", dict); - _deserialized = true; + call("_from_dict", dict); + emit_signal("deserialized", this); } @@ -477,13 +477,18 @@ Dictionary Entity::_to_dict() { if (_s_bag.is_valid()) dict["bag"] = _s_bag->to_dict(); + //// Actionbars //// + + dict["actionbar_locked"] = _actionbar_locked; + dict["actionbar_profile"] = _action_bar_profile->to_dict(); + return dict; } void Entity::_from_dict(const Dictionary &dict) { ERR_FAIL_COND(dict.empty()); sets_guid(dict.get("guid", 0)); - sets_guid(dict.get("guid", 0)); + //setc_guid(dict.get("guid", 0)); sets_entity_type((EntityEnums::EntityType)((int)dict.get("type", 0))); @@ -492,8 +497,6 @@ void Entity::_from_dict(const Dictionary &dict) { sets_xp(dict.get("xp", 0)); sets_money(dict.get("money", 0)); - sets_entity_data_id(dict.get("entity_data_id", 0)); - sets_entity_name(dict.get("entity_name", "")); //// Stats //// @@ -502,7 +505,7 @@ void Entity::_from_dict(const Dictionary &dict) { for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { Ref s = _stats[i]; - + s->from_dict(stats.get(String::num(i), Dictionary())); } @@ -730,9 +733,18 @@ void Entity::_from_dict(const Dictionary &dict) { }*/ } + //// Actionbars //// + + _actionbar_locked = dict.get("actionbar_locked", false); + _action_bar_profile->from_dict(dict.get("actionbar_profile", Dictionary())); + + int edi = dict.get("entity_data_id", 0); + if (DataManager::get_instance() != NULL) { - sets_entity_data(DataManager::get_instance()->get_entity_data(gets_entity_data_id())); + sets_entity_data(DataManager::get_instance()->get_entity_data(edi)); } + + sets_entity_data_id(edi); } Entity::Entity() { @@ -808,6 +820,9 @@ Entity::Entity() { _s_free_spell_points = 0; _c_free_spell_points = 0; + _action_bar_profile.instance(); + _actionbar_locked = false; + for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { Ref s = Ref(memnew(Stat(static_cast(i)))); @@ -953,6 +968,8 @@ Entity::~Entity() { _s_equipment[i].unref(); _c_equipment[i].unref(); } + + _action_bar_profile.unref(); } void Entity::initialize(Ref info) { @@ -4131,6 +4148,19 @@ int Entity::getc_data_count() { return _c_data.size(); } +//// Actionbars //// + +bool Entity::get_actionbar_locked() { + return _actionbar_locked; +} +void Entity::set_actionbar_locked(bool value) { + _actionbar_locked = value; +} + +Ref Entity::get_action_bar_profile() { + return _action_bar_profile; +} + void Entity::loaded() { //sendstate = true; } @@ -5063,4 +5093,12 @@ void Entity::_bind_methods() { ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Entity::_from_dict); ClassDB::bind_method(D_METHOD("_to_dict"), &Entity::_to_dict); + + //Actionbars + + ClassDB::bind_method(D_METHOD("get_actionbar_locked"), &Entity::get_actionbar_locked); + ClassDB::bind_method(D_METHOD("set_actionbar_locked", "value"), &Entity::set_actionbar_locked); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "actionbar_locked"), "set_actionbar_locked", "get_actionbar_locked"); + + ClassDB::bind_method(D_METHOD("get_action_bar_profile"), &Entity::get_action_bar_profile); } diff --git a/entities/entity.h b/entities/entity.h index 75dcc93..4850733 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -34,6 +34,8 @@ #include "./data/entity_data_container.h" #include "./skills/entity_skill.h" +#include "../profile_manager/actionbar/action_bar_profile.h" + class EntityData; class AuraData; class Spell; @@ -655,6 +657,13 @@ public: Ref getc_data(int index); int getc_data_count(); + //// Actionbars //// + + bool get_actionbar_locked(); + void set_actionbar_locked(bool value); + + Ref get_action_bar_profile(); + void loaded(); String random_name(); @@ -807,6 +816,11 @@ private: Vector > _s_data; Vector > _c_data; + //// Actionbars //// + + bool _actionbar_locked; + Ref _action_bar_profile; + //// Crafting System //// Vector > _s_craft_recipes; diff --git a/entities/player.cpp b/entities/player.cpp index 946eb4c..76084d4 100644 --- a/entities/player.cpp +++ b/entities/player.cpp @@ -18,16 +18,39 @@ void Player::setc_seed(int value) { _c_seed = value; } +//Ref Player::get_input_profile() { +// return _input_profile; +//} + void Player::_setup() { Entity::_setup(); - if (gets_entity_data().is_valid() && !gets_bag().is_valid()) { - Ref bag; - bag.instance(); + if (gets_entity_data().is_valid()) { + ProfileManager *pm = ProfileManager::get_instance(); - bag->set_size(gets_entity_data()->get_bag_size()); + if (pm != NULL) { + Ref cp = pm->get_class_profile(gets_entity_data()->get_id()); - sets_bag(bag); + if (cp.is_valid()) { + set_actionbar_locked(cp->get_actionbar_locked()); + + get_action_bar_profile()->clear_action_bars(); + + Ref abp = cp->get_action_bar_profile(); + + get_action_bar_profile()->from_actionbar_profile(abp); + } + } + + if (!gets_bag().is_valid()) { + + Ref bag; + bag.instance(); + + bag->set_size(gets_entity_data()->get_bag_size()); + + sets_bag(bag); + } } } @@ -48,8 +71,15 @@ void Player::_from_dict(const Dictionary &dict) { Player::Player() { //_seed = 0; don't it will be random by default like this _c_seed = _s_seed; + + //_input_profile = Ref(memnew(InputProfile())); } +Player::~Player() { + //_input_profile.unref(); +} + + void Player::_bind_methods() { ClassDB::bind_method(D_METHOD("gets_seed"), &Player::gets_seed); ClassDB::bind_method(D_METHOD("sets_seed", "value"), &Player::sets_seed); @@ -58,4 +88,6 @@ void Player::_bind_methods() { ClassDB::bind_method(D_METHOD("getc_seed"), &Player::getc_seed); ClassDB::bind_method(D_METHOD("setc_seed", "value"), &Player::setc_seed); ADD_PROPERTY(PropertyInfo(Variant::INT, "cseed"), "setc_seed", "getc_seed"); + + //ClassDB::bind_method(D_METHOD("get_input_profile"), &Player::get_input_profile); } diff --git a/entities/player.h b/entities/player.h index f197d4a..719f553 100644 --- a/entities/player.h +++ b/entities/player.h @@ -3,6 +3,9 @@ #include "entity.h" +#include "../profile_manager/input/input_profile.h" +#include "../profile_manager/profile_manager.h" + class Bag; class Player : public Entity { @@ -15,12 +18,17 @@ public: int getc_seed(); void setc_seed(int value); + //// Profiles //// + + //Ref get_input_profile(); + void _setup(); Dictionary _to_dict(); void _from_dict(const Dictionary &dict); Player(); + ~Player(); protected: static void _bind_methods(); @@ -28,6 +36,8 @@ protected: private: int _s_seed; int _c_seed; + + //Ref _input_profile; }; diff --git a/profile_manager/actionbar/action_bar_entry.cpp b/profile_manager/actionbar/action_bar_entry.cpp index d9454d4..7bcc666 100644 --- a/profile_manager/actionbar/action_bar_entry.cpp +++ b/profile_manager/actionbar/action_bar_entry.cpp @@ -52,10 +52,6 @@ Ref ActionBarEntry::get_button(int index) { return _button_entries.get(index); } - int _action_bar_id; -int _slot_num; -Vector > _button_entries; - Dictionary ActionBarEntry::to_dict() const { Dictionary dict; @@ -87,7 +83,7 @@ void ActionBarEntry::from_dict(const Dictionary &dict) { for (int i = 0; i < arr.size(); ++i) { Ref e; e.instance(); - + e->from_dict(arr.get(i)); _button_entries.push_back(e); diff --git a/profile_manager/actionbar/action_bar_profile.cpp b/profile_manager/actionbar/action_bar_profile.cpp index 96d01c3..9dba232 100644 --- a/profile_manager/actionbar/action_bar_profile.cpp +++ b/profile_manager/actionbar/action_bar_profile.cpp @@ -76,7 +76,8 @@ Dictionary ActionBarProfile::to_dict() const { return dict; } void ActionBarProfile::from_dict(const Dictionary &dict) { - ERR_FAIL_COND(dict.empty()); + if (dict.empty()) + return; _action_bars.clear(); @@ -94,6 +95,16 @@ void ActionBarProfile::from_dict(const Dictionary &dict) { } } +void ActionBarProfile::from_actionbar_profile(Ref other) { + _action_bars.clear(); + + _name = other->get_action_bar_profile_name(); + + for (int i = 0; i < other->get_action_bar_count(); ++i) { + _action_bars.push_back(other->get_action_bar(i)); + } +} + ActionBarProfile::ActionBarProfile() { } @@ -116,5 +127,7 @@ void ActionBarProfile::_bind_methods() { ClassDB::bind_method(D_METHOD("from_dict", "dict"), &ActionBarProfile::from_dict); ClassDB::bind_method(D_METHOD("to_dict"), &ActionBarProfile::to_dict); + + ClassDB::bind_method(D_METHOD("from_actionbar_profile", "other"), &ActionBarProfile::from_actionbar_profile); } diff --git a/profile_manager/actionbar/action_bar_profile.h b/profile_manager/actionbar/action_bar_profile.h index 6f81c47..3e221c4 100644 --- a/profile_manager/actionbar/action_bar_profile.h +++ b/profile_manager/actionbar/action_bar_profile.h @@ -2,6 +2,7 @@ #define ACTION_BAR_PROFILE_H #include "core/reference.h" +#include "core/ustring.h" #include "core/vector.h" #include "core/dictionary.h" #include "core/array.h" @@ -26,6 +27,8 @@ public: Dictionary to_dict() const; void from_dict(const Dictionary &dict); + void from_actionbar_profile(Ref other); + ActionBarProfile(); ~ActionBarProfile(); diff --git a/profile_manager/class_profile.cpp b/profile_manager/class_profile.cpp index 7b7bc8b..0b74675 100644 --- a/profile_manager/class_profile.cpp +++ b/profile_manager/class_profile.cpp @@ -43,7 +43,6 @@ void ClassProfile::set_xp(int value) bool ClassProfile::get_actionbar_locked() { return _actionbar_locked; } - void ClassProfile::set_actionbar_locked(bool value) { _actionbar_locked = value; } @@ -52,7 +51,6 @@ Ref ClassProfile::get_input_profile() { return _input_profile; } - Ref ClassProfile::get_action_bar_profile() { return _action_bar_profile; @@ -73,7 +71,6 @@ Dictionary ClassProfile::to_dict() const { dict["level"] = _level; dict["xp"] = _xp; dict["actionbar_locked"] = _actionbar_locked; - dict["actionbar_profile"] = _action_bar_profile->to_dict(); dict["custom_data"] = _custom_data;