2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* globals.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2017-02-21 04:05:15 +01:00
|
|
|
#include "global_config.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "bind/core_bind.h"
|
|
|
|
#include "io/file_access_network.h"
|
|
|
|
#include "io/file_access_pack.h"
|
|
|
|
#include "io/marshalls.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "os/dir_access.h"
|
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "os/os.h"
|
2017-01-11 20:15:40 +01:00
|
|
|
#include "variant_parser.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-02-05 01:02:52 +01:00
|
|
|
#define FORMAT_VERSION 3
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GlobalConfig *GlobalConfig::singleton = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
GlobalConfig *GlobalConfig::get_singleton() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
String GlobalConfig::get_resource_path() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return resource_path;
|
|
|
|
};
|
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
String GlobalConfig::get_project_file_name() const {
|
|
|
|
|
|
|
|
return project_file_name;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String GlobalConfig::localize_path(const String &p_path) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (resource_path == "")
|
2014-02-10 02:10:30 +01:00
|
|
|
return p_path; //not initialied yet
|
|
|
|
|
2016-10-30 18:22:05 +01:00
|
|
|
if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
|
2017-03-05 16:44:50 +01:00
|
|
|
(p_path.is_abs_path() && !p_path.begins_with(resource_path)))
|
2014-02-10 02:10:30 +01:00
|
|
|
return p_path.simplify_path();
|
|
|
|
|
|
|
|
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String path = p_path.replace("\\", "/").simplify_path();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (dir->change_dir(path) == OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String cwd = dir->get_current_dir();
|
2017-03-05 16:44:50 +01:00
|
|
|
cwd = cwd.replace("\\", "/");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
memdelete(dir);
|
|
|
|
|
|
|
|
if (!cwd.begins_with(resource_path)) {
|
|
|
|
return p_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
return cwd.replace_first(resource_path, "res:/");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
memdelete(dir);
|
|
|
|
|
|
|
|
int sep = path.find_last("/");
|
|
|
|
if (sep == -1) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return "res://" + path;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2016-05-02 04:12:30 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String parent = path.substr(0, sep);
|
|
|
|
|
|
|
|
String plocal = localize_path(parent);
|
|
|
|
if (plocal == "") {
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
return plocal + path.substr(sep, path.size() - sep);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GlobalConfig::set_initial_value(const String &p_name, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!props.has(p_name));
|
2017-03-05 16:44:50 +01:00
|
|
|
props[p_name].initial = p_value;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String GlobalConfig::globalize_path(const String &p_path) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_path.begins_with("res://")) {
|
|
|
|
|
|
|
|
if (resource_path != "") {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return p_path.replace("res:/", resource_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
return p_path.replace("res://", "");
|
|
|
|
};
|
|
|
|
|
|
|
|
return p_path;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GlobalConfig::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_value.get_type() == Variant::NIL)
|
2014-02-10 02:10:30 +01:00
|
|
|
props.erase(p_name);
|
|
|
|
else {
|
|
|
|
if (props.has(p_name)) {
|
|
|
|
if (!props[p_name].overrided)
|
2017-03-05 16:44:50 +01:00
|
|
|
props[p_name].variant = p_value;
|
2015-12-16 03:39:36 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (props[p_name].order >= NO_ORDER_BASE && registering_order) {
|
|
|
|
props[p_name].order = last_order++;
|
2015-12-16 03:39:36 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
props[p_name] = VariantContainer(p_value, last_order++ + (registering_order ? 0 : NO_ORDER_BASE));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!disable_platform_override) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String s = String(p_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
int sl = s.find("/");
|
|
|
|
int p = s.find(".");
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p != -1 && sl != -1 && p < sl) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<String> ps = s.substr(0, sl).split(".");
|
|
|
|
String prop = s.substr(sl, s.length() - sl);
|
|
|
|
for (int i = 1; i < ps.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ps[i] == OS::get_singleton()->get_name()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String fullprop = ps[0] + prop;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
set(fullprop, p_value);
|
|
|
|
props[fullprop].overrided = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GlobalConfig::_get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
2017-01-15 01:56:22 +01:00
|
|
|
if (!props.has(p_name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
print_line("WARNING: not found: " + String(p_name));
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2017-01-15 01:56:22 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = props[p_name].variant;
|
2014-02-10 02:10:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct _VCSort {
|
|
|
|
|
|
|
|
String name;
|
|
|
|
Variant::Type type;
|
|
|
|
int order;
|
|
|
|
int flags;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::_get_property_list(List<PropertyInfo> *p_list) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
Set<_VCSort> vclist;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const VariantContainer *v = &E->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (v->hide_from_editor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_VCSort vc;
|
2017-03-05 16:44:50 +01:00
|
|
|
vc.name = E->key();
|
|
|
|
vc.order = v->order;
|
|
|
|
vc.type = v->variant.get_type();
|
2014-02-10 02:10:30 +01:00
|
|
|
if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload"))
|
2017-03-05 16:44:50 +01:00
|
|
|
vc.flags = PROPERTY_USAGE_STORAGE;
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
vclist.insert(vc);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (custom_prop_info.has(E->get().name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo pi = custom_prop_info[E->get().name];
|
|
|
|
pi.name = E->get().name;
|
|
|
|
pi.usage = E->get().flags;
|
|
|
|
p_list->push_back(pi);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GlobalConfig::_load_resource_pack(const String &p_pack) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (PackedData::get_singleton()->is_disabled())
|
|
|
|
return false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ok = PackedData::get_singleton()->add_pack(p_pack) == OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//if data.pck is found, all directory access will be from here
|
|
|
|
DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
|
2017-03-05 16:44:50 +01:00
|
|
|
using_datapack = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
static String _find_project_file(DirAccess *p_diraccess, bool p_res = false) {
|
|
|
|
p_diraccess->list_dir_begin();
|
|
|
|
String ret = "";
|
|
|
|
while (true) {
|
|
|
|
bool isdir;
|
|
|
|
String file = p_diraccess->get_next(&isdir);
|
|
|
|
if (file == "")
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!isdir) {
|
|
|
|
if (file.get_extension() == "godot") {
|
|
|
|
|
|
|
|
if (p_res) {
|
|
|
|
ret = "res://" + file;
|
|
|
|
} else {
|
|
|
|
ret = p_diraccess->get_current_dir() + "/" + file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_diraccess->list_dir_end();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static String _find_project_file() {
|
|
|
|
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
String ret = _find_project_file(dir, true);
|
|
|
|
memdelete(dir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
//If looking for files in network, just use network!
|
|
|
|
if (FileAccessNetworkClient::get_singleton()) {
|
2017-04-16 10:17:24 +02:00
|
|
|
String gdproj = _find_project_file();
|
|
|
|
if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
2017-02-21 04:05:15 +01:00
|
|
|
|
|
|
|
_load_settings("res://override.cfg");
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
String exec_path = OS::get_singleton()->get_executable_path();
|
|
|
|
|
|
|
|
//Attempt with a passed main pack first
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_main_pack != "") {
|
2014-06-28 04:21:45 +02:00
|
|
|
|
|
|
|
bool ok = _load_resource_pack(p_main_pack);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN);
|
2017-04-16 10:17:24 +02:00
|
|
|
String gdproj = _find_project_file();
|
|
|
|
if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
2017-02-21 04:05:15 +01:00
|
|
|
//load override from location of the main pack
|
|
|
|
_load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
|
2014-06-28 04:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
//Attempt with execname.pck
|
2017-03-05 16:44:50 +01:00
|
|
|
if (exec_path != "") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_load_resource_pack(exec_path.get_basename() + ".pck")) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
String gdproj = _find_project_file();
|
|
|
|
if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
2017-02-21 04:05:15 +01:00
|
|
|
//load override from location of executable
|
|
|
|
_load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
//Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this)
|
2017-03-05 16:44:50 +01:00
|
|
|
if (OS::get_singleton()->get_resource_dir() != "") {
|
2017-03-24 21:45:31 +01:00
|
|
|
//OS will call Globals->get_resource_path which will be empty if not overridden!
|
2014-02-10 02:10:30 +01:00
|
|
|
//if the OS would rather use somewhere else, then it will not be empty.
|
2017-02-21 04:05:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
|
|
|
|
if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
|
|
|
|
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
// data.pck and data.zip are deprecated and no longer supported, apologies.
|
|
|
|
// make sure this is loaded from the resource path
|
2017-04-16 10:17:24 +02:00
|
|
|
String gdproj = _find_project_file();
|
|
|
|
if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_load_settings("res://override.cfg");
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
//Nothing was found, try to find a *.godot somewhere!
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!d, ERR_CANT_CREATE);
|
2015-11-14 22:43:14 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
d->change_dir(p_path);
|
2015-11-14 22:43:14 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
String candidate = d->get_current_dir();
|
|
|
|
String current_dir = d->get_current_dir();
|
|
|
|
bool found = false;
|
2015-11-14 22:43:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2017-02-21 04:05:15 +01:00
|
|
|
//try to load settings in ascending through dirs shape!
|
2017-04-16 10:17:24 +02:00
|
|
|
String gdproj = _find_project_file(d);
|
|
|
|
if (_load_settings(gdproj) == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_load_settings(current_dir + "/override.cfg");
|
|
|
|
candidate = current_dir;
|
|
|
|
found = true;
|
2017-02-21 04:05:15 +01:00
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
d->change_dir("..");
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d->get_current_dir() == current_dir)
|
2017-02-21 04:05:15 +01:00
|
|
|
break; //not doing anything useful
|
2017-03-05 16:44:50 +01:00
|
|
|
current_dir = d->get_current_dir();
|
2017-02-21 04:05:15 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
resource_path = candidate;
|
|
|
|
resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case
|
2017-02-21 04:05:15 +01:00
|
|
|
memdelete(d);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
if (!found)
|
|
|
|
return ERR_FILE_NOT_FOUND;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
|
|
|
|
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
bool GlobalConfig::has(String p_var) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
return props.has(p_var);
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::set_registering_order(bool p_enable) {
|
2015-12-16 03:39:36 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
registering_order = p_enable;
|
2015-12-16 03:39:36 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
Error GlobalConfig::_load_settings_binary(const String p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Error err;
|
2017-03-05 16:44:50 +01:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
|
|
|
if (err != OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t hdr[4];
|
2017-03-05 16:44:50 +01:00
|
|
|
f->get_buffer(hdr, 4);
|
|
|
|
if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
memdelete(f);
|
2017-02-05 00:53:55 +01:00
|
|
|
ERR_EXPLAIN("Corrupted header in binary godot.cfb (not ECFG)");
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT;)
|
|
|
|
}
|
|
|
|
|
2015-12-16 03:39:36 +01:00
|
|
|
set_registering_order(false);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t count = f->get_32();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t slen = f->get_32();
|
2014-02-10 02:10:30 +01:00
|
|
|
CharString cs;
|
2017-03-05 16:44:50 +01:00
|
|
|
cs.resize(slen + 1);
|
|
|
|
cs[slen] = 0;
|
|
|
|
f->get_buffer((uint8_t *)cs.ptr(), slen);
|
2014-02-10 02:10:30 +01:00
|
|
|
String key;
|
|
|
|
key.parse_utf8(cs.ptr());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t vlen = f->get_32();
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<uint8_t> d;
|
|
|
|
d.resize(vlen);
|
2017-03-05 16:44:50 +01:00
|
|
|
f->get_buffer(d.ptr(), vlen);
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant value;
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = decode_variant(value, d.ptr(), d.size());
|
|
|
|
ERR_EXPLAIN("Error decoding property: " + key);
|
|
|
|
ERR_CONTINUE(err != OK);
|
|
|
|
set(key, value);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-16 03:39:36 +01:00
|
|
|
set_registering_order(true);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2017-01-05 13:16:00 +01:00
|
|
|
Error GlobalConfig::_load_settings(const String p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Error err;
|
2017-03-05 16:44:50 +01:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 20:15:40 +01:00
|
|
|
if (!f)
|
|
|
|
return ERR_CANT_OPEN;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 20:15:40 +01:00
|
|
|
VariantParser::StreamFile stream;
|
2017-03-05 16:44:50 +01:00
|
|
|
stream.f = f;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 20:15:40 +01:00
|
|
|
String assign;
|
|
|
|
Variant value;
|
|
|
|
VariantParser::Tag next_tag;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int lines = 0;
|
2017-01-11 20:15:40 +01:00
|
|
|
String error_text;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 20:15:40 +01:00
|
|
|
String section;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
assign = Variant();
|
2017-01-11 20:15:40 +01:00
|
|
|
next_tag.fields.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
next_tag.name = String();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
|
|
|
|
if (err == ERR_FILE_EOF) {
|
2017-01-11 20:15:40 +01:00
|
|
|
memdelete(f);
|
2017-04-16 10:17:24 +02:00
|
|
|
project_file_name = p_path.get_file();
|
2017-01-11 20:15:40 +01:00
|
|
|
return OK;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (err != OK) {
|
|
|
|
ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
|
2017-01-11 20:15:40 +01:00
|
|
|
memdelete(f);
|
|
|
|
return err;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (assign != String()) {
|
|
|
|
if (section == String() && assign == "config_version") {
|
2017-02-05 01:02:52 +01:00
|
|
|
int config_version = value;
|
|
|
|
if (config_version > FORMAT_VERSION) {
|
|
|
|
memdelete(f);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(config_version > FORMAT_VERSION, ERR_FILE_CANT_OPEN);
|
2017-02-05 01:02:52 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
set(section + "/" + assign, value);
|
|
|
|
} else if (next_tag.name != String()) {
|
|
|
|
section = next_tag.name;
|
2017-01-11 20:15:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
project_file_name = p_path.get_file();
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(f);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int GlobalConfig::get_order(const String &p_name) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!props.has(p_name), -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
return props[p_name].order;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GlobalConfig::set_order(const String &p_name, int p_order) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!props.has(p_name));
|
2017-03-05 16:44:50 +01:00
|
|
|
props[p_name].order = p_order;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GlobalConfig::clear(const String &p_name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!props.has(p_name));
|
|
|
|
props.erase(p_name);
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
Error GlobalConfig::save() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
if (project_file_name.empty()) {
|
|
|
|
String name = ((String)get("application/name")).replace(" ", "_");
|
|
|
|
return save_custom(get_resource_path() + "/" + name + ".godot");
|
|
|
|
} else {
|
|
|
|
return save_custom(get_resource_path() + "/" + project_file_name);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Error err;
|
2017-03-05 16:44:50 +01:00
|
|
|
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
|
|
|
|
if (err != OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-16 10:17:24 +02:00
|
|
|
ERR_EXPLAIN("Couldn't save godot.cfb at " + p_file);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err, err)
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
|
|
|
|
file->store_buffer(hdr, 4);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int count = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file->store_32(count); //store how many properties are saved
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String key = F->get();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->key() != "")
|
|
|
|
key = E->key() + "/" + key;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant value;
|
|
|
|
if (p_custom.has(key))
|
2017-03-05 16:44:50 +01:00
|
|
|
value = p_custom[key];
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
value = get(key);
|
|
|
|
|
|
|
|
file->store_32(key.length());
|
|
|
|
file->store_string(key);
|
|
|
|
|
|
|
|
int len;
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = encode_variant(value, NULL, len);
|
|
|
|
if (err != OK)
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(file);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector<uint8_t> buff;
|
|
|
|
buff.resize(len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
err = encode_variant(value, &buff[0], len);
|
|
|
|
if (err != OK)
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(file);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
file->store_32(len);
|
2017-03-05 16:44:50 +01:00
|
|
|
file->store_buffer(buff.ptr(), buff.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file->close();
|
|
|
|
memdelete(file);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error GlobalConfig::_save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Error err;
|
2017-03-05 16:44:50 +01:00
|
|
|
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (err) {
|
2017-04-16 10:17:24 +02:00
|
|
|
ERR_EXPLAIN("Couldn't save project file - " + p_file);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err, err)
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
file->store_string("config_version=" + itos(FORMAT_VERSION) + "\n");
|
2017-02-05 01:02:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
|
2017-02-05 01:02:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E != props.front())
|
2014-02-10 02:10:30 +01:00
|
|
|
file->store_string("\n");
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->key() != "")
|
|
|
|
file->store_string("[" + E->key() + "]\n\n");
|
|
|
|
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String key = F->get();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->key() != "")
|
|
|
|
key = E->key() + "/" + key;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant value;
|
|
|
|
if (p_custom.has(key))
|
2017-03-05 16:44:50 +01:00
|
|
|
value = p_custom[key];
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
value = get(key);
|
|
|
|
|
2017-01-11 20:15:40 +01:00
|
|
|
String vstr;
|
2017-03-05 16:44:50 +01:00
|
|
|
VariantWriter::write_to_string(value, vstr);
|
|
|
|
file->store_string(F->get() + "=" + vstr + "\n");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file->close();
|
|
|
|
memdelete(file);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2015-06-30 16:28:43 +02:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
Error GlobalConfig::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
|
2015-06-30 16:28:43 +02:00
|
|
|
|
|
|
|
return save_custom(p_file);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error GlobalConfig::save_custom(const String &p_path, const CustomMap &p_custom, const Set<String> &p_ignore_masks) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_path == "", ERR_INVALID_PARAMETER);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Set<_VCSort> vclist;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const VariantContainer *v = &G->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (v->hide_from_editor)
|
|
|
|
continue;
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
if (p_custom.has(G->key()))
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool discard = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Set<String>::Element *E = p_ignore_masks.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(G->key()).match(E->get())) {
|
|
|
|
discard = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (discard)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_VCSort vc;
|
2017-03-05 16:44:50 +01:00
|
|
|
vc.name = G->key(); //*k;
|
|
|
|
vc.order = v->order;
|
|
|
|
vc.type = v->variant.get_type();
|
|
|
|
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
|
|
|
|
if (v->variant == v->initial)
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
vclist.insert(vc);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_VCSort vc;
|
2017-03-05 16:44:50 +01:00
|
|
|
vc.name = E->key();
|
|
|
|
vc.order = 0xFFFFFFF;
|
|
|
|
vc.type = E->get().get_type();
|
|
|
|
vc.flags = PROPERTY_USAGE_STORAGE;
|
2014-02-10 02:10:30 +01:00
|
|
|
vclist.insert(vc);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, List<String> > props;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String category = E->get().name;
|
|
|
|
String name = E->get().name;
|
|
|
|
|
|
|
|
int div = category.find("/");
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (div < 0)
|
|
|
|
category = "";
|
2014-02-10 02:10:30 +01:00
|
|
|
else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
category = category.substr(0, div);
|
|
|
|
name = name.substr(div + 1, name.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
props[category].push_back(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_path.ends_with(".cfg"))
|
2017-03-05 16:44:50 +01:00
|
|
|
return _save_settings_text(p_path, props, p_custom);
|
2014-02-10 02:10:30 +01:00
|
|
|
else if (p_path.ends_with(".cfb"))
|
2017-03-05 16:44:50 +01:00
|
|
|
return _save_settings_binary(p_path, props, p_custom);
|
2014-02-10 02:10:30 +01:00
|
|
|
else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_EXPLAIN("Unknown config file format: " + p_path);
|
|
|
|
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
Error err = file->open(dst_file,FileAccess::WRITE);
|
|
|
|
if (err) {
|
|
|
|
memdelete(file);
|
2017-02-05 00:53:55 +01:00
|
|
|
ERR_EXPLAIN("Coudln't save godot.cfg");
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND_V(err,err)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(Map<String,List<String> >::Element *E=props.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E!=props.front())
|
|
|
|
file->store_string("\n");
|
|
|
|
|
|
|
|
if (E->key()!="")
|
|
|
|
file->store_string("["+E->key()+"]\n\n");
|
|
|
|
for(List<String>::Element *F=E->get().front();F;F=F->next()) {
|
|
|
|
|
|
|
|
String key = F->get();
|
|
|
|
if (E->key()!="")
|
|
|
|
key=E->key()+"/"+key;
|
|
|
|
Variant value;
|
|
|
|
|
|
|
|
if (p_custom.has(key))
|
|
|
|
value=p_custom[key];
|
|
|
|
else
|
|
|
|
value = get(key);
|
|
|
|
|
|
|
|
file->store_string(F->get()+"="+_encode_variant(value)+"\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file->close();
|
|
|
|
memdelete(file);
|
|
|
|
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
if (GlobalConfig::get_singleton()->has(p_var)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
GlobalConfig::get_singleton()->set_initial_value(p_var, p_default);
|
2017-01-05 13:16:00 +01:00
|
|
|
return GlobalConfig::get_singleton()->get(p_var);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
GlobalConfig::get_singleton()->set(p_var, p_default);
|
|
|
|
GlobalConfig::get_singleton()->set_initial_value(p_var, p_default);
|
2014-02-10 02:10:30 +01:00
|
|
|
return p_default;
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::add_singleton(const Singleton &p_singleton) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
singletons.push_back(p_singleton);
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton_ptrs[p_singleton.name] = p_singleton.ptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Object *GlobalConfig::get_singleton_object(const String &p_name) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
|
2016-08-29 01:57:27 +02:00
|
|
|
if (!E)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return E->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GlobalConfig::has_singleton(const String &p_name) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return get_singleton_object(p_name) != NULL;
|
|
|
|
};
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::get_singletons(List<Singleton> *p_singletons) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
|
2014-02-10 02:10:30 +01:00
|
|
|
p_singletons->push_back(E->get());
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
Vector<String> GlobalConfig::get_optimizer_presets() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<PropertyInfo> pi;
|
2017-01-05 13:16:00 +01:00
|
|
|
GlobalConfig::get_singleton()->get_property_list(&pi);
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<String> names;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!E->get().name.begins_with("optimizer_presets/"))
|
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
names.push_back(E->get().name.get_slicec('/', 1));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
names.sort();
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GlobalConfig::_add_property_info_bind(const Dictionary &p_info) {
|
2016-08-16 22:10:53 +02:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!p_info.has("name"));
|
|
|
|
ERR_FAIL_COND(!p_info.has("type"));
|
|
|
|
|
|
|
|
PropertyInfo pinfo;
|
|
|
|
pinfo.name = p_info["name"];
|
|
|
|
ERR_FAIL_COND(!props.has(pinfo.name));
|
|
|
|
pinfo.type = Variant::Type(p_info["type"].operator int());
|
|
|
|
ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
|
|
|
|
|
|
|
|
if (p_info.has("hint"))
|
|
|
|
pinfo.hint = PropertyHint(p_info["hint"].operator int());
|
|
|
|
if (p_info.has("hint_string"))
|
|
|
|
pinfo.hint_string = p_info["hint_string"];
|
|
|
|
|
|
|
|
set_custom_property_info(pinfo.name, pinfo);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GlobalConfig::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!props.has(p_prop));
|
2017-03-05 16:44:50 +01:00
|
|
|
custom_prop_info[p_prop] = p_info;
|
|
|
|
custom_prop_info[p_prop].name = p_prop;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::set_disable_platform_override(bool p_disable) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
disable_platform_override = p_disable;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
bool GlobalConfig::is_using_datapack() const {
|
2014-02-19 15:57:14 +01:00
|
|
|
|
|
|
|
return using_datapack;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GlobalConfig::property_can_revert(const String &p_name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
if (!props.has(p_name))
|
|
|
|
return false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return props[p_name].initial != props[p_name].variant;
|
2017-01-05 13:16:00 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant GlobalConfig::property_get_revert(const String &p_name) {
|
2017-01-05 13:16:00 +01:00
|
|
|
|
|
|
|
if (!props.has(p_name))
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
return props[p_name].initial;
|
|
|
|
}
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
void GlobalConfig::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("has", "name"), &GlobalConfig::has);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_order", "name", "pos"), &GlobalConfig::set_order);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_order", "name"), &GlobalConfig::get_order);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &GlobalConfig::set_initial_value);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &GlobalConfig::_add_property_info_bind);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear", "name"), &GlobalConfig::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("localize_path", "path"), &GlobalConfig::localize_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("globalize_path", "path"), &GlobalConfig::globalize_path);
|
2017-04-16 10:17:24 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_project_file_name"), &GlobalConfig::get_project_file_name);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("save"), &GlobalConfig::save);
|
|
|
|
ClassDB::bind_method(D_METHOD("has_singleton", "name"), &GlobalConfig::has_singleton);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object);
|
|
|
|
ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &GlobalConfig::_load_resource_pack);
|
|
|
|
ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &GlobalConfig::property_can_revert);
|
|
|
|
ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &GlobalConfig::property_get_revert);
|
2015-06-30 16:28:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("save_custom", "file"), &GlobalConfig::_save_custom_bnd);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
GlobalConfig::GlobalConfig() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
|
|
|
last_order = 0;
|
|
|
|
disable_platform_override = false;
|
|
|
|
registering_order = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Array va;
|
|
|
|
InputEvent key;
|
2017-03-05 16:44:50 +01:00
|
|
|
key.type = InputEvent::KEY;
|
2014-02-10 02:10:30 +01:00
|
|
|
InputEvent joyb;
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.type = InputEvent::JOYPAD_BUTTON;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("application/name", "");
|
|
|
|
GLOBAL_DEF("application/main_scene", "");
|
|
|
|
custom_prop_info["application/main_scene"] = PropertyInfo(Variant::STRING, "application/main_scene", PROPERTY_HINT_FILE, "tscn,scn,xscn,xml,res");
|
|
|
|
GLOBAL_DEF("application/disable_stdout", false);
|
|
|
|
GLOBAL_DEF("application/disable_stderr", false);
|
|
|
|
GLOBAL_DEF("application/use_shared_user_dir", true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
key.key.scancode = KEY_RETURN;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
key.key.scancode = KEY_ENTER;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
key.key.scancode = KEY_SPACE;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_BUTTON_0;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_accept", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_accept");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_SPACE;
|
2015-06-06 14:44:38 +02:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_BUTTON_3;
|
2015-06-06 14:44:38 +02:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_select", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_select");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_ESCAPE;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_BUTTON_1;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_cancel", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_cancel");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_TAB;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_focus_next", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_focus_next");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_TAB;
|
|
|
|
key.key.mod.shift = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_focus_prev", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_focus_prev");
|
2017-03-05 16:44:50 +01:00
|
|
|
key.key.mod.shift = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_LEFT;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_DPAD_LEFT;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_left", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_left");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_RIGHT;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_DPAD_RIGHT;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_right", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_right");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_UP;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_DPAD_UP;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_up", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_up");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_DOWN;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
joyb.joy_button.button_index = JOY_DPAD_DOWN;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(joyb);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_down", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_down");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_PAGEUP;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_page_up", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_page_up");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
va = Array();
|
|
|
|
key.key.scancode = KEY_PAGEDOWN;
|
2014-02-10 02:10:30 +01:00
|
|
|
va.push_back(key);
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("input/ui_page_down", va);
|
2015-12-14 22:36:53 +01:00
|
|
|
input_presets.push_back("input/ui_page_down");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//GLOBAL_DEF("display/handheld/orientation", "landscape");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
custom_prop_info["display/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
|
|
|
|
custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
|
|
|
|
custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("debug/profiler/max_functions", 16384);
|
|
|
|
using_datapack = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
GlobalConfig::~GlobalConfig() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|