mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-09 22:41:39 +02:00
Now entities have an action bar profile aswell. Also fixed small deserialization issues.
This commit is contained in:
parent
87848565b4
commit
df8331e07f
@ -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<Stat> 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<Stat> s = Ref<Stat>(memnew(Stat(static_cast<Stat::StatId>(i))));
|
||||
|
||||
@ -953,6 +968,8 @@ Entity::~Entity() {
|
||||
_s_equipment[i].unref();
|
||||
_c_equipment[i].unref();
|
||||
}
|
||||
|
||||
_action_bar_profile.unref();
|
||||
}
|
||||
|
||||
void Entity::initialize(Ref<EntityCreateInfo> 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<ActionBarProfile> 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);
|
||||
}
|
||||
|
@ -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<EntityDataContainer> getc_data(int index);
|
||||
int getc_data_count();
|
||||
|
||||
//// Actionbars ////
|
||||
|
||||
bool get_actionbar_locked();
|
||||
void set_actionbar_locked(bool value);
|
||||
|
||||
Ref<ActionBarProfile> get_action_bar_profile();
|
||||
|
||||
void loaded();
|
||||
|
||||
String random_name();
|
||||
@ -807,6 +816,11 @@ private:
|
||||
Vector<Ref<EntityDataContainer> > _s_data;
|
||||
Vector<Ref<EntityDataContainer> > _c_data;
|
||||
|
||||
//// Actionbars ////
|
||||
|
||||
bool _actionbar_locked;
|
||||
Ref<ActionBarProfile> _action_bar_profile;
|
||||
|
||||
//// Crafting System ////
|
||||
|
||||
Vector<Ref<CraftRecipe> > _s_craft_recipes;
|
||||
|
@ -18,16 +18,39 @@ void Player::setc_seed(int value) {
|
||||
_c_seed = value;
|
||||
}
|
||||
|
||||
//Ref<InputProfile> 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;
|
||||
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<ClassProfile> 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<ActionBarProfile> abp = cp->get_action_bar_profile();
|
||||
|
||||
get_action_bar_profile()->from_actionbar_profile(abp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!gets_bag().is_valid()) {
|
||||
|
||||
Ref<Bag> 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<InputProfile>(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);
|
||||
}
|
||||
|
@ -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<InputProfile> 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<InputProfile> _input_profile;
|
||||
};
|
||||
|
||||
|
||||
|
@ -52,10 +52,6 @@ Ref<ActionBarButtonEntry> ActionBarEntry::get_button(int index) {
|
||||
return _button_entries.get(index);
|
||||
}
|
||||
|
||||
int _action_bar_id;
|
||||
int _slot_num;
|
||||
Vector<Ref<ActionBarButtonEntry> > _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<ActionBarButtonEntry> e;
|
||||
e.instance();
|
||||
|
||||
|
||||
e->from_dict(arr.get(i));
|
||||
|
||||
_button_entries.push_back(e);
|
||||
|
@ -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<ActionBarProfile> 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);
|
||||
}
|
||||
|
||||
|
@ -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<ActionBarProfile> other);
|
||||
|
||||
ActionBarProfile();
|
||||
~ActionBarProfile();
|
||||
|
||||
|
@ -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<InputProfile> ClassProfile::get_input_profile()
|
||||
{
|
||||
return _input_profile;
|
||||
}
|
||||
|
||||
Ref<ActionBarProfile> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user