1 /**
2 Contains global variables accessible from everywhere.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.projectsettings;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 /**
24 Contains global variables accessible from everywhere.
25 
26 Use $(D getSetting), $(D setSetting) or $(D hasSetting) to access them. Variables stored in `project.godot` are also loaded into ProjectSettings, making this object very useful for reading custom game configuration options.
27 When naming a Project Settings property, use the full path to the setting including the category. For example, `"application/config/name"` for the project name. Category and property names can be viewed in the Project Settings dialog.
28 $(B Feature tags:) Project settings can be overridden for specific platforms and configurations (debug, release, ...) using $(D url=https://docs.godotengine.org/en/latest/tutorials/export/feature_tags.html)feature tags$(D /url).
29 $(B Overriding:) Any project setting can be overridden by creating a file named `override.cfg` in the project's root directory. This can also be used in exported projects by placing this file in the same directory as the project binary. Overriding will still take the base project settings' $(D url=https://docs.godotengine.org/en/latest/tutorials/export/feature_tags.html)feature tags$(D /url) in account. Therefore, make sure to $(I also) override the setting with the desired feature tags if you want them to override base project settings on all platforms and configurations.
30 */
31 @GodotBaseClass struct ProjectSettingsSingleton
32 {
33 	package(godot) enum string _GODOT_internal_name = "ProjectSettings";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; }
37 	alias _GODOT_base this;
38 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
39 	package(godot) __gshared bool _classBindingInitialized = false;
40 	package(godot) static struct GDNativeClassBinding
41 	{
42 		__gshared:
43 		godot_object _singleton;
44 		immutable char* _singletonName = "ProjectSettings";
45 		@GodotName("add_property_info") GodotMethod!(void, Dictionary) addPropertyInfo;
46 		@GodotName("clear") GodotMethod!(void, String) clear;
47 		@GodotName("get_order") GodotMethod!(long, String) getOrder;
48 		@GodotName("get_setting") GodotMethod!(Variant, String) getSetting;
49 		@GodotName("globalize_path") GodotMethod!(String, String) globalizePath;
50 		@GodotName("has_setting") GodotMethod!(bool, String) hasSetting;
51 		@GodotName("load_resource_pack") GodotMethod!(bool, String, bool, long) loadResourcePack;
52 		@GodotName("localize_path") GodotMethod!(String, String) localizePath;
53 		@GodotName("property_can_revert") GodotMethod!(bool, String) propertyCanRevert;
54 		@GodotName("property_get_revert") GodotMethod!(Variant, String) propertyGetRevert;
55 		@GodotName("save") GodotMethod!(GodotError) save;
56 		@GodotName("save_custom") GodotMethod!(GodotError, String) saveCustom;
57 		@GodotName("set_initial_value") GodotMethod!(void, String, Variant) setInitialValue;
58 		@GodotName("set_order") GodotMethod!(void, String, long) setOrder;
59 		@GodotName("set_setting") GodotMethod!(void, String, Variant) setSetting;
60 	}
61 	/// 
62 	pragma(inline, true) bool opEquals(in ProjectSettingsSingleton other) const
63 	{ return _godot_object.ptr is other._godot_object.ptr; }
64 	/// 
65 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
66 	{ _godot_object.ptr = n; return null; }
67 	/// 
68 	pragma(inline, true) bool opEquals(typeof(null) n) const
69 	{ return _godot_object.ptr is n; }
70 	/// 
71 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
72 	mixin baseCasts;
73 	/// Construct a new instance of ProjectSettingsSingleton.
74 	/// Note: use `memnew!ProjectSettingsSingleton` instead.
75 	static ProjectSettingsSingleton _new()
76 	{
77 		static godot_class_constructor constructor;
78 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ProjectSettings");
79 		if(constructor is null) return typeof(this).init;
80 		return cast(ProjectSettingsSingleton)(constructor());
81 	}
82 	@disable new(size_t s);
83 	/**
84 	Adds a custom property info to a property. The dictionary must contain:
85 	- `name`: $(D String) (the property's name)
86 	- `type`: $(D long) (see $(D Variant.type))
87 	- optionally `hint`: $(D long) (see $(D propertyhint)) and `hint_string`: $(D String)
88 	$(B Example:)
89 	
90 	
91 	ProjectSettings.set("category/property_name", 0)
92 	
93 	var property_info = {
94 	    "name": "category/property_name",
95 	    "type": TYPE_INT,
96 	    "hint": PROPERTY_HINT_ENUM,
97 	    "hint_string": "one,two,three"
98 	}
99 	
100 	ProjectSettings.add_property_info(property_info)
101 	
102 	
103 	*/
104 	void addPropertyInfo(in Dictionary hint)
105 	{
106 		checkClassBinding!(typeof(this))();
107 		ptrcall!(void)(GDNativeClassBinding.addPropertyInfo, _godot_object, hint);
108 	}
109 	/**
110 	Clears the whole configuration (not recommended, may break things).
111 	*/
112 	void clear(in String name)
113 	{
114 		checkClassBinding!(typeof(this))();
115 		ptrcall!(void)(GDNativeClassBinding.clear, _godot_object, name);
116 	}
117 	/**
118 	Returns the order of a configuration value (influences when saved to the config file).
119 	*/
120 	long getOrder(in String name) const
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(long)(GDNativeClassBinding.getOrder, _godot_object, name);
124 	}
125 	/**
126 	Returns the value of a setting.
127 	$(B Example:)
128 	
129 	
130 	print(ProjectSettings.get_setting("application/config/name"))
131 	
132 	
133 	*/
134 	Variant getSetting(in String name) const
135 	{
136 		checkClassBinding!(typeof(this))();
137 		return ptrcall!(Variant)(GDNativeClassBinding.getSetting, _godot_object, name);
138 	}
139 	/**
140 	Returns the absolute, native OS path corresponding to the localized `path` (starting with `res://` or `user://`). The returned path will vary depending on the operating system and user preferences. See $(D url=https://docs.godotengine.org/en/3.3/tutorials/io/data_paths.html)File paths in Godot projects$(D /url) to see what those paths convert to. See also $(D localizePath).
141 	$(B Note:) $(D globalizePath) with `res://` will not work in an exported project. Instead, prepend the executable's base directory to the path when running from an exported project:
142 	
143 	
144 	var path = ""
145 	if OS.has_feature("editor"):
146 	    # Running from an editor binary.
147 	    # `path` will contain the absolute path to `hello.txt` located in the project root.
148 	    path = ProjectSettings.globalize_path("res://hello.txt")
149 	else:
150 	    # Running from an exported project.
151 	    # `path` will contain the absolute path to `hello.txt` next to the executable.
152 	    # This is *not* identical to using `ProjectSettings.globalize_path()` with a `res://` path,
153 	    # but is close enough in spirit.
154 	    path = OS.get_executable_path().get_base_dir().plus_file("hello.txt")
155 	
156 	
157 	*/
158 	String globalizePath(in String path) const
159 	{
160 		checkClassBinding!(typeof(this))();
161 		return ptrcall!(String)(GDNativeClassBinding.globalizePath, _godot_object, path);
162 	}
163 	/**
164 	Returns `true` if a configuration value is present.
165 	*/
166 	bool hasSetting(in String name) const
167 	{
168 		checkClassBinding!(typeof(this))();
169 		return ptrcall!(bool)(GDNativeClassBinding.hasSetting, _godot_object, name);
170 	}
171 	/**
172 	Loads the contents of the .pck or .zip file specified by `pack` into the resource filesystem (`res://`). Returns `true` on success.
173 	$(B Note:) If a file from `pack` shares the same path as a file already in the resource filesystem, any attempts to load that file will use the file from `pack` unless `replace_files` is set to `false`.
174 	$(B Note:) The optional `offset` parameter can be used to specify the offset in bytes to the start of the resource pack. This is only supported for .pck files.
175 	*/
176 	bool loadResourcePack(in String pack, in bool replace_files = true, in long offset = 0)
177 	{
178 		checkClassBinding!(typeof(this))();
179 		return ptrcall!(bool)(GDNativeClassBinding.loadResourcePack, _godot_object, pack, replace_files, offset);
180 	}
181 	/**
182 	Returns the localized path (starting with `res://`) corresponding to the absolute, native OS `path`. See also $(D globalizePath).
183 	*/
184 	String localizePath(in String path) const
185 	{
186 		checkClassBinding!(typeof(this))();
187 		return ptrcall!(String)(GDNativeClassBinding.localizePath, _godot_object, path);
188 	}
189 	/**
190 	Returns `true` if the specified property exists and its initial value differs from the current value.
191 	*/
192 	bool propertyCanRevert(in String name)
193 	{
194 		checkClassBinding!(typeof(this))();
195 		return ptrcall!(bool)(GDNativeClassBinding.propertyCanRevert, _godot_object, name);
196 	}
197 	/**
198 	Returns the specified property's initial value. Returns `null` if the property does not exist.
199 	*/
200 	Variant propertyGetRevert(in String name)
201 	{
202 		checkClassBinding!(typeof(this))();
203 		return ptrcall!(Variant)(GDNativeClassBinding.propertyGetRevert, _godot_object, name);
204 	}
205 	/**
206 	Saves the configuration to the `project.godot` file.
207 	$(B Note:) This method is intended to be used by editor plugins, as modified $(D ProjectSettings) can't be loaded back in the running app. If you want to change project settings in exported projects, use $(D saveCustom) to save `override.cfg` file.
208 	*/
209 	GodotError save()
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(GodotError)(GDNativeClassBinding.save, _godot_object);
213 	}
214 	/**
215 	Saves the configuration to a custom file. The file extension must be `.godot` (to save in text-based $(D ConfigFile) format) or `.binary` (to save in binary format). You can also save `override.cfg` file, which is also text, but can be used in exported projects unlike other formats.
216 	*/
217 	GodotError saveCustom(in String file)
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(GodotError)(GDNativeClassBinding.saveCustom, _godot_object, file);
221 	}
222 	/**
223 	Sets the specified property's initial value. This is the value the property reverts to.
224 	*/
225 	void setInitialValue(VariantArg1)(in String name, in VariantArg1 value)
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(GDNativeClassBinding.setInitialValue, _godot_object, name, value);
229 	}
230 	/**
231 	Sets the order of a configuration value (influences when saved to the config file).
232 	*/
233 	void setOrder(in String name, in long position)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(GDNativeClassBinding.setOrder, _godot_object, name, position);
237 	}
238 	/**
239 	Sets the value of a setting.
240 	$(B Example:)
241 	
242 	
243 	ProjectSettings.set_setting("application/config/name", "Example")
244 	
245 	
246 	*/
247 	void setSetting(VariantArg1)(in String name, in VariantArg1 value)
248 	{
249 		checkClassBinding!(typeof(this))();
250 		ptrcall!(void)(GDNativeClassBinding.setSetting, _godot_object, name, value);
251 	}
252 }
253 /// Returns: the ProjectSettingsSingleton
254 @property @nogc nothrow pragma(inline, true)
255 ProjectSettingsSingleton ProjectSettings()
256 {
257 	checkClassBinding!ProjectSettingsSingleton();
258 	return ProjectSettingsSingleton(ProjectSettingsSingleton.GDNativeClassBinding._singleton);
259 }