1 /**
2 Sprite frame library for AnimatedSprite.
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.spriteframes;
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.resource;
25 import godot.reference;
26 import godot.texture;
27 /**
28 Sprite frame library for AnimatedSprite.
29 
30 Sprite frame library for $(D AnimatedSprite). Contains frames and animation data for playback.
31 $(B Note:) You can associate a set of normal maps by creating additional $(D SpriteFrames) resources with a `_normal` suffix. For example, having 2 $(D SpriteFrames) resources `run` and `run_normal` will make it so the `run` animation uses the normal map.
32 */
33 @GodotBaseClass struct SpriteFrames
34 {
35 	package(godot) enum string _GODOT_internal_name = "SpriteFrames";
36 public:
37 @nogc nothrow:
38 	union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; }
39 	alias _GODOT_base this;
40 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
41 	package(godot) __gshared bool _classBindingInitialized = false;
42 	package(godot) static struct GDNativeClassBinding
43 	{
44 		__gshared:
45 		@GodotName("_get_animations") GodotMethod!(Array) _getAnimations;
46 		@GodotName("_get_frames") GodotMethod!(Array) _getFrames;
47 		@GodotName("_set_animations") GodotMethod!(void, Array) _setAnimations;
48 		@GodotName("_set_frames") GodotMethod!(void, Array) _setFrames;
49 		@GodotName("add_animation") GodotMethod!(void, String) addAnimation;
50 		@GodotName("add_frame") GodotMethod!(void, String, Texture, long) addFrame;
51 		@GodotName("clear") GodotMethod!(void, String) clear;
52 		@GodotName("clear_all") GodotMethod!(void) clearAll;
53 		@GodotName("get_animation_loop") GodotMethod!(bool, String) getAnimationLoop;
54 		@GodotName("get_animation_names") GodotMethod!(PoolStringArray) getAnimationNames;
55 		@GodotName("get_animation_speed") GodotMethod!(double, String) getAnimationSpeed;
56 		@GodotName("get_frame") GodotMethod!(Texture, String, long) getFrame;
57 		@GodotName("get_frame_count") GodotMethod!(long, String) getFrameCount;
58 		@GodotName("has_animation") GodotMethod!(bool, String) hasAnimation;
59 		@GodotName("remove_animation") GodotMethod!(void, String) removeAnimation;
60 		@GodotName("remove_frame") GodotMethod!(void, String, long) removeFrame;
61 		@GodotName("rename_animation") GodotMethod!(void, String, String) renameAnimation;
62 		@GodotName("set_animation_loop") GodotMethod!(void, String, bool) setAnimationLoop;
63 		@GodotName("set_animation_speed") GodotMethod!(void, String, double) setAnimationSpeed;
64 		@GodotName("set_frame") GodotMethod!(void, String, long, Texture) setFrame;
65 	}
66 	/// 
67 	pragma(inline, true) bool opEquals(in SpriteFrames other) const
68 	{ return _godot_object.ptr is other._godot_object.ptr; }
69 	/// 
70 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
71 	{ _godot_object.ptr = n; return null; }
72 	/// 
73 	pragma(inline, true) bool opEquals(typeof(null) n) const
74 	{ return _godot_object.ptr is n; }
75 	/// 
76 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
77 	mixin baseCasts;
78 	/// Construct a new instance of SpriteFrames.
79 	/// Note: use `memnew!SpriteFrames` instead.
80 	static SpriteFrames _new()
81 	{
82 		static godot_class_constructor constructor;
83 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("SpriteFrames");
84 		if(constructor is null) return typeof(this).init;
85 		return cast(SpriteFrames)(constructor());
86 	}
87 	@disable new(size_t s);
88 	/**
89 	
90 	*/
91 	Array _getAnimations() const
92 	{
93 		Array _GODOT_args = Array.make();
94 		String _GODOT_method_name = String("_get_animations");
95 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
96 	}
97 	/**
98 	
99 	*/
100 	Array _getFrames() const
101 	{
102 		Array _GODOT_args = Array.make();
103 		String _GODOT_method_name = String("_get_frames");
104 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
105 	}
106 	/**
107 	
108 	*/
109 	void _setAnimations(in Array arg0)
110 	{
111 		Array _GODOT_args = Array.make();
112 		_GODOT_args.append(arg0);
113 		String _GODOT_method_name = String("_set_animations");
114 		this.callv(_GODOT_method_name, _GODOT_args);
115 	}
116 	/**
117 	
118 	*/
119 	void _setFrames(in Array arg0)
120 	{
121 		Array _GODOT_args = Array.make();
122 		_GODOT_args.append(arg0);
123 		String _GODOT_method_name = String("_set_frames");
124 		this.callv(_GODOT_method_name, _GODOT_args);
125 	}
126 	/**
127 	Adds a new animation to the library.
128 	*/
129 	void addAnimation(in String anim)
130 	{
131 		checkClassBinding!(typeof(this))();
132 		ptrcall!(void)(GDNativeClassBinding.addAnimation, _godot_object, anim);
133 	}
134 	/**
135 	Adds a frame to the given animation.
136 	*/
137 	void addFrame(in String anim, Texture frame, in long at_position = -1)
138 	{
139 		checkClassBinding!(typeof(this))();
140 		ptrcall!(void)(GDNativeClassBinding.addFrame, _godot_object, anim, frame, at_position);
141 	}
142 	/**
143 	Removes all frames from the given animation.
144 	*/
145 	void clear(in String anim)
146 	{
147 		checkClassBinding!(typeof(this))();
148 		ptrcall!(void)(GDNativeClassBinding.clear, _godot_object, anim);
149 	}
150 	/**
151 	Removes all animations. A "default" animation will be created.
152 	*/
153 	void clearAll()
154 	{
155 		checkClassBinding!(typeof(this))();
156 		ptrcall!(void)(GDNativeClassBinding.clearAll, _godot_object);
157 	}
158 	/**
159 	Returns `true` if the given animation is configured to loop when it finishes playing. Otherwise, returns `false`.
160 	*/
161 	bool getAnimationLoop(in String anim) const
162 	{
163 		checkClassBinding!(typeof(this))();
164 		return ptrcall!(bool)(GDNativeClassBinding.getAnimationLoop, _godot_object, anim);
165 	}
166 	/**
167 	Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
168 	*/
169 	PoolStringArray getAnimationNames() const
170 	{
171 		checkClassBinding!(typeof(this))();
172 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.getAnimationNames, _godot_object);
173 	}
174 	/**
175 	The animation's speed in frames per second.
176 	*/
177 	double getAnimationSpeed(in String anim) const
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(double)(GDNativeClassBinding.getAnimationSpeed, _godot_object, anim);
181 	}
182 	/**
183 	Returns the animation's selected frame.
184 	*/
185 	Ref!Texture getFrame(in String anim, in long idx) const
186 	{
187 		checkClassBinding!(typeof(this))();
188 		return ptrcall!(Texture)(GDNativeClassBinding.getFrame, _godot_object, anim, idx);
189 	}
190 	/**
191 	Returns the number of frames in the animation.
192 	*/
193 	long getFrameCount(in String anim) const
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(long)(GDNativeClassBinding.getFrameCount, _godot_object, anim);
197 	}
198 	/**
199 	If `true`, the named animation exists.
200 	*/
201 	bool hasAnimation(in String anim) const
202 	{
203 		checkClassBinding!(typeof(this))();
204 		return ptrcall!(bool)(GDNativeClassBinding.hasAnimation, _godot_object, anim);
205 	}
206 	/**
207 	Removes the given animation.
208 	*/
209 	void removeAnimation(in String anim)
210 	{
211 		checkClassBinding!(typeof(this))();
212 		ptrcall!(void)(GDNativeClassBinding.removeAnimation, _godot_object, anim);
213 	}
214 	/**
215 	Removes the animation's selected frame.
216 	*/
217 	void removeFrame(in String anim, in long idx)
218 	{
219 		checkClassBinding!(typeof(this))();
220 		ptrcall!(void)(GDNativeClassBinding.removeFrame, _godot_object, anim, idx);
221 	}
222 	/**
223 	Changes the animation's name to `newname`.
224 	*/
225 	void renameAnimation(in String anim, in String newname)
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(GDNativeClassBinding.renameAnimation, _godot_object, anim, newname);
229 	}
230 	/**
231 	If `true`, the animation will loop.
232 	*/
233 	void setAnimationLoop(in String anim, in bool loop)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(GDNativeClassBinding.setAnimationLoop, _godot_object, anim, loop);
237 	}
238 	/**
239 	The animation's speed in frames per second.
240 	*/
241 	void setAnimationSpeed(in String anim, in double speed)
242 	{
243 		checkClassBinding!(typeof(this))();
244 		ptrcall!(void)(GDNativeClassBinding.setAnimationSpeed, _godot_object, anim, speed);
245 	}
246 	/**
247 	Sets the texture of the given frame.
248 	*/
249 	void setFrame(in String anim, in long idx, Texture txt)
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(GDNativeClassBinding.setFrame, _godot_object, anim, idx, txt);
253 	}
254 	/**
255 	
256 	*/
257 	@property Array animations()
258 	{
259 		return _getAnimations();
260 	}
261 	/// ditto
262 	@property void animations(Array v)
263 	{
264 		_setAnimations(v);
265 	}
266 	/**
267 	Compatibility property, always equals to an empty array.
268 	*/
269 	@property Array frames()
270 	{
271 		return _getFrames();
272 	}
273 	/// ditto
274 	@property void frames(Array v)
275 	{
276 		_setFrames(v);
277 	}
278 }