2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* globals.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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. */
|
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
|
|
|
#ifndef GLOBAL_CONFIG_H
|
|
|
|
#define GLOBAL_CONFIG_H
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "os/thread_safe.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "set.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
class GlobalConfig : public Object {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(GlobalConfig, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
_THREAD_SAFE_CLASS_
|
|
|
|
|
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
typedef Map<String, Variant> CustomMap;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Singleton {
|
|
|
|
StringName name;
|
|
|
|
Object *ptr;
|
2017-03-05 16:44:50 +01:00
|
|
|
Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) {
|
|
|
|
name = p_name;
|
|
|
|
ptr = p_ptr;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2015-12-16 03:39:36 +01:00
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
NO_ORDER_BASE = 1 << 18
|
2015-12-16 03:39:36 +01:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct VariantContainer {
|
|
|
|
int order;
|
|
|
|
bool persist;
|
|
|
|
Variant variant;
|
2017-01-05 13:16:00 +01:00
|
|
|
Variant initial;
|
2014-02-10 02:10:30 +01:00
|
|
|
bool hide_from_editor;
|
|
|
|
bool overrided;
|
2017-03-05 16:44:50 +01:00
|
|
|
VariantContainer() {
|
|
|
|
order = 0;
|
|
|
|
hide_from_editor = false;
|
|
|
|
persist = false;
|
|
|
|
overrided = false;
|
|
|
|
}
|
|
|
|
VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) {
|
|
|
|
variant = p_variant;
|
|
|
|
order = p_order;
|
|
|
|
hide_from_editor = false;
|
|
|
|
persist = p_persist;
|
|
|
|
overrided = false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2015-12-16 03:39:36 +01:00
|
|
|
bool registering_order;
|
2014-02-10 02:10:30 +01:00
|
|
|
int last_order;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<StringName, VariantContainer> props;
|
2014-02-10 02:10:30 +01:00
|
|
|
String resource_path;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<StringName, PropertyInfo> custom_prop_info;
|
2014-02-10 02:10:30 +01:00
|
|
|
bool disable_platform_override;
|
2014-02-19 15:57:14 +01:00
|
|
|
bool using_datapack;
|
2015-12-14 22:36:53 +01:00
|
|
|
List<String> input_presets;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
static GlobalConfig *singleton;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Error _load_settings(const String p_path);
|
|
|
|
Error _load_settings_binary(const String p_path);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error _save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap());
|
|
|
|
Error _save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<Singleton> singletons;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<StringName, Object *> singleton_ptrs;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error _save_custom_bnd(const String &p_file);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _load_resource_pack(const String &p_pack);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _add_property_info_bind(const Dictionary &p_info);
|
2016-08-16 22:10:53 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
bool has(String p_var) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
String localize_path(const String &p_path) const;
|
|
|
|
String globalize_path(const String &p_path) const;
|
2017-01-05 13:16:00 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_initial_value(const String &p_name, const Variant &p_value);
|
|
|
|
bool property_can_revert(const String &p_name);
|
|
|
|
Variant property_get_revert(const String &p_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String get_resource_path() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
static GlobalConfig *get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void clear(const String &p_name);
|
|
|
|
int get_order(const String &p_name) const;
|
|
|
|
void set_order(const String &p_name, int p_order);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error setup(const String &p_path, const String &p_main_pack);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Set<String> &p_ignore_masks = Set<String>());
|
2014-02-10 02:10:30 +01:00
|
|
|
Error save();
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void add_singleton(const Singleton &p_singleton);
|
|
|
|
void get_singletons(List<Singleton> *p_singletons);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool has_singleton(const String &p_name) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector<String> get_optimizer_presets() const;
|
|
|
|
|
2015-12-14 22:36:53 +01:00
|
|
|
List<String> get_input_presets() const { return input_presets; }
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_disable_platform_override(bool p_disable);
|
2017-03-05 16:44:50 +01:00
|
|
|
Object *get_singleton_object(const String &p_name) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void register_global_defaults();
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
bool is_using_datapack() const;
|
|
|
|
|
2015-12-16 03:39:36 +01:00
|
|
|
void set_registering_order(bool p_registering);
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
GlobalConfig();
|
|
|
|
~GlobalConfig();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//not a macro any longer
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default);
|
|
|
|
#define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value)
|
2017-01-05 13:16:00 +01:00
|
|
|
#define GLOBAL_GET(m_var) GlobalConfig::get_singleton()->get(m_var)
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|