1 /**
2 Sprite node that can use multiple textures for animation.
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.animatedsprite;
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.node2d;
25 import godot.spriteframes;
26 /**
27 Sprite node that can use multiple textures for animation.
28 
29 Animations are created using a $(D SpriteFrames) resource, which can be configured in the editor via the SpriteFrames panel.
30 $(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.
31 */
32 @GodotBaseClass struct AnimatedSprite
33 {
34 	package(godot) enum string _GODOT_internal_name = "AnimatedSprite";
35 public:
36 @nogc nothrow:
37 	union { /** */ godot_object _godot_object; /** */ Node2D _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("_is_playing") GodotMethod!(bool) _isPlaying;
45 		@GodotName("_res_changed") GodotMethod!(void) _resChanged;
46 		@GodotName("_set_playing") GodotMethod!(void, bool) _setPlaying;
47 		@GodotName("get_animation") GodotMethod!(String) getAnimation;
48 		@GodotName("get_frame") GodotMethod!(long) getFrame;
49 		@GodotName("get_offset") GodotMethod!(Vector2) getOffset;
50 		@GodotName("get_speed_scale") GodotMethod!(double) getSpeedScale;
51 		@GodotName("get_sprite_frames") GodotMethod!(SpriteFrames) getSpriteFrames;
52 		@GodotName("is_centered") GodotMethod!(bool) isCentered;
53 		@GodotName("is_flipped_h") GodotMethod!(bool) isFlippedH;
54 		@GodotName("is_flipped_v") GodotMethod!(bool) isFlippedV;
55 		@GodotName("is_playing") GodotMethod!(bool) isPlaying;
56 		@GodotName("play") GodotMethod!(void, String, bool) play;
57 		@GodotName("set_animation") GodotMethod!(void, String) setAnimation;
58 		@GodotName("set_centered") GodotMethod!(void, bool) setCentered;
59 		@GodotName("set_flip_h") GodotMethod!(void, bool) setFlipH;
60 		@GodotName("set_flip_v") GodotMethod!(void, bool) setFlipV;
61 		@GodotName("set_frame") GodotMethod!(void, long) setFrame;
62 		@GodotName("set_offset") GodotMethod!(void, Vector2) setOffset;
63 		@GodotName("set_speed_scale") GodotMethod!(void, double) setSpeedScale;
64 		@GodotName("set_sprite_frames") GodotMethod!(void, SpriteFrames) setSpriteFrames;
65 		@GodotName("stop") GodotMethod!(void) stop;
66 	}
67 	/// 
68 	pragma(inline, true) bool opEquals(in AnimatedSprite other) const
69 	{ return _godot_object.ptr is other._godot_object.ptr; }
70 	/// 
71 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
72 	{ _godot_object.ptr = n; return null; }
73 	/// 
74 	pragma(inline, true) bool opEquals(typeof(null) n) const
75 	{ return _godot_object.ptr is n; }
76 	/// 
77 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
78 	mixin baseCasts;
79 	/// Construct a new instance of AnimatedSprite.
80 	/// Note: use `memnew!AnimatedSprite` instead.
81 	static AnimatedSprite _new()
82 	{
83 		static godot_class_constructor constructor;
84 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AnimatedSprite");
85 		if(constructor is null) return typeof(this).init;
86 		return cast(AnimatedSprite)(constructor());
87 	}
88 	@disable new(size_t s);
89 	/**
90 	
91 	*/
92 	bool _isPlaying() const
93 	{
94 		Array _GODOT_args = Array.make();
95 		String _GODOT_method_name = String("_is_playing");
96 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
97 	}
98 	/**
99 	
100 	*/
101 	void _resChanged()
102 	{
103 		Array _GODOT_args = Array.make();
104 		String _GODOT_method_name = String("_res_changed");
105 		this.callv(_GODOT_method_name, _GODOT_args);
106 	}
107 	/**
108 	
109 	*/
110 	void _setPlaying(in bool playing)
111 	{
112 		Array _GODOT_args = Array.make();
113 		_GODOT_args.append(playing);
114 		String _GODOT_method_name = String("_set_playing");
115 		this.callv(_GODOT_method_name, _GODOT_args);
116 	}
117 	/**
118 	
119 	*/
120 	String getAnimation() const
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(String)(GDNativeClassBinding.getAnimation, _godot_object);
124 	}
125 	/**
126 	
127 	*/
128 	long getFrame() const
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(long)(GDNativeClassBinding.getFrame, _godot_object);
132 	}
133 	/**
134 	
135 	*/
136 	Vector2 getOffset() const
137 	{
138 		checkClassBinding!(typeof(this))();
139 		return ptrcall!(Vector2)(GDNativeClassBinding.getOffset, _godot_object);
140 	}
141 	/**
142 	
143 	*/
144 	double getSpeedScale() const
145 	{
146 		checkClassBinding!(typeof(this))();
147 		return ptrcall!(double)(GDNativeClassBinding.getSpeedScale, _godot_object);
148 	}
149 	/**
150 	
151 	*/
152 	Ref!SpriteFrames getSpriteFrames() const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(SpriteFrames)(GDNativeClassBinding.getSpriteFrames, _godot_object);
156 	}
157 	/**
158 	
159 	*/
160 	bool isCentered() const
161 	{
162 		checkClassBinding!(typeof(this))();
163 		return ptrcall!(bool)(GDNativeClassBinding.isCentered, _godot_object);
164 	}
165 	/**
166 	
167 	*/
168 	bool isFlippedH() const
169 	{
170 		checkClassBinding!(typeof(this))();
171 		return ptrcall!(bool)(GDNativeClassBinding.isFlippedH, _godot_object);
172 	}
173 	/**
174 	
175 	*/
176 	bool isFlippedV() const
177 	{
178 		checkClassBinding!(typeof(this))();
179 		return ptrcall!(bool)(GDNativeClassBinding.isFlippedV, _godot_object);
180 	}
181 	/**
182 	Returns `true` if an animation is currently being played.
183 	*/
184 	bool isPlaying() const
185 	{
186 		checkClassBinding!(typeof(this))();
187 		return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object);
188 	}
189 	/**
190 	Plays the animation named `anim`. If no `anim` is provided, the current animation is played. If `backwards` is `true`, the animation will be played in reverse.
191 	*/
192 	void play(in String anim = gs!"", in bool backwards = false)
193 	{
194 		checkClassBinding!(typeof(this))();
195 		ptrcall!(void)(GDNativeClassBinding.play, _godot_object, anim, backwards);
196 	}
197 	/**
198 	
199 	*/
200 	void setAnimation(in String animation)
201 	{
202 		checkClassBinding!(typeof(this))();
203 		ptrcall!(void)(GDNativeClassBinding.setAnimation, _godot_object, animation);
204 	}
205 	/**
206 	
207 	*/
208 	void setCentered(in bool centered)
209 	{
210 		checkClassBinding!(typeof(this))();
211 		ptrcall!(void)(GDNativeClassBinding.setCentered, _godot_object, centered);
212 	}
213 	/**
214 	
215 	*/
216 	void setFlipH(in bool flip_h)
217 	{
218 		checkClassBinding!(typeof(this))();
219 		ptrcall!(void)(GDNativeClassBinding.setFlipH, _godot_object, flip_h);
220 	}
221 	/**
222 	
223 	*/
224 	void setFlipV(in bool flip_v)
225 	{
226 		checkClassBinding!(typeof(this))();
227 		ptrcall!(void)(GDNativeClassBinding.setFlipV, _godot_object, flip_v);
228 	}
229 	/**
230 	
231 	*/
232 	void setFrame(in long frame)
233 	{
234 		checkClassBinding!(typeof(this))();
235 		ptrcall!(void)(GDNativeClassBinding.setFrame, _godot_object, frame);
236 	}
237 	/**
238 	
239 	*/
240 	void setOffset(in Vector2 offset)
241 	{
242 		checkClassBinding!(typeof(this))();
243 		ptrcall!(void)(GDNativeClassBinding.setOffset, _godot_object, offset);
244 	}
245 	/**
246 	
247 	*/
248 	void setSpeedScale(in double speed_scale)
249 	{
250 		checkClassBinding!(typeof(this))();
251 		ptrcall!(void)(GDNativeClassBinding.setSpeedScale, _godot_object, speed_scale);
252 	}
253 	/**
254 	
255 	*/
256 	void setSpriteFrames(SpriteFrames sprite_frames)
257 	{
258 		checkClassBinding!(typeof(this))();
259 		ptrcall!(void)(GDNativeClassBinding.setSpriteFrames, _godot_object, sprite_frames);
260 	}
261 	/**
262 	Stops the current animation (does not reset the frame counter).
263 	*/
264 	void stop()
265 	{
266 		checkClassBinding!(typeof(this))();
267 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
268 	}
269 	/**
270 	The current animation from the `frames` resource. If this value changes, the `frame` counter is reset.
271 	*/
272 	@property String animation()
273 	{
274 		return getAnimation();
275 	}
276 	/// ditto
277 	@property void animation(String v)
278 	{
279 		setAnimation(v);
280 	}
281 	/**
282 	If `true`, texture will be centered.
283 	*/
284 	@property bool centered()
285 	{
286 		return isCentered();
287 	}
288 	/// ditto
289 	@property void centered(bool v)
290 	{
291 		setCentered(v);
292 	}
293 	/**
294 	If `true`, texture is flipped horizontally.
295 	*/
296 	@property bool flipH()
297 	{
298 		return isFlippedH();
299 	}
300 	/// ditto
301 	@property void flipH(bool v)
302 	{
303 		setFlipH(v);
304 	}
305 	/**
306 	If `true`, texture is flipped vertically.
307 	*/
308 	@property bool flipV()
309 	{
310 		return isFlippedV();
311 	}
312 	/// ditto
313 	@property void flipV(bool v)
314 	{
315 		setFlipV(v);
316 	}
317 	/**
318 	The displayed animation frame's index.
319 	*/
320 	@property long frame()
321 	{
322 		return getFrame();
323 	}
324 	/// ditto
325 	@property void frame(long v)
326 	{
327 		setFrame(v);
328 	}
329 	/**
330 	The $(D SpriteFrames) resource containing the animation(s).
331 	*/
332 	@property SpriteFrames frames()
333 	{
334 		return getSpriteFrames();
335 	}
336 	/// ditto
337 	@property void frames(SpriteFrames v)
338 	{
339 		setSpriteFrames(v);
340 	}
341 	/**
342 	The texture's drawing offset.
343 	*/
344 	@property Vector2 offset()
345 	{
346 		return getOffset();
347 	}
348 	/// ditto
349 	@property void offset(Vector2 v)
350 	{
351 		setOffset(v);
352 	}
353 	/**
354 	If `true`, the $(D animation) is currently playing.
355 	*/
356 	@property bool playing()
357 	{
358 		return _isPlaying();
359 	}
360 	/// ditto
361 	@property void playing(bool v)
362 	{
363 		_setPlaying(v);
364 	}
365 	/**
366 	The animation speed is multiplied by this value.
367 	*/
368 	@property double speedScale()
369 	{
370 		return getSpeedScale();
371 	}
372 	/// ditto
373 	@property void speedScale(double v)
374 	{
375 		setSpeedScale(v);
376 	}
377 }