Entities now create their own actionbar profiles from the default on the first access.

This commit is contained in:
Relintai 2020-09-12 23:00:18 +02:00
parent 749c0a5c2f
commit 57d80dafff
3 changed files with 37 additions and 20 deletions

View File

@ -797,22 +797,24 @@ void Entity::setup_actionbars() {
return; return;
} }
//ProfileManager *pm = ProfileManager::get_singleton(); get_action_bar_profile();
/*
ProfileManager *pm = ProfileManager::get_singleton();
//if (pm != NULL) { if (pm != NULL) {
// Ref<ClassProfile> cp = pm->get_class_profile(gets_entity_data()->get_id()); Ref<ClassProfile> cp = get_class_profile();
// if (cp.is_valid()) { if (cp.is_valid()) {
// set_actionbar_locked(cp->get_actionbar_locked()); set_actionbar_locked(cp->get_actionbar_locked());
// _action_bar_profile = cp->get_action_bar_profile(); _action_bar_profile = cp->get_default_action_bar_profile();
//get_action_bar_profile()->clear_action_bars(); get_action_bar_profile()->clear_action_bars();
//Ref<ActionBarProfile> abp = cp->get_action_bar_profile(); Ref<ActionBarProfile> abp = cp->get_action_bar_profile();
//get_action_bar_profile()->from_actionbar_profile(abp); get_action_bar_profile()->from_actionbar_profile(abp);
//} }
//} }*/
if (!gets_bag().is_valid()) { if (!gets_bag().is_valid()) {
Ref<Bag> bag; Ref<Bag> bag;
@ -1277,7 +1279,9 @@ Dictionary Entity::_to_dict() {
//// Actionbars //// //// Actionbars ////
dict["actionbar_locked"] = _actionbar_locked; dict["actionbar_locked"] = _actionbar_locked;
//dict["actionbar_profile"] = _action_bar_profile->to_dict();
if (_action_bar_profile.is_valid())
dict["actionbar_profile"] = _action_bar_profile->to_dict();
// AI // AI
@ -1605,7 +1609,14 @@ void Entity::_from_dict(const Dictionary &dict) {
//// Actionbars //// //// Actionbars ////
_actionbar_locked = dict.get("actionbar_locked", false); _actionbar_locked = dict.get("actionbar_locked", false);
//_action_bar_profile->from_dict(dict.get("actionbar_profile", Dictionary()));
if (dict.has("actionbar_profile")) {
if (!_action_bar_profile.is_valid())
_action_bar_profile.instance();
_action_bar_profile->from_dict(dict.get("actionbar_profile", Dictionary()));
}
StringName edp = dict.get("entity_data_path", ""); StringName edp = dict.get("entity_data_path", "");
@ -5370,16 +5381,22 @@ void Entity::set_actionbar_locked(bool value) {
} }
Ref<ActionBarProfile> Entity::get_action_bar_profile() { Ref<ActionBarProfile> Entity::get_action_bar_profile() {
if (_action_bar_profile.is_valid())
return _action_bar_profile;
_action_bar_profile.instance();
Ref<ClassProfile> cp = ProfileManager::get_singleton()->getc_player_profile()->get_class_profile(gets_entity_data()->get_path()); Ref<ClassProfile> cp = ProfileManager::get_singleton()->getc_player_profile()->get_class_profile(gets_entity_data()->get_path());
if (cp.is_valid()) { if (cp.is_valid()) {
set_actionbar_locked(cp->get_actionbar_locked()); set_actionbar_locked(cp->get_actionbar_locked());
return cp->get_action_bar_profile(); Ref<ActionBarProfile> p = cp->get_default_action_bar_profile();
if (p.is_valid())
_action_bar_profile->from_actionbar_profile(p);
} }
return Ref<ActionBarProfile>(); return _action_bar_profile;
//return _action_bar_profile;
} }
void Entity::loaded() { void Entity::loaded() {

View File

@ -70,7 +70,7 @@ void ClassProfile::set_actionbar_locked(const bool value) {
Ref<InputProfile> ClassProfile::get_input_profile() { Ref<InputProfile> ClassProfile::get_input_profile() {
return _input_profile; return _input_profile;
} }
Ref<ActionBarProfile> ClassProfile::get_action_bar_profile() { Ref<ActionBarProfile> ClassProfile::get_default_action_bar_profile() {
return _action_bar_profile; return _action_bar_profile;
} }
@ -223,7 +223,7 @@ void ClassProfile::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_custom_data", "name"), &ClassProfile::get_custom_data); ClassDB::bind_method(D_METHOD("get_custom_data", "name"), &ClassProfile::get_custom_data);
ClassDB::bind_method(D_METHOD("get_input_profile"), &ClassProfile::get_input_profile); ClassDB::bind_method(D_METHOD("get_input_profile"), &ClassProfile::get_input_profile);
ClassDB::bind_method(D_METHOD("get_action_bar_profile"), &ClassProfile::get_action_bar_profile); ClassDB::bind_method(D_METHOD("get_default_action_bar_profile"), &ClassProfile::get_default_action_bar_profile);
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &ClassProfile::from_dict); ClassDB::bind_method(D_METHOD("from_dict", "dict"), &ClassProfile::from_dict);
ClassDB::bind_method(D_METHOD("to_dict"), &ClassProfile::to_dict); ClassDB::bind_method(D_METHOD("to_dict"), &ClassProfile::to_dict);

View File

@ -50,7 +50,7 @@ public:
void set_actionbar_locked(const bool value); void set_actionbar_locked(const bool value);
Ref<InputProfile> get_input_profile(); Ref<InputProfile> get_input_profile();
Ref<ActionBarProfile> get_action_bar_profile(); Ref<ActionBarProfile> get_default_action_bar_profile();
void emit_change(); void emit_change();