1 /**
2 Saves a specific resource type to 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.resourceformatsaver;
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 import godot.resource;
26 /**
27 Saves a specific resource type to a file.
28 
29 The engine can save resources when you do it from the editor, or when you use the $(D ResourceSaver) singleton. This is accomplished thanks to multiple $(D ResourceFormatSaver)s, each handling its own format and called automatically by the engine.
30 By default, Godot saves resources as `.tres` (text-based), `.res` (binary) or another built-in format, but you can choose to create your own format by extending this class. 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 ResourceFormatSavers, it will be called automatically when saving resources of its recognized type(s). You may also implement a $(D ResourceFormatLoader).
31 */
32 @GodotBaseClass struct ResourceFormatSaver
33 {
34 	package(godot) enum string _GODOT_internal_name = "ResourceFormatSaver";
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_recognized_extensions") GodotMethod!(PoolStringArray, Resource) getRecognizedExtensions;
45 		@GodotName("recognize") GodotMethod!(bool, Resource) recognize;
46 		@GodotName("save") GodotMethod!(long, String, Resource, long) save;
47 	}
48 	/// 
49 	pragma(inline, true) bool opEquals(in ResourceFormatSaver other) const
50 	{ return _godot_object.ptr is other._godot_object.ptr; }
51 	/// 
52 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
53 	{ _godot_object.ptr = n; return null; }
54 	/// 
55 	pragma(inline, true) bool opEquals(typeof(null) n) const
56 	{ return _godot_object.ptr is n; }
57 	/// 
58 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
59 	mixin baseCasts;
60 	/// Construct a new instance of ResourceFormatSaver.
61 	/// Note: use `memnew!ResourceFormatSaver` instead.
62 	static ResourceFormatSaver _new()
63 	{
64 		static godot_class_constructor constructor;
65 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ResourceFormatSaver");
66 		if(constructor is null) return typeof(this).init;
67 		return cast(ResourceFormatSaver)(constructor());
68 	}
69 	@disable new(size_t s);
70 	/**
71 	Returns the list of extensions available for saving the resource object, provided it is recognized (see $(D recognize)).
72 	*/
73 	PoolStringArray getRecognizedExtensions(Resource resource)
74 	{
75 		Array _GODOT_args = Array.make();
76 		_GODOT_args.append(resource);
77 		String _GODOT_method_name = String("get_recognized_extensions");
78 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!PoolStringArray);
79 	}
80 	/**
81 	Returns whether the given resource object can be saved by this saver.
82 	*/
83 	bool recognize(Resource resource)
84 	{
85 		Array _GODOT_args = Array.make();
86 		_GODOT_args.append(resource);
87 		String _GODOT_method_name = String("recognize");
88 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
89 	}
90 	/**
91 	Saves the given resource object to a file at the target `path`. `flags` is a bitmask composed with $(D ResourceSaver.saverflags) constants.
92 	Returns $(D constant OK) on success, or an $(D error) constant in case of failure.
93 	*/
94 	long save(in String path, Resource resource, in long flags)
95 	{
96 		Array _GODOT_args = Array.make();
97 		_GODOT_args.append(path);
98 		_GODOT_args.append(resource);
99 		_GODOT_args.append(flags);
100 		String _GODOT_method_name = String("save");
101 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
102 	}
103 }