1 /** 2 Base class for all resources. 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.resource; 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 import godot.classdb; 23 import godot.reference; 24 import godot.node; 25 /** 26 Base class for all resources. 27 28 Resource is the base class for all resource types. Resources are primarily data containers. They are reference counted and freed when no longer in use. They are also loaded only once from disk, and further attempts to load the resource will return the same reference (all this in contrast to a $(D Node), which is not reference counted and can be instanced from disk as many times as desired). Resources can be saved externally on disk or bundled into another object, such as a $(D Node) or another resource. 29 */ 30 @GodotBaseClass struct Resource 31 { 32 enum string _GODOT_internal_name = "Resource"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; Reference _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("_setup_local_to_scene") GodotMethod!(void) _setupLocalToScene; 43 @GodotName("set_path") GodotMethod!(void, String) setPath; 44 @GodotName("take_over_path") GodotMethod!(void, String) takeOverPath; 45 @GodotName("get_path") GodotMethod!(String) getPath; 46 @GodotName("set_name") GodotMethod!(void, String) setName; 47 @GodotName("get_name") GodotMethod!(String) getName; 48 @GodotName("get_rid") GodotMethod!(RID) getRid; 49 @GodotName("set_local_to_scene") GodotMethod!(void, bool) setLocalToScene; 50 @GodotName("is_local_to_scene") GodotMethod!(bool) isLocalToScene; 51 @GodotName("get_local_scene") GodotMethod!(Node) getLocalScene; 52 @GodotName("setup_local_to_scene") GodotMethod!(void) setupLocalToScene; 53 @GodotName("duplicate") GodotMethod!(Resource, bool) duplicate; 54 } 55 bool opEquals(in Resource other) const { return _godot_object.ptr is other._godot_object.ptr; } 56 Resource opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 57 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 58 mixin baseCasts; 59 static Resource _new() 60 { 61 static godot_class_constructor constructor; 62 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Resource"); 63 if(constructor is null) return typeof(this).init; 64 return cast(Resource)(constructor()); 65 } 66 @disable new(size_t s); 67 /** 68 69 */ 70 void _setupLocalToScene() 71 { 72 Array _GODOT_args = Array.empty_array; 73 String _GODOT_method_name = String("_setup_local_to_scene"); 74 this.callv(_GODOT_method_name, _GODOT_args); 75 } 76 /** 77 78 */ 79 void setPath(StringArg0)(in StringArg0 path) 80 { 81 checkClassBinding!(typeof(this))(); 82 ptrcall!(void)(_classBinding.setPath, _godot_object, path); 83 } 84 /** 85 Set the path of the resource. Differs from set_path(), if another `Resource` exists with "path" it over-takes it, instead of failing. 86 */ 87 void takeOverPath(StringArg0)(in StringArg0 path) 88 { 89 checkClassBinding!(typeof(this))(); 90 ptrcall!(void)(_classBinding.takeOverPath, _godot_object, path); 91 } 92 /** 93 94 */ 95 String getPath() const 96 { 97 checkClassBinding!(typeof(this))(); 98 return ptrcall!(String)(_classBinding.getPath, _godot_object); 99 } 100 /** 101 102 */ 103 void setName(StringArg0)(in StringArg0 name) 104 { 105 checkClassBinding!(typeof(this))(); 106 ptrcall!(void)(_classBinding.setName, _godot_object, name); 107 } 108 /** 109 110 */ 111 String getName() const 112 { 113 checkClassBinding!(typeof(this))(); 114 return ptrcall!(String)(_classBinding.getName, _godot_object); 115 } 116 /** 117 Return the RID of the resource (or an empty RID). Many resources (such as $(D Texture), $(D Mesh), etc) are high level abstractions of resources stored in a server, so this function will return the original RID. 118 */ 119 RID getRid() const 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(RID)(_classBinding.getRid, _godot_object); 123 } 124 /** 125 126 */ 127 void setLocalToScene(in bool enable) 128 { 129 checkClassBinding!(typeof(this))(); 130 ptrcall!(void)(_classBinding.setLocalToScene, _godot_object, enable); 131 } 132 /** 133 134 */ 135 bool isLocalToScene() const 136 { 137 checkClassBinding!(typeof(this))(); 138 return ptrcall!(bool)(_classBinding.isLocalToScene, _godot_object); 139 } 140 /** 141 142 */ 143 Node getLocalScene() const 144 { 145 checkClassBinding!(typeof(this))(); 146 return ptrcall!(Node)(_classBinding.getLocalScene, _godot_object); 147 } 148 /** 149 150 */ 151 void setupLocalToScene() 152 { 153 checkClassBinding!(typeof(this))(); 154 ptrcall!(void)(_classBinding.setupLocalToScene, _godot_object); 155 } 156 /** 157 158 */ 159 Ref!Resource duplicate(in bool subresources = false) const 160 { 161 checkClassBinding!(typeof(this))(); 162 return ptrcall!(Resource)(_classBinding.duplicate, _godot_object, subresources); 163 } 164 /** 165 166 */ 167 @property bool resourceLocalToScene() 168 { 169 return isLocalToScene(); 170 } 171 /// ditto 172 @property void resourceLocalToScene(bool v) 173 { 174 setLocalToScene(v); 175 } 176 /** 177 178 */ 179 @property String resourcePath() 180 { 181 return getPath(); 182 } 183 /// ditto 184 @property void resourcePath(String v) 185 { 186 setPath(v); 187 } 188 /** 189 190 */ 191 @property String resourceName() 192 { 193 return getName(); 194 } 195 /// ditto 196 @property void resourceName(String v) 197 { 198 setName(v); 199 } 200 }