1 /** 2 Resource Preloader Node. 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.resourcepreloader; 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 import godot.classdb; 24 import godot.node; 25 import godot.resource; 26 /** 27 Resource Preloader Node. 28 29 This node is used to preload sub-resources inside a scene, so when the scene is loaded, all the resources are ready to use and can be retrieved from the preloader. 30 GDScript has a simplified $(D @GDScript.preload) built-in method which can be used in most situations, leaving the use of $(D ResourcePreloader) for more advanced scenarios. 31 */ 32 @GodotBaseClass struct ResourcePreloader 33 { 34 package(godot) enum string _GODOT_internal_name = "ResourcePreloader"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Node _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("_get_resources") GodotMethod!(Array) _getResources; 45 @GodotName("_set_resources") GodotMethod!(void, Array) _setResources; 46 @GodotName("add_resource") GodotMethod!(void, String, Resource) addResource; 47 @GodotName("get_resource") GodotMethod!(Resource, String) getResource; 48 @GodotName("get_resource_list") GodotMethod!(PoolStringArray) getResourceList; 49 @GodotName("has_resource") GodotMethod!(bool, String) hasResource; 50 @GodotName("remove_resource") GodotMethod!(void, String) removeResource; 51 @GodotName("rename_resource") GodotMethod!(void, String, String) renameResource; 52 } 53 /// 54 pragma(inline, true) bool opEquals(in ResourcePreloader other) const 55 { return _godot_object.ptr is other._godot_object.ptr; } 56 /// 57 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 58 { _godot_object.ptr = n; return null; } 59 /// 60 pragma(inline, true) bool opEquals(typeof(null) n) const 61 { return _godot_object.ptr is n; } 62 /// 63 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 64 mixin baseCasts; 65 /// Construct a new instance of ResourcePreloader. 66 /// Note: use `memnew!ResourcePreloader` instead. 67 static ResourcePreloader _new() 68 { 69 static godot_class_constructor constructor; 70 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ResourcePreloader"); 71 if(constructor is null) return typeof(this).init; 72 return cast(ResourcePreloader)(constructor()); 73 } 74 @disable new(size_t s); 75 /** 76 77 */ 78 Array _getResources() const 79 { 80 Array _GODOT_args = Array.make(); 81 String _GODOT_method_name = String("_get_resources"); 82 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 83 } 84 /** 85 86 */ 87 void _setResources(in Array arg0) 88 { 89 Array _GODOT_args = Array.make(); 90 _GODOT_args.append(arg0); 91 String _GODOT_method_name = String("_set_resources"); 92 this.callv(_GODOT_method_name, _GODOT_args); 93 } 94 /** 95 Adds a resource to the preloader with the given `name`. If a resource with the given `name` already exists, the new resource will be renamed to "`name` N" where N is an incrementing number starting from 2. 96 */ 97 void addResource(in String name, Resource resource) 98 { 99 checkClassBinding!(typeof(this))(); 100 ptrcall!(void)(GDNativeClassBinding.addResource, _godot_object, name, resource); 101 } 102 /** 103 Returns the resource associated to `name`. 104 */ 105 Ref!Resource getResource(in String name) const 106 { 107 checkClassBinding!(typeof(this))(); 108 return ptrcall!(Resource)(GDNativeClassBinding.getResource, _godot_object, name); 109 } 110 /** 111 Returns the list of resources inside the preloader. 112 */ 113 PoolStringArray getResourceList() const 114 { 115 checkClassBinding!(typeof(this))(); 116 return ptrcall!(PoolStringArray)(GDNativeClassBinding.getResourceList, _godot_object); 117 } 118 /** 119 Returns `true` if the preloader contains a resource associated to `name`. 120 */ 121 bool hasResource(in String name) const 122 { 123 checkClassBinding!(typeof(this))(); 124 return ptrcall!(bool)(GDNativeClassBinding.hasResource, _godot_object, name); 125 } 126 /** 127 Removes the resource associated to `name` from the preloader. 128 */ 129 void removeResource(in String name) 130 { 131 checkClassBinding!(typeof(this))(); 132 ptrcall!(void)(GDNativeClassBinding.removeResource, _godot_object, name); 133 } 134 /** 135 Renames a resource inside the preloader from `name` to `newname`. 136 */ 137 void renameResource(in String name, in String newname) 138 { 139 checkClassBinding!(typeof(this))(); 140 ptrcall!(void)(GDNativeClassBinding.renameResource, _godot_object, name, newname); 141 } 142 /** 143 144 */ 145 @property Array resources() 146 { 147 return _getResources(); 148 } 149 /// ditto 150 @property void resources(Array v) 151 { 152 _setResources(v); 153 } 154 }