2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "input_profile.h"
|
|
|
|
|
2022-08-17 15:35:28 +02:00
|
|
|
#include "core/config/project_settings.h"
|
2022-08-17 14:19:55 +02:00
|
|
|
#include "core/string/ustring.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
#include "../class_profile.h"
|
|
|
|
|
|
|
|
Ref<ClassProfile> InputProfile::get_owner() {
|
|
|
|
return Ref<ClassProfile>(_owner);
|
|
|
|
}
|
|
|
|
void InputProfile::set_owner(ClassProfile *owner) {
|
|
|
|
_owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
Array InputProfile::get_data() {
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
void InputProfile::set_data(const Array &data) {
|
|
|
|
_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputProfile::load_to_projectsettings() {
|
2022-03-19 13:52:08 +01:00
|
|
|
ERR_FAIL_COND(!ProjectSettings::get_singleton());
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
for (int i = 0; i < _data.size(); ++i) {
|
|
|
|
Array arr = _data[i];
|
|
|
|
|
|
|
|
ProjectSettings::get_singleton()->set(arr[0], arr[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputProfile::save_from_projectsettings() {
|
|
|
|
_data.clear();
|
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
ProjectSettings::get_singleton()->get_property_list(&pinfo);
|
|
|
|
|
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
const PropertyInfo &pi = E->get();
|
|
|
|
|
|
|
|
if (!pi.name.begins_with("input/"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
|
|
|
|
|
|
|
|
Dictionary action = ProjectSettings::get_singleton()->get(pi.name);
|
|
|
|
|
|
|
|
Array arr;
|
|
|
|
arr.push_back(name);
|
|
|
|
arr.push_back(action);
|
|
|
|
|
|
|
|
_data.push_back(arr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputProfile::load_defaults() {
|
|
|
|
_data.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputProfile::emit_change() {
|
|
|
|
emit_signal("changed");
|
|
|
|
|
|
|
|
if (_owner != NULL)
|
|
|
|
_owner->emit_change();
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary InputProfile::to_dict() const {
|
|
|
|
Dictionary dict;
|
|
|
|
|
|
|
|
dict["data"] = _data;
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
void InputProfile::from_dict(const Dictionary &dict) {
|
|
|
|
_data = dict.get("data", Array());
|
|
|
|
|
|
|
|
emit_change();
|
|
|
|
}
|
|
|
|
|
|
|
|
InputProfile::InputProfile() {
|
2022-03-19 13:52:08 +01:00
|
|
|
_owner = nullptr;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputProfile::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("changed"));
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_owner"), &InputProfile::get_owner);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("load_defaults"), &InputProfile::load_defaults);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_data"), &InputProfile::get_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data", "data"), &InputProfile::set_data);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data"), "set_data", "get_data");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("load_to_projectsettings"), &InputProfile::load_to_projectsettings);
|
|
|
|
ClassDB::bind_method(D_METHOD("save_from_projectsettings"), &InputProfile::save_from_projectsettings);
|
2022-03-16 09:02:48 +01:00
|
|
|
}
|