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