1 /**
2 Loads a specific resource type from a file.
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.resourceformatloader;
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.reference;
25 /**
26 Loads a specific resource type from a file.
27 
28 Godot loads resources in the editor or in exported games using ResourceFormatLoaders. They are queried automatically via the $(D ResourceLoader) singleton, or when a resource with internal dependencies is loaded. Each file type may load as a different resource type, so multiple ResourceFormatLoaders are registered in the engine.
29 Extending this class allows you to define your own loader. Be sure to respect the documented return types and values. You should give it a global class name with `class_name` for it to be registered. Like built-in ResourceFormatLoaders, it will be called automatically when loading resources of its handled type(s). You may also implement a $(D ResourceFormatSaver).
30 $(B Note:) You can also extend $(D EditorImportPlugin) if the resource type you need exists but Godot is unable to load its format. Choosing one way over another depends on if the format is suitable or not for the final exported game. For example, it's better to import `.png` textures as `.stex` ($(D StreamTexture)) first, so they can be loaded with better efficiency on the graphics card.
31 */
32 @GodotBaseClass struct ResourceFormatLoader
33 {
34 	package(godot) enum string _GODOT_internal_name = "ResourceFormatLoader";
35 public:
36 @nogc nothrow:
37 	union { /** */ godot_object _godot_object; /** */ Reference _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_dependencies") GodotMethod!(void, String, String) getDependencies;
45 		@GodotName("get_recognized_extensions") GodotMethod!(PoolStringArray) getRecognizedExtensions;
46 		@GodotName("get_resource_type") GodotMethod!(String, String) getResourceType;
47 		@GodotName("handles_type") GodotMethod!(bool, String) handlesType;
48 		@GodotName("load") GodotMethod!(Variant, String, String) load;
49 		@GodotName("rename_dependencies") GodotMethod!(long, String, String) renameDependencies;
50 	}
51 	/// 
52 	pragma(inline, true) bool opEquals(in ResourceFormatLoader other) const
53 	{ return _godot_object.ptr is other._godot_object.ptr; }
54 	/// 
55 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
56 	{ _godot_object.ptr = n; return null; }
57 	/// 
58 	pragma(inline, true) bool opEquals(typeof(null) n) const
59 	{ return _godot_object.ptr is n; }
60 	/// 
61 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
62 	mixin baseCasts;
63 	/// Construct a new instance of ResourceFormatLoader.
64 	/// Note: use `memnew!ResourceFormatLoader` instead.
65 	static ResourceFormatLoader _new()
66 	{
67 		static godot_class_constructor constructor;
68 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ResourceFormatLoader");
69 		if(constructor is null) return typeof(this).init;
70 		return cast(ResourceFormatLoader)(constructor());
71 	}
72 	@disable new(size_t s);
73 	/**
74 	If implemented, gets the dependencies of a given resource. If `add_types` is `true`, paths should be appended `::TypeName`, where `TypeName` is the class name of the dependency.
75 	$(B Note:) Custom resource types defined by scripts aren't known by the $(D ClassDB), so you might just return `"Resource"` for them.
76 	*/
77 	void getDependencies(in String path, in String add_types)
78 	{
79 		Array _GODOT_args = Array.make();
80 		_GODOT_args.append(path);
81 		_GODOT_args.append(add_types);
82 		String _GODOT_method_name = String("get_dependencies");
83 		this.callv(_GODOT_method_name, _GODOT_args);
84 	}
85 	/**
86 	Gets the list of extensions for files this loader is able to read.
87 	*/
88 	PoolStringArray getRecognizedExtensions()
89 	{
90 		Array _GODOT_args = Array.make();
91 		String _GODOT_method_name = String("get_recognized_extensions");
92 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!PoolStringArray);
93 	}
94 	/**
95 	Gets the class name of the resource associated with the given path. If the loader cannot handle it, it should return `""`.
96 	$(B Note:) Custom resource types defined by scripts aren't known by the $(D ClassDB), so you might just return `"Resource"` for them.
97 	*/
98 	String getResourceType(in String path)
99 	{
100 		Array _GODOT_args = Array.make();
101 		_GODOT_args.append(path);
102 		String _GODOT_method_name = String("get_resource_type");
103 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
104 	}
105 	/**
106 	Tells which resource class this loader can load.
107 	$(B Note:) Custom resource types defined by scripts aren't known by the $(D ClassDB), so you might just handle `"Resource"` for them.
108 	*/
109 	bool handlesType(in String typename)
110 	{
111 		Array _GODOT_args = Array.make();
112 		_GODOT_args.append(typename);
113 		String _GODOT_method_name = String("handles_type");
114 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
115 	}
116 	/**
117 	Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, `original_path` will target the source file. Returns a $(D Resource) object on success, or an $(D error) constant in case of failure.
118 	*/
119 	Variant load(in String path, in String original_path)
120 	{
121 		Array _GODOT_args = Array.make();
122 		_GODOT_args.append(path);
123 		_GODOT_args.append(original_path);
124 		String _GODOT_method_name = String("load");
125 		return this.callv(_GODOT_method_name, _GODOT_args);
126 	}
127 	/**
128 	If implemented, renames dependencies within the given resource and saves it. `renames` is a dictionary `{ String => String }` mapping old dependency paths to new paths.
129 	Returns $(D constant OK) on success, or an $(D error) constant in case of failure.
130 	*/
131 	long renameDependencies(in String path, in String renames)
132 	{
133 		Array _GODOT_args = Array.make();
134 		_GODOT_args.append(path);
135 		_GODOT_args.append(renames);
136 		String _GODOT_method_name = String("rename_dependencies");
137 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
138 	}
139 }