1 /**
2 A countdown timer.
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.timer;
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.node;
25 /**
26 A countdown timer.
27 
28 Counts down a specified interval and emits a signal on reaching 0. Can be set to repeat or "one-shot" mode.
29 $(B Note:) To create a one-shot timer without instantiating a node, use $(D SceneTree.createTimer).
30 */
31 @GodotBaseClass struct Timer
32 {
33 	package(godot) enum string _GODOT_internal_name = "Timer";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Node _GODOT_base; }
37 	alias _GODOT_base this;
38 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
39 	package(godot) __gshared bool _classBindingInitialized = false;
40 	package(godot) static struct GDNativeClassBinding
41 	{
42 		__gshared:
43 		@GodotName("get_time_left") GodotMethod!(double) getTimeLeft;
44 		@GodotName("get_timer_process_mode") GodotMethod!(Timer.TimerProcessMode) getTimerProcessMode;
45 		@GodotName("get_wait_time") GodotMethod!(double) getWaitTime;
46 		@GodotName("has_autostart") GodotMethod!(bool) hasAutostart;
47 		@GodotName("is_one_shot") GodotMethod!(bool) isOneShot;
48 		@GodotName("is_paused") GodotMethod!(bool) isPaused;
49 		@GodotName("is_stopped") GodotMethod!(bool) isStopped;
50 		@GodotName("set_autostart") GodotMethod!(void, bool) setAutostart;
51 		@GodotName("set_one_shot") GodotMethod!(void, bool) setOneShot;
52 		@GodotName("set_paused") GodotMethod!(void, bool) setPaused;
53 		@GodotName("set_timer_process_mode") GodotMethod!(void, long) setTimerProcessMode;
54 		@GodotName("set_wait_time") GodotMethod!(void, double) setWaitTime;
55 		@GodotName("start") GodotMethod!(void, double) start;
56 		@GodotName("stop") GodotMethod!(void) stop;
57 	}
58 	/// 
59 	pragma(inline, true) bool opEquals(in Timer other) const
60 	{ return _godot_object.ptr is other._godot_object.ptr; }
61 	/// 
62 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
63 	{ _godot_object.ptr = n; return null; }
64 	/// 
65 	pragma(inline, true) bool opEquals(typeof(null) n) const
66 	{ return _godot_object.ptr is n; }
67 	/// 
68 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
69 	mixin baseCasts;
70 	/// Construct a new instance of Timer.
71 	/// Note: use `memnew!Timer` instead.
72 	static Timer _new()
73 	{
74 		static godot_class_constructor constructor;
75 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Timer");
76 		if(constructor is null) return typeof(this).init;
77 		return cast(Timer)(constructor());
78 	}
79 	@disable new(size_t s);
80 	/// 
81 	enum TimerProcessMode : int
82 	{
83 		/**
84 		Update the timer during the physics step at each frame (fixed framerate processing).
85 		*/
86 		timerProcessPhysics = 0,
87 		/**
88 		Update the timer during the idle time at each frame.
89 		*/
90 		timerProcessIdle = 1,
91 	}
92 	/// 
93 	enum Constants : int
94 	{
95 		timerProcessPhysics = 0,
96 		timerProcessIdle = 1,
97 	}
98 	/**
99 	
100 	*/
101 	double getTimeLeft() const
102 	{
103 		checkClassBinding!(typeof(this))();
104 		return ptrcall!(double)(GDNativeClassBinding.getTimeLeft, _godot_object);
105 	}
106 	/**
107 	
108 	*/
109 	Timer.TimerProcessMode getTimerProcessMode() const
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(Timer.TimerProcessMode)(GDNativeClassBinding.getTimerProcessMode, _godot_object);
113 	}
114 	/**
115 	
116 	*/
117 	double getWaitTime() const
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(double)(GDNativeClassBinding.getWaitTime, _godot_object);
121 	}
122 	/**
123 	
124 	*/
125 	bool hasAutostart() const
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(bool)(GDNativeClassBinding.hasAutostart, _godot_object);
129 	}
130 	/**
131 	
132 	*/
133 	bool isOneShot() const
134 	{
135 		checkClassBinding!(typeof(this))();
136 		return ptrcall!(bool)(GDNativeClassBinding.isOneShot, _godot_object);
137 	}
138 	/**
139 	
140 	*/
141 	bool isPaused() const
142 	{
143 		checkClassBinding!(typeof(this))();
144 		return ptrcall!(bool)(GDNativeClassBinding.isPaused, _godot_object);
145 	}
146 	/**
147 	Returns `true` if the timer is stopped.
148 	*/
149 	bool isStopped() const
150 	{
151 		checkClassBinding!(typeof(this))();
152 		return ptrcall!(bool)(GDNativeClassBinding.isStopped, _godot_object);
153 	}
154 	/**
155 	
156 	*/
157 	void setAutostart(in bool enable)
158 	{
159 		checkClassBinding!(typeof(this))();
160 		ptrcall!(void)(GDNativeClassBinding.setAutostart, _godot_object, enable);
161 	}
162 	/**
163 	
164 	*/
165 	void setOneShot(in bool enable)
166 	{
167 		checkClassBinding!(typeof(this))();
168 		ptrcall!(void)(GDNativeClassBinding.setOneShot, _godot_object, enable);
169 	}
170 	/**
171 	
172 	*/
173 	void setPaused(in bool paused)
174 	{
175 		checkClassBinding!(typeof(this))();
176 		ptrcall!(void)(GDNativeClassBinding.setPaused, _godot_object, paused);
177 	}
178 	/**
179 	
180 	*/
181 	void setTimerProcessMode(in long mode)
182 	{
183 		checkClassBinding!(typeof(this))();
184 		ptrcall!(void)(GDNativeClassBinding.setTimerProcessMode, _godot_object, mode);
185 	}
186 	/**
187 	
188 	*/
189 	void setWaitTime(in double time_sec)
190 	{
191 		checkClassBinding!(typeof(this))();
192 		ptrcall!(void)(GDNativeClassBinding.setWaitTime, _godot_object, time_sec);
193 	}
194 	/**
195 	Starts the timer. Sets `wait_time` to `time_sec` if `time_sec > 0`. This also resets the remaining time to `wait_time`.
196 	$(B Note:) this method will not resume a paused timer. See $(D paused).
197 	*/
198 	void start(in double time_sec = -1)
199 	{
200 		checkClassBinding!(typeof(this))();
201 		ptrcall!(void)(GDNativeClassBinding.start, _godot_object, time_sec);
202 	}
203 	/**
204 	Stops the timer.
205 	*/
206 	void stop()
207 	{
208 		checkClassBinding!(typeof(this))();
209 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
210 	}
211 	/**
212 	If `true`, the timer will automatically start when entering the scene tree.
213 	$(B Note:) This property is automatically set to `false` after the timer enters the scene tree and starts.
214 	*/
215 	@property bool autostart()
216 	{
217 		return hasAutostart();
218 	}
219 	/// ditto
220 	@property void autostart(bool v)
221 	{
222 		setAutostart(v);
223 	}
224 	/**
225 	If `true`, the timer will stop when reaching 0. If `false`, it will restart.
226 	*/
227 	@property bool oneShot()
228 	{
229 		return isOneShot();
230 	}
231 	/// ditto
232 	@property void oneShot(bool v)
233 	{
234 		setOneShot(v);
235 	}
236 	/**
237 	If `true`, the timer is paused and will not process until it is unpaused again, even if $(D start) is called.
238 	*/
239 	@property bool paused()
240 	{
241 		return isPaused();
242 	}
243 	/// ditto
244 	@property void paused(bool v)
245 	{
246 		setPaused(v);
247 	}
248 	/**
249 	Processing mode. See $(D timerprocessmode).
250 	*/
251 	@property Timer.TimerProcessMode processMode()
252 	{
253 		return getTimerProcessMode();
254 	}
255 	/// ditto
256 	@property void processMode(long v)
257 	{
258 		setTimerProcessMode(v);
259 	}
260 	/**
261 	The timer's remaining time in seconds. Returns 0 if the timer is inactive.
262 	$(B Note:) You cannot set this value. To change the timer's remaining time, use $(D start).
263 	*/
264 	@property double timeLeft()
265 	{
266 		return getTimeLeft();
267 	}
268 	/**
269 	Wait time in seconds.
270 	*/
271 	@property double waitTime()
272 	{
273 		return getWaitTime();
274 	}
275 	/// ditto
276 	@property void waitTime(double v)
277 	{
278 		setWaitTime(v);
279 	}
280 }