mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Added PlayerProfile, and now ProfileManager has clientside, and serverside variables.
This commit is contained in:
parent
affacaea58
commit
9493be41fb
2
SCsub
2
SCsub
@ -115,6 +115,8 @@ sources = [
|
||||
|
||||
"profiles/class_profile.cpp",
|
||||
|
||||
"profiles/player_profile.cpp",
|
||||
|
||||
"singletons/profile_manager.cpp",
|
||||
"singletons/entity_data_manager.cpp",
|
||||
]
|
||||
|
@ -481,7 +481,7 @@ void Entity::_setup(Ref<EntityCreateInfo> info) {
|
||||
|
||||
if (gets_entity_player_type() == EntityEnums::ENTITY_PLAYER_TYPE_PLAYER || gets_entity_player_type() == EntityEnums::ENTITY_PLAYER_TYPE_DISPLAY) {
|
||||
if (EntityDataManager::get_instance()->get_use_global_class_level()) {
|
||||
Ref<ClassProfile> cp = ProfileManager::get_instance()->get_class_profile(gets_entity_data()->get_id());
|
||||
Ref<ClassProfile> cp = ProfileManager::get_instance()->getc_player_profile()->get_class_profile(gets_entity_data()->get_id());
|
||||
|
||||
if (cp.is_valid()) {
|
||||
int leveldiff = cp->get_level() - _s_class_level;
|
||||
@ -857,7 +857,7 @@ int Entity::getc_pet_count() {
|
||||
//// Profiles ////
|
||||
|
||||
Ref<ClassProfile> Entity::get_class_profile() {
|
||||
return ProfileManager::get_instance()->get_class_profile(_s_class_id);
|
||||
return ProfileManager::get_instance()->getc_player_profile()->get_class_profile(_s_class_id);
|
||||
}
|
||||
|
||||
//// Serialization ////
|
||||
@ -5362,7 +5362,7 @@ void Entity::set_actionbar_locked(bool value) {
|
||||
}
|
||||
|
||||
Ref<ActionBarProfile> Entity::get_action_bar_profile() {
|
||||
Ref<ClassProfile> cp = ProfileManager::get_instance()->get_class_profile(gets_entity_data()->get_id());
|
||||
Ref<ClassProfile> cp = ProfileManager::get_instance()->getc_player_profile()->get_class_profile(gets_entity_data()->get_id());
|
||||
|
||||
if (cp.is_valid()) {
|
||||
set_actionbar_locked(cp->get_actionbar_locked());
|
||||
|
@ -75,7 +75,7 @@ Ref<ActionBarProfile> ClassProfile::get_action_bar_profile() {
|
||||
}
|
||||
|
||||
void ClassProfile::emit_change() {
|
||||
emit_signal("changed", Ref<ClassProfile>(this));
|
||||
emit_signal("changed");
|
||||
}
|
||||
|
||||
Dictionary ClassProfile::get_custom_data() {
|
||||
@ -188,6 +188,10 @@ void ClassProfile::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_actionbar_locked", "value"), &ClassProfile::set_actionbar_locked);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "actionbar_locked"), "set_actionbar_locked", "get_actionbar_locked");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_custom_data"), &ClassProfile::get_custom_data);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_data", "value"), &ClassProfile::set_custom_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "custom_data"), "set_custom_data", "get_custom_data");
|
||||
|
||||
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);
|
||||
|
||||
|
231
profiles/player_profile.cpp
Normal file
231
profiles/player_profile.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "player_profile.h"
|
||||
|
||||
const String PlayerProfile::DEFAULT_PROFILE_FILE_NAME = "default.profile";
|
||||
|
||||
int PlayerProfile::get_id() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
void PlayerProfile::set_id(int value) {
|
||||
_id = value;
|
||||
}
|
||||
|
||||
String PlayerProfile::get_profile_name() {
|
||||
return _profile_name;
|
||||
}
|
||||
|
||||
void PlayerProfile::set_profile_name(String value) {
|
||||
_profile_name = value;
|
||||
}
|
||||
|
||||
int PlayerProfile::get_last_used_character() const {
|
||||
return _last_used_character;
|
||||
}
|
||||
|
||||
void PlayerProfile::set_last_used_character(const int value) {
|
||||
_last_used_character = value;
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
int PlayerProfile::get_class_profile_count() const {
|
||||
return _class_profiles.size();
|
||||
}
|
||||
|
||||
Ref<ClassProfile> PlayerProfile::get_class_profile_index(const int index) {
|
||||
return _class_profiles.get(index);
|
||||
}
|
||||
|
||||
void PlayerProfile::add_class_profile(Ref<ClassProfile> profile) {
|
||||
profile->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(profile);
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
void PlayerProfile::clear_class_profiles() {
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
_class_profiles.get(i)->disconnect("changed", this, "_on_class_profile_changed");
|
||||
}
|
||||
|
||||
_class_profiles.clear();
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
void PlayerProfile::remove_class_profile(const int index) {
|
||||
_class_profiles.get(index)->disconnect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.remove(index);
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
Vector<Ref<ClassProfile> > &PlayerProfile::get_class_profiles() {
|
||||
return _class_profiles;
|
||||
}
|
||||
|
||||
Ref<ClassProfile> PlayerProfile::get_class_profile(const int class_id) {
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
if (_class_profiles.get(i)->get_class_id() == class_id) {
|
||||
return Ref<ClassProfile>(_class_profiles.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ClassProfile> class_profile = Ref<ClassProfile>(memnew(ClassProfile(class_id)));
|
||||
|
||||
class_profile->load_defaults();
|
||||
class_profile->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(Ref<ClassProfile>(class_profile));
|
||||
|
||||
emit_signal("changed");
|
||||
|
||||
return class_profile;
|
||||
}
|
||||
|
||||
void PlayerProfile::emit_change() {
|
||||
emit_signal("changed", Ref<PlayerProfile>(this));
|
||||
}
|
||||
|
||||
Dictionary PlayerProfile::get_custom_data() {
|
||||
return _custom_data;
|
||||
}
|
||||
void PlayerProfile::set_custom_data(const Dictionary &dict) {
|
||||
_custom_data = dict;
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
Dictionary PlayerProfile::to_dict() const {
|
||||
Dictionary dict;
|
||||
|
||||
dict["last_used_character"] = _last_used_character;
|
||||
dict["profile_name"] = _profile_name;
|
||||
|
||||
Array arr;
|
||||
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
Dictionary d = _class_profiles[i]->to_dict();
|
||||
|
||||
arr.append(d);
|
||||
}
|
||||
|
||||
dict["class_profiles"] = arr;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void PlayerProfile::from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
clear_class_profiles();
|
||||
|
||||
_last_used_character = dict.get("last_used_character", "");
|
||||
_profile_name = dict.get("profile_name", 0);
|
||||
|
||||
Array arr = dict.get("class_profiles", Array());
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
Ref<ClassProfile> c;
|
||||
c.instance();
|
||||
|
||||
c->from_dict(arr.get(i));
|
||||
c->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(c);
|
||||
}
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
PlayerProfile::PlayerProfile() {
|
||||
_id = 0;
|
||||
_last_used_character = 0;
|
||||
_profile_name = DEFAULT_PROFILE_FILE_NAME;
|
||||
}
|
||||
|
||||
PlayerProfile::~PlayerProfile() {
|
||||
_custom_data.clear();
|
||||
|
||||
_class_profiles.clear();
|
||||
}
|
||||
|
||||
void PlayerProfile::load_defaults() {
|
||||
clear_class_profiles();
|
||||
|
||||
_class_profiles.push_back(memnew(ClassProfile("Naturalist", 1, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("Berserker", 3, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("IceArcher", 4, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("Chronomancer", 6, 1, 0, false)));
|
||||
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
_class_profiles.get(i)->load_defaults();
|
||||
_class_profiles.get(i)->connect("changed", this, "_on_class_profile_changed");
|
||||
}
|
||||
|
||||
emit_change();
|
||||
}
|
||||
|
||||
void PlayerProfile::_on_class_profile_changed() {
|
||||
emit_change();
|
||||
}
|
||||
|
||||
void PlayerProfile::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("changed", PropertyInfo(Variant::OBJECT, "profile", PROPERTY_HINT_RESOURCE_TYPE, "PlayerProfile")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_id"), &PlayerProfile::get_id);
|
||||
ClassDB::bind_method(D_METHOD("set_id", "value"), &PlayerProfile::set_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_profile_name"), &PlayerProfile::get_profile_name);
|
||||
ClassDB::bind_method(D_METHOD("set_profile_name", "value"), &PlayerProfile::set_profile_name);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "profile_name"), "set_profile_name", "get_profile_name");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_used_character"), &PlayerProfile::get_last_used_character);
|
||||
ClassDB::bind_method(D_METHOD("set_last_used_character", "value"), &PlayerProfile::set_last_used_character);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "set_last_used_character"), "set_last_used_character", "get_last_used_character");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_custom_data"), &PlayerProfile::get_custom_data);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_data", "value"), &PlayerProfile::set_custom_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "custom_data"), "set_custom_data", "get_custom_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile_count"), &PlayerProfile::get_class_profile_count);
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile_index", "index"), &PlayerProfile::get_class_profile_index);
|
||||
ClassDB::bind_method(D_METHOD("add_class_profile", "profile"), &PlayerProfile::add_class_profile);
|
||||
ClassDB::bind_method(D_METHOD("clear_class_profiles"), &PlayerProfile::clear_class_profiles);
|
||||
ClassDB::bind_method(D_METHOD("remove_class_profile", "index"), &PlayerProfile::remove_class_profile);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile", "class_id"), &PlayerProfile::get_class_profile);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_defaults"), &PlayerProfile::load_defaults);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &PlayerProfile::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &PlayerProfile::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_class_profile_changed"), &PlayerProfile::_on_class_profile_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("emit_change"), &PlayerProfile::emit_change);
|
||||
}
|
84
profiles/player_profile.h
Normal file
84
profiles/player_profile.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PLAYER_PROFILE_H
|
||||
#define PLAYER_PROFILE_H
|
||||
|
||||
#include "core/dictionary.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
#include "class_profile.h"
|
||||
|
||||
class PlayerProfile : public Reference {
|
||||
GDCLASS(PlayerProfile, Reference);
|
||||
|
||||
public:
|
||||
static const String DEFAULT_PROFILE_FILE_NAME;
|
||||
|
||||
int get_id();
|
||||
void set_id(int value);
|
||||
|
||||
String get_profile_name();
|
||||
void set_profile_name(String value);
|
||||
|
||||
int get_last_used_character() const;
|
||||
void set_last_used_character(const int value);
|
||||
|
||||
int get_class_profile_count() const;
|
||||
Ref<ClassProfile> get_class_profile_index(const int index);
|
||||
void add_class_profile(Ref<ClassProfile> profile);
|
||||
void clear_class_profiles();
|
||||
void remove_class_profile(const int index);
|
||||
|
||||
Vector<Ref<ClassProfile> > &get_class_profiles();
|
||||
Ref<ClassProfile> get_class_profile(const int class_id);
|
||||
|
||||
Dictionary get_custom_data();
|
||||
void set_custom_data(const Dictionary &dict);
|
||||
|
||||
Dictionary to_dict() const;
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
void emit_change();
|
||||
|
||||
PlayerProfile();
|
||||
~PlayerProfile();
|
||||
|
||||
void load_defaults();
|
||||
|
||||
protected:
|
||||
void _on_class_profile_changed();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _id;
|
||||
int _last_used_character;
|
||||
String _profile_name;
|
||||
|
||||
Dictionary _custom_data;
|
||||
|
||||
Vector<Ref<ClassProfile> > _class_profiles;
|
||||
};
|
||||
|
||||
#endif
|
@ -130,6 +130,7 @@ SOFTWARE.
|
||||
#include "profiles/actionbar/action_bar_profile.h"
|
||||
|
||||
#include "profiles/class_profile.h"
|
||||
#include "profiles/player_profile.h"
|
||||
|
||||
#include "singletons/profile_manager.h"
|
||||
|
||||
@ -255,6 +256,8 @@ void register_entity_spell_system_types() {
|
||||
ClassDB::register_class<ActionBarProfile>();
|
||||
|
||||
ClassDB::register_class<ClassProfile>();
|
||||
ClassDB::register_class<PlayerProfile>();
|
||||
|
||||
ClassDB::register_class<ProfileManager>();
|
||||
|
||||
entity_data_manager = memnew(EntityDataManager);
|
||||
|
@ -25,14 +25,26 @@ SOFTWARE.
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/project_settings.h"
|
||||
|
||||
const String ProfileManager::DEFAULT_PROFILE_FILE_NAME = "default.profile";
|
||||
|
||||
ProfileManager *ProfileManager::_instance;
|
||||
|
||||
ProfileManager *ProfileManager::get_instance() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
bool ProfileManager::get_automatic_load() const {
|
||||
return _automatic_load;
|
||||
}
|
||||
void ProfileManager::set_automatic_load(const bool load) {
|
||||
_automatic_load = load;
|
||||
}
|
||||
|
||||
bool ProfileManager::get_automatic_save() const {
|
||||
return _automatic_save;
|
||||
}
|
||||
void ProfileManager::set_automatic_save(const bool load) {
|
||||
_automatic_save = load;
|
||||
}
|
||||
|
||||
String ProfileManager::get_save_file() const {
|
||||
return _save_file;
|
||||
}
|
||||
@ -43,75 +55,25 @@ void ProfileManager::set_save_file(const String &file) {
|
||||
save();
|
||||
}
|
||||
|
||||
int ProfileManager::get_last_used_class() const {
|
||||
return _last_used_class;
|
||||
int ProfileManager::gets_player_profile_count() const {
|
||||
return _s_player_profiles.size();
|
||||
}
|
||||
Ref<PlayerProfile> ProfileManager::gets_player_profile_index(const int index) {
|
||||
|
||||
return _s_player_profiles.get(index);
|
||||
}
|
||||
void ProfileManager::adds_player_profile(const Ref<PlayerProfile> &profile) {
|
||||
_s_player_profiles.push_back(profile);
|
||||
}
|
||||
void ProfileManager::clears_player_profiles() {
|
||||
_s_player_profiles.clear();
|
||||
}
|
||||
void ProfileManager::removes_player_profile(const int index) {
|
||||
_s_player_profiles.remove(index);
|
||||
}
|
||||
|
||||
void ProfileManager::set_last_used_class(const int value) {
|
||||
_last_used_class = value;
|
||||
|
||||
if (_automatic_save)
|
||||
save();
|
||||
}
|
||||
|
||||
int ProfileManager::get_class_profile_count() const {
|
||||
return _class_profiles.size();
|
||||
}
|
||||
|
||||
Ref<ClassProfile> ProfileManager::get_class_profile_index(const int index) {
|
||||
return _class_profiles.get(index);
|
||||
}
|
||||
|
||||
void ProfileManager::add_class_profile(Ref<ClassProfile> profile) {
|
||||
profile->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(profile);
|
||||
|
||||
if (_automatic_save)
|
||||
save();
|
||||
}
|
||||
|
||||
void ProfileManager::clear_class_profiles() {
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
_class_profiles.get(i)->disconnect("changed", this, "_on_class_profile_changed");
|
||||
}
|
||||
|
||||
_class_profiles.clear();
|
||||
|
||||
if (_automatic_save)
|
||||
save();
|
||||
}
|
||||
|
||||
void ProfileManager::remove_class_profile(const int index) {
|
||||
_class_profiles.get(index)->disconnect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.remove(index);
|
||||
|
||||
if (_automatic_save)
|
||||
save();
|
||||
}
|
||||
|
||||
Vector<Ref<ClassProfile> > &ProfileManager::get_class_profiles() {
|
||||
return _class_profiles;
|
||||
}
|
||||
|
||||
Ref<ClassProfile> ProfileManager::get_class_profile(const int class_id) {
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
if (_class_profiles.get(i)->get_class_id() == class_id) {
|
||||
return Ref<ClassProfile>(_class_profiles.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ClassProfile> class_profile = Ref<ClassProfile>(memnew(ClassProfile(class_id)));
|
||||
|
||||
class_profile->load_defaults();
|
||||
class_profile->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(Ref<ClassProfile>(class_profile));
|
||||
|
||||
emit_signal("changed");
|
||||
|
||||
return class_profile;
|
||||
Ref<PlayerProfile> ProfileManager::getc_player_profile() {
|
||||
return _c_player_profile;
|
||||
}
|
||||
|
||||
void ProfileManager::save() {
|
||||
@ -138,7 +100,7 @@ void ProfileManager::_save() {
|
||||
|
||||
void ProfileManager::_load() {
|
||||
if (FileAccess::exists(_save_file)) {
|
||||
clear_class_profiles();
|
||||
//clears_player_profiles();
|
||||
|
||||
Error err;
|
||||
String text = FileAccess::get_file_as_string(_save_file, &err);
|
||||
@ -174,70 +136,54 @@ void ProfileManager::load_profile(const String &name) {
|
||||
}
|
||||
|
||||
void ProfileManager::load_defaults() {
|
||||
clear_class_profiles();
|
||||
|
||||
_class_profiles.push_back(memnew(ClassProfile("Naturalist", 1, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("Berserker", 3, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("IceArcher", 4, 1, 0, false)));
|
||||
_class_profiles.push_back(memnew(ClassProfile("Chronomancer", 6, 1, 0, false)));
|
||||
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
_class_profiles.get(i)->load_defaults();
|
||||
_class_profiles.get(i)->connect("changed", this, "_on_class_profile_changed");
|
||||
}
|
||||
|
||||
emit_signal("changed");
|
||||
}
|
||||
|
||||
Dictionary ProfileManager::to_dict() const {
|
||||
Dictionary dict;
|
||||
|
||||
dict["last_used_class"] = _last_used_class;
|
||||
dict["profile_name"] = _profile_name;
|
||||
dict["cplayer_profile"] = _c_player_profile->to_dict();
|
||||
|
||||
Array arr;
|
||||
|
||||
for (int i = 0; i < _class_profiles.size(); ++i) {
|
||||
Dictionary d = _class_profiles[i]->to_dict();
|
||||
for (int i = 0; i < _s_player_profiles.size(); ++i) {
|
||||
Dictionary d = _s_player_profiles[i]->to_dict();
|
||||
|
||||
arr.append(d);
|
||||
}
|
||||
|
||||
dict["class_profiles"] = arr;
|
||||
dict["splayer_profiles"] = arr;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void ProfileManager::from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
clear_class_profiles();
|
||||
//clears_player_profiles();
|
||||
|
||||
_last_used_class = dict.get("last_used_class", "");
|
||||
_profile_name = dict.get("profile_name", 0);
|
||||
_c_player_profile->from_dict(dict.get("cplayer_profile", Dictionary()));
|
||||
|
||||
Array arr = dict.get("class_profiles", Array());
|
||||
Array arr = dict.get("splayer_profiles", Array());
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
Ref<ClassProfile> c;
|
||||
Ref<PlayerProfile> c;
|
||||
c.instance();
|
||||
|
||||
c->from_dict(arr.get(i));
|
||||
c->connect("changed", this, "_on_class_profile_changed");
|
||||
|
||||
_class_profiles.push_back(c);
|
||||
_s_player_profiles.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
ProfileManager::ProfileManager() {
|
||||
_instance = this;
|
||||
_last_used_class = 0;
|
||||
|
||||
_profile_name = ProfileManager::DEFAULT_PROFILE_FILE_NAME;
|
||||
|
||||
_automatic_load = GLOBAL_DEF("ess/profiles/automatic_load", false);
|
||||
_automatic_save = GLOBAL_DEF("ess/profiles/automatic_save", false);
|
||||
_save_file = GLOBAL_DEF("ess/profiles/save_file", "user://profile.save");
|
||||
|
||||
_c_player_profile.instance();
|
||||
|
||||
if (_automatic_load)
|
||||
call_deferred("load");
|
||||
}
|
||||
@ -245,10 +191,10 @@ ProfileManager::ProfileManager() {
|
||||
ProfileManager::~ProfileManager() {
|
||||
_instance = NULL;
|
||||
|
||||
_class_profiles.clear();
|
||||
_s_player_profiles.clear();
|
||||
}
|
||||
|
||||
void ProfileManager::_on_class_profile_changed(Ref<ClassProfile> profile) {
|
||||
void ProfileManager::_on_player_profile_changed(Ref<PlayerProfile> profile) {
|
||||
if (_automatic_save)
|
||||
save();
|
||||
}
|
||||
@ -266,21 +212,22 @@ void ProfileManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_automatic_load", "load"), &ProfileManager::set_automatic_load);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_load"), "set_automatic_load", "get_automatic_load");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_automatic_save"), &ProfileManager::get_automatic_save);
|
||||
ClassDB::bind_method(D_METHOD("set_automatic_save", "load"), &ProfileManager::set_automatic_save);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_save"), "set_automatic_save", "get_automatic_save");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_save_file"), &ProfileManager::get_save_file);
|
||||
ClassDB::bind_method(D_METHOD("set_save_file", "path"), &ProfileManager::set_save_file);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "set_save_file"), "set_save_file", "get_save_file");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_used_class"), &ProfileManager::get_last_used_class);
|
||||
ClassDB::bind_method(D_METHOD("set_last_used_class", "value"), &ProfileManager::set_last_used_class);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "last_used_class"), "set_last_used_class", "get_last_used_class");
|
||||
ClassDB::bind_method(D_METHOD("gets_player_profile_count"), &ProfileManager::gets_player_profile_count);
|
||||
ClassDB::bind_method(D_METHOD("gets_player_profile_index", "index"), &ProfileManager::gets_player_profile_index);
|
||||
ClassDB::bind_method(D_METHOD("adds_player_profile", "profile"), &ProfileManager::adds_player_profile);
|
||||
ClassDB::bind_method(D_METHOD("clears_player_profiles"), &ProfileManager::clears_player_profiles);
|
||||
ClassDB::bind_method(D_METHOD("removes_player_profile", "index"), &ProfileManager::removes_player_profile);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile_count"), &ProfileManager::get_class_profile_count);
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile_index", "index"), &ProfileManager::get_class_profile_index);
|
||||
ClassDB::bind_method(D_METHOD("add_class_profile", "profile"), &ProfileManager::add_class_profile);
|
||||
ClassDB::bind_method(D_METHOD("clear_class_profiles"), &ProfileManager::clear_class_profiles);
|
||||
ClassDB::bind_method(D_METHOD("remove_class_profile", "index"), &ProfileManager::remove_class_profile);
|
||||
ClassDB::bind_method(D_METHOD("getc_player_profile"), &ProfileManager::getc_player_profile);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_class_profile", "class_id"), &ProfileManager::get_class_profile);
|
||||
ClassDB::bind_method(D_METHOD("save"), &ProfileManager::save);
|
||||
ClassDB::bind_method(D_METHOD("load"), &ProfileManager::load);
|
||||
ClassDB::bind_method(D_METHOD("save_profile", "name"), &ProfileManager::save_profile);
|
||||
@ -290,5 +237,5 @@ void ProfileManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &ProfileManager::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &ProfileManager::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_class_profile_changed", "profile"), &ProfileManager::_on_class_profile_changed);
|
||||
ClassDB::bind_method(D_METHOD("_on_player_profile_changed", "profile"), &ProfileManager::_on_player_profile_changed);
|
||||
}
|
||||
|
@ -27,36 +27,30 @@ SOFTWARE.
|
||||
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "../profiles/class_profile.h"
|
||||
#include "../profiles/player_profile.h"
|
||||
|
||||
class ProfileManager : public Object {
|
||||
GDCLASS(ProfileManager, Object);
|
||||
|
||||
public:
|
||||
static const String DEFAULT_PROFILE_FILE_NAME;
|
||||
|
||||
static ProfileManager *get_instance();
|
||||
|
||||
bool get_automatic_load() { return _automatic_load; }
|
||||
void set_automatic_load(bool load) { _automatic_load = load; }
|
||||
bool get_automatic_load() const;
|
||||
void set_automatic_load(const bool load);
|
||||
|
||||
bool get_automatic_save() { return _automatic_save; }
|
||||
void set_automatic_save(bool load) { _automatic_save = load; }
|
||||
bool get_automatic_save() const;
|
||||
void set_automatic_save(const bool load);
|
||||
|
||||
String get_save_file() const;
|
||||
void set_save_file(const String &file);
|
||||
|
||||
int get_last_used_class() const;
|
||||
void set_last_used_class(const int value);
|
||||
int gets_player_profile_count() const;
|
||||
Ref<PlayerProfile> gets_player_profile_index(const int index);
|
||||
void adds_player_profile(const Ref<PlayerProfile> &profile);
|
||||
void clears_player_profiles();
|
||||
void removes_player_profile(const int index);
|
||||
|
||||
int get_class_profile_count() const;
|
||||
Ref<ClassProfile> get_class_profile_index(const int index);
|
||||
void add_class_profile(Ref<ClassProfile> profile);
|
||||
void clear_class_profiles();
|
||||
void remove_class_profile(const int index);
|
||||
|
||||
Vector<Ref<ClassProfile> > &get_class_profiles();
|
||||
Ref<ClassProfile> get_class_profile(const int class_id);
|
||||
Ref<PlayerProfile> getc_player_profile();
|
||||
|
||||
void save();
|
||||
void load();
|
||||
@ -76,7 +70,7 @@ public:
|
||||
~ProfileManager();
|
||||
|
||||
protected:
|
||||
void _on_class_profile_changed(Ref<ClassProfile> profile);
|
||||
void _on_player_profile_changed(Ref<PlayerProfile> profile);
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
@ -85,12 +79,10 @@ private:
|
||||
bool _automatic_load;
|
||||
bool _automatic_save;
|
||||
|
||||
int _last_used_class;
|
||||
|
||||
String _profile_name;
|
||||
String _save_file;
|
||||
|
||||
Vector<Ref<ClassProfile> > _class_profiles;
|
||||
Vector<Ref<PlayerProfile> > _s_player_profiles;
|
||||
Ref<PlayerProfile> _c_player_profile;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user