fix automatic save in ProfileManager.

This commit is contained in:
Relintai 2020-03-20 14:41:13 +01:00
parent 38738dc2f8
commit 7c4e23ed8b
2 changed files with 14 additions and 1 deletions

View File

@ -136,6 +136,8 @@ Dictionary PlayerProfile::to_dict() const {
dict["class_profiles"] = arr;
dict["custom_data"] = _custom_data;
return dict;
}
void PlayerProfile::from_dict(const Dictionary &dict) {
@ -158,6 +160,8 @@ void PlayerProfile::from_dict(const Dictionary &dict) {
_class_profiles.push_back(c);
}
_custom_data = dict.get("custom_data", Dictionary());
emit_change();
}

View File

@ -66,6 +66,10 @@ void ProfileManager::adds_player_profile(const Ref<PlayerProfile> &profile) {
_s_player_profiles.push_back(profile);
}
void ProfileManager::clears_player_profiles() {
//for (int i = 0; i < _s_player_profiles.size(); ++i) {
// _c_player_profile->disconnect("changed", this, "_on_player_profile_changed");
//}
_s_player_profiles.clear();
}
void ProfileManager::removes_player_profile(const int index) {
@ -158,9 +162,11 @@ Dictionary ProfileManager::to_dict() const {
void ProfileManager::from_dict(const Dictionary &dict) {
ERR_FAIL_COND(dict.empty());
//clears_player_profiles();
clears_player_profiles();
_c_player_profile->disconnect("changed", this, "_on_player_profile_changed");
_c_player_profile->from_dict(dict.get("cplayer_profile", Dictionary()));
_c_player_profile->connect("changed", this, "_on_player_profile_changed");
Array arr = dict.get("splayer_profiles", Array());
@ -183,6 +189,7 @@ ProfileManager::ProfileManager() {
_save_file = GLOBAL_DEF("ess/profiles/save_file", "user://profile.save");
_c_player_profile.instance();
_c_player_profile->connect("changed", this, "_on_player_profile_changed");
if (_automatic_load)
call_deferred("load");
@ -191,6 +198,8 @@ ProfileManager::ProfileManager() {
ProfileManager::~ProfileManager() {
_instance = NULL;
_c_player_profile->disconnect("changed", this, "_on_player_profile_changed");
_s_player_profiles.clear();
}