1 /** 2 Resource Loader. 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.resourceloader; 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.resourceinteractiveloader; 23 import godot.resource; 24 /** 25 Resource Loader. 26 27 This is a static object accessible as `ResourceLoader`. GDScript has a simplified load() function, though. 28 */ 29 @GodotBaseClass struct ResourceLoaderSingleton 30 { 31 enum string _GODOT_internal_name = "_ResourceLoader"; 32 public: 33 @nogc nothrow: 34 union { godot_object _godot_object; GodotObject _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct _classBinding 39 { 40 __gshared: 41 godot_object _singleton; 42 immutable char* _singletonName = "ResourceLoader"; 43 @GodotName("load_interactive") GodotMethod!(ResourceInteractiveLoader, String, String) loadInteractive; 44 @GodotName("load") GodotMethod!(Resource, String, String, bool) load; 45 @GodotName("get_recognized_extensions_for_type") GodotMethod!(PoolStringArray, String) getRecognizedExtensionsForType; 46 @GodotName("set_abort_on_missing_resources") GodotMethod!(void, bool) setAbortOnMissingResources; 47 @GodotName("get_dependencies") GodotMethod!(PoolStringArray, String) getDependencies; 48 @GodotName("has_cached") GodotMethod!(bool, String) hasCached; 49 @GodotName("exists") GodotMethod!(bool, String, String) exists; 50 @GodotName("has") GodotMethod!(bool, String) has; 51 } 52 bool opEquals(in ResourceLoaderSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; } 53 ResourceLoaderSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 54 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 55 mixin baseCasts; 56 static ResourceLoaderSingleton _new() 57 { 58 static godot_class_constructor constructor; 59 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_ResourceLoader"); 60 if(constructor is null) return typeof(this).init; 61 return cast(ResourceLoaderSingleton)(constructor()); 62 } 63 @disable new(size_t s); 64 /** 65 Load a resource interactively, the returned object allows to load with high granularity. 66 */ 67 Ref!ResourceInteractiveLoader loadInteractive(StringArg0, StringArg1)(in StringArg0 path, in StringArg1 type_hint = "") 68 { 69 checkClassBinding!(typeof(this))(); 70 return ptrcall!(ResourceInteractiveLoader)(_classBinding.loadInteractive, _godot_object, path, type_hint); 71 } 72 /** 73 74 */ 75 Ref!Resource load(StringArg0, StringArg1)(in StringArg0 path, in StringArg1 type_hint = "", in bool p_no_cache = false) 76 { 77 checkClassBinding!(typeof(this))(); 78 return ptrcall!(Resource)(_classBinding.load, _godot_object, path, type_hint, p_no_cache); 79 } 80 /** 81 Return the list of recognized extensions for a resource type. 82 */ 83 PoolStringArray getRecognizedExtensionsForType(StringArg0)(in StringArg0 type) 84 { 85 checkClassBinding!(typeof(this))(); 86 return ptrcall!(PoolStringArray)(_classBinding.getRecognizedExtensionsForType, _godot_object, type); 87 } 88 /** 89 Change the behavior on missing sub-resources. Default is to abort load. 90 */ 91 void setAbortOnMissingResources(in bool abort) 92 { 93 checkClassBinding!(typeof(this))(); 94 ptrcall!(void)(_classBinding.setAbortOnMissingResources, _godot_object, abort); 95 } 96 /** 97 98 */ 99 PoolStringArray getDependencies(StringArg0)(in StringArg0 path) 100 { 101 checkClassBinding!(typeof(this))(); 102 return ptrcall!(PoolStringArray)(_classBinding.getDependencies, _godot_object, path); 103 } 104 /** 105 106 */ 107 bool hasCached(StringArg0)(in StringArg0 path) 108 { 109 checkClassBinding!(typeof(this))(); 110 return ptrcall!(bool)(_classBinding.hasCached, _godot_object, path); 111 } 112 /** 113 114 */ 115 bool exists(StringArg0, StringArg1)(in StringArg0 path, in StringArg1 type_hint = "") 116 { 117 checkClassBinding!(typeof(this))(); 118 return ptrcall!(bool)(_classBinding.exists, _godot_object, path, type_hint); 119 } 120 /** 121 122 */ 123 bool has(StringArg0)(in StringArg0 path) 124 { 125 checkClassBinding!(typeof(this))(); 126 return ptrcall!(bool)(_classBinding.has, _godot_object, path); 127 } 128 } 129 /// Returns: the ResourceLoaderSingleton 130 @property @nogc nothrow pragma(inline, true) 131 ResourceLoaderSingleton ResourceLoader() 132 { 133 checkClassBinding!ResourceLoaderSingleton(); 134 return ResourceLoaderSingleton(ResourceLoaderSingleton._classBinding._singleton); 135 }