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.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 /** 23 Contains global variables accessible from everywhere. 24 25 Use "ProjectSettings.get_setting(variable)", "ProjectSettings.set_setting(variable,value)" or "ProjectSettings.has_setting(variable)" to access them. Variables stored in project.godot are also loaded into ProjectSettings, making this object very useful for reading custom game configuration options. 26 */ 27 @GodotBaseClass struct ProjectSettingsSingleton 28 { 29 enum string _GODOT_internal_name = "ProjectSettings"; 30 public: 31 @nogc nothrow: 32 union { godot_object _godot_object; GodotObject _GODOT_base; } 33 alias _GODOT_base this; 34 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 35 package(godot) __gshared bool _classBindingInitialized = false; 36 package(godot) static struct _classBinding 37 { 38 __gshared: 39 godot_object _singleton; 40 immutable char* _singletonName = "ProjectSettings"; 41 @GodotName("has_setting") GodotMethod!(bool, String) hasSetting; 42 @GodotName("set_setting") GodotMethod!(void, String, Variant) setSetting; 43 @GodotName("get_setting") GodotMethod!(Variant, String) getSetting; 44 @GodotName("set_order") GodotMethod!(void, String, long) setOrder; 45 @GodotName("get_order") GodotMethod!(long, String) getOrder; 46 @GodotName("set_initial_value") GodotMethod!(void, String, Variant) setInitialValue; 47 @GodotName("add_property_info") GodotMethod!(void, Dictionary) addPropertyInfo; 48 @GodotName("clear") GodotMethod!(void, String) clear; 49 @GodotName("localize_path") GodotMethod!(String, String) localizePath; 50 @GodotName("globalize_path") GodotMethod!(String, String) globalizePath; 51 @GodotName("save") GodotMethod!(GodotError) save; 52 @GodotName("load_resource_pack") GodotMethod!(bool, String) loadResourcePack; 53 @GodotName("property_can_revert") GodotMethod!(bool, String) propertyCanRevert; 54 @GodotName("property_get_revert") GodotMethod!(Variant, String) propertyGetRevert; 55 @GodotName("save_custom") GodotMethod!(GodotError, String) saveCustom; 56 } 57 bool opEquals(in ProjectSettingsSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; } 58 ProjectSettingsSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 59 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 60 mixin baseCasts; 61 static ProjectSettingsSingleton _new() 62 { 63 static godot_class_constructor constructor; 64 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ProjectSettings"); 65 if(constructor is null) return typeof(this).init; 66 return cast(ProjectSettingsSingleton)(constructor()); 67 } 68 @disable new(size_t s); 69 /** 70 Return true if a configuration value is present. 71 */ 72 bool hasSetting(StringArg0)(in StringArg0 name) const 73 { 74 checkClassBinding!(typeof(this))(); 75 return ptrcall!(bool)(_classBinding.hasSetting, _godot_object, name); 76 } 77 /** 78 79 */ 80 void setSetting(StringArg0, VariantArg1)(in StringArg0 name, in VariantArg1 value) 81 { 82 checkClassBinding!(typeof(this))(); 83 ptrcall!(void)(_classBinding.setSetting, _godot_object, name, value); 84 } 85 /** 86 87 */ 88 Variant getSetting(StringArg0)(in StringArg0 name) const 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(Variant)(_classBinding.getSetting, _godot_object, name); 92 } 93 /** 94 Set the order of a configuration value (influences when saved to the config file). 95 */ 96 void setOrder(StringArg0)(in StringArg0 name, in long position) 97 { 98 checkClassBinding!(typeof(this))(); 99 ptrcall!(void)(_classBinding.setOrder, _godot_object, name, position); 100 } 101 /** 102 Return the order of a configuration value (influences when saved to the config file). 103 */ 104 long getOrder(StringArg0)(in StringArg0 name) const 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(long)(_classBinding.getOrder, _godot_object, name); 108 } 109 /** 110 111 */ 112 void setInitialValue(StringArg0, VariantArg1)(in StringArg0 name, in VariantArg1 value) 113 { 114 checkClassBinding!(typeof(this))(); 115 ptrcall!(void)(_classBinding.setInitialValue, _godot_object, name, value); 116 } 117 /** 118 Add a custom property info to a property. The dictionary must contain: name:$(D String)(the name of the property) and type:$(D long)(see TYPE_* in $(D @GlobalScope)), and optionally hint:$(D long)(see PROPERTY_HINT_* in $(D @GlobalScope)), hint_string:$(D String). 119 Example: 120 121 122 ProjectSettings.set("category/property_name", 0) 123 124 var property_info = { 125 "name": "category/property_name", 126 "type": TYPE_INT, 127 "hint": PROPERTY_HINT_ENUM, 128 "hint_string": "one,two,three" 129 } 130 131 ProjectSettings.add_property_info(property_info) 132 133 134 */ 135 void addPropertyInfo(in Dictionary hint) 136 { 137 checkClassBinding!(typeof(this))(); 138 ptrcall!(void)(_classBinding.addPropertyInfo, _godot_object, hint); 139 } 140 /** 141 Clear the whole configuration (not recommended, may break things). 142 */ 143 void clear(StringArg0)(in StringArg0 name) 144 { 145 checkClassBinding!(typeof(this))(); 146 ptrcall!(void)(_classBinding.clear, _godot_object, name); 147 } 148 /** 149 Convert a path to a localized path (res:// path). 150 */ 151 String localizePath(StringArg0)(in StringArg0 path) const 152 { 153 checkClassBinding!(typeof(this))(); 154 return ptrcall!(String)(_classBinding.localizePath, _godot_object, path); 155 } 156 /** 157 Convert a localized path (res://) to a full native OS path. 158 */ 159 String globalizePath(StringArg0)(in StringArg0 path) const 160 { 161 checkClassBinding!(typeof(this))(); 162 return ptrcall!(String)(_classBinding.globalizePath, _godot_object, path); 163 } 164 /** 165 Saves the configuration to the project.godot file. 166 */ 167 GodotError save() 168 { 169 checkClassBinding!(typeof(this))(); 170 return ptrcall!(GodotError)(_classBinding.save, _godot_object); 171 } 172 /** 173 Loads the contents of the .pck or .zip file specified by `pack` into the resource filesystem (res://). Returns true on success. 174 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`. 175 */ 176 bool loadResourcePack(StringArg0)(in StringArg0 pack) 177 { 178 checkClassBinding!(typeof(this))(); 179 return ptrcall!(bool)(_classBinding.loadResourcePack, _godot_object, pack); 180 } 181 /** 182 Returns true if the specified property exists and its initial value differs from the current value. 183 */ 184 bool propertyCanRevert(StringArg0)(in StringArg0 name) 185 { 186 checkClassBinding!(typeof(this))(); 187 return ptrcall!(bool)(_classBinding.propertyCanRevert, _godot_object, name); 188 } 189 /** 190 Returns the initial value of the specified property. Returns null if the property does not exist. 191 */ 192 Variant propertyGetRevert(StringArg0)(in StringArg0 name) 193 { 194 checkClassBinding!(typeof(this))(); 195 return ptrcall!(Variant)(_classBinding.propertyGetRevert, _godot_object, name); 196 } 197 /** 198 Saves the configuration to a custom file. 199 */ 200 GodotError saveCustom(StringArg0)(in StringArg0 file) 201 { 202 checkClassBinding!(typeof(this))(); 203 return ptrcall!(GodotError)(_classBinding.saveCustom, _godot_object, file); 204 } 205 } 206 /// Returns: the ProjectSettingsSingleton 207 @property @nogc nothrow pragma(inline, true) 208 ProjectSettingsSingleton ProjectSettings() 209 { 210 checkClassBinding!ProjectSettingsSingleton(); 211 return ProjectSettingsSingleton(ProjectSettingsSingleton._classBinding._singleton); 212 }