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