1 /**
2 Singleton for saving Godot-specific resource types.
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.resourcesaver;
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.resource;
24 /**
25 Singleton for saving Godot-specific resource types.
26 
27 Singleton for saving Godot-specific resource types to the filesystem.
28 It uses the many $(D ResourceFormatSaver) classes registered in the engine (either built-in or from a plugin) to save engine-specific resource data to text-based (e.g. `.tres` or `.tscn`) or binary files (e.g. `.res` or `.scn`).
29 */
30 @GodotBaseClass struct ResourceSaverSingleton
31 {
32 	package(godot) enum string _GODOT_internal_name = "_ResourceSaver";
33 public:
34 @nogc nothrow:
35 	union { /** */ godot_object _godot_object; /** */ GodotObject _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 GDNativeClassBinding
40 	{
41 		__gshared:
42 		godot_object _singleton;
43 		immutable char* _singletonName = "ResourceSaver";
44 		@GodotName("get_recognized_extensions") GodotMethod!(PoolStringArray, Resource) getRecognizedExtensions;
45 		@GodotName("save") GodotMethod!(GodotError, String, Resource, long) save;
46 	}
47 	/// 
48 	pragma(inline, true) bool opEquals(in ResourceSaverSingleton other) const
49 	{ return _godot_object.ptr is other._godot_object.ptr; }
50 	/// 
51 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
52 	{ _godot_object.ptr = n; return null; }
53 	/// 
54 	pragma(inline, true) bool opEquals(typeof(null) n) const
55 	{ return _godot_object.ptr is n; }
56 	/// 
57 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
58 	mixin baseCasts;
59 	/// Construct a new instance of ResourceSaverSingleton.
60 	/// Note: use `memnew!ResourceSaverSingleton` instead.
61 	static ResourceSaverSingleton _new()
62 	{
63 		static godot_class_constructor constructor;
64 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_ResourceSaver");
65 		if(constructor is null) return typeof(this).init;
66 		return cast(ResourceSaverSingleton)(constructor());
67 	}
68 	@disable new(size_t s);
69 	/// 
70 	enum SaverFlags : int
71 	{
72 		/**
73 		Save the resource with a path relative to the scene which uses it.
74 		*/
75 		flagRelativePaths = 1,
76 		/**
77 		Bundles external resources.
78 		*/
79 		flagBundleResources = 2,
80 		/**
81 		Changes the $(D Resource.resourcePath) of the saved resource to match its new location.
82 		*/
83 		flagChangePath = 4,
84 		/**
85 		Do not save editor-specific metadata (identified by their `__editor` prefix).
86 		*/
87 		flagOmitEditorProperties = 8,
88 		/**
89 		Save as big endian (see $(D File.endianSwap)).
90 		*/
91 		flagSaveBigEndian = 16,
92 		/**
93 		Compress the resource on save using $(D constant File.COMPRESSION_ZSTD). Only available for binary resource types.
94 		*/
95 		flagCompress = 32,
96 		/**
97 		Take over the paths of the saved subresources (see $(D Resource.takeOverPath)).
98 		*/
99 		flagReplaceSubresourcePaths = 64,
100 	}
101 	/// 
102 	enum Constants : int
103 	{
104 		flagRelativePaths = 1,
105 		flagBundleResources = 2,
106 		flagChangePath = 4,
107 		flagOmitEditorProperties = 8,
108 		flagSaveBigEndian = 16,
109 		flagCompress = 32,
110 		flagReplaceSubresourcePaths = 64,
111 	}
112 	/**
113 	Returns the list of extensions available for saving a resource of a given type.
114 	*/
115 	PoolStringArray getRecognizedExtensions(Resource type)
116 	{
117 		checkClassBinding!(typeof(this))();
118 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.getRecognizedExtensions, _godot_object, type);
119 	}
120 	/**
121 	Saves a resource to disk to the given path, using a $(D ResourceFormatSaver) that recognizes the resource object.
122 	The `flags` bitmask can be specified to customize the save behavior.
123 	Returns $(D constant OK) on success.
124 	*/
125 	GodotError save(in String path, Resource resource, in long flags = 0)
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(GodotError)(GDNativeClassBinding.save, _godot_object, path, resource, flags);
129 	}
130 }
131 /// Returns: the ResourceSaverSingleton
132 @property @nogc nothrow pragma(inline, true)
133 ResourceSaverSingleton ResourceSaver()
134 {
135 	checkClassBinding!ResourceSaverSingleton();
136 	return ResourceSaverSingleton(ResourceSaverSingleton.GDNativeClassBinding._singleton);
137 }