|
@@ -1,8 +1,7 @@
|
|
--- set value of numeric time indicator (in percent from 0 to 60s)
|
|
|
|
|
|
+-- set value of numeric time indicator (from 0 to 60s)
|
|
local function update_numeric(p)
|
|
local function update_numeric(p)
|
|
local node = gui.get_node("numeric")
|
|
local node = gui.get_node("numeric")
|
|
- local percent = math.floor(p)
|
|
|
|
- gui.set_text(node, tostring(percent) .. "s")
|
|
|
|
|
|
+ gui.set_text(node, tostring(p) .. "s")
|
|
end
|
|
end
|
|
|
|
|
|
-- update radial/circle time indicator by changing the fill angle
|
|
-- update radial/circle time indicator by changing the fill angle
|
|
@@ -13,18 +12,25 @@ local function update_radial(p)
|
|
end
|
|
end
|
|
|
|
|
|
function init(self)
|
|
function init(self)
|
|
- self.time = 0
|
|
|
|
|
|
+ self.count = 0 -- <1>
|
|
|
|
+ local interval = 1 -- <2>
|
|
|
|
+ local repeating = true -- <3>
|
|
|
|
|
|
- -- create a timer delay with 1s interval, repeating
|
|
|
|
- local interval = 1
|
|
|
|
- local repeating = true
|
|
|
|
- timer.delay(interval, repeating, function()
|
|
|
|
- -- each second this function will be called
|
|
|
|
- self.time = self.time + 1
|
|
|
|
- -- take modulo out of time elapsed from the beginning for 60s periods:
|
|
|
|
- local p = self.time % 60
|
|
|
|
-
|
|
|
|
- update_numeric(p)
|
|
|
|
- update_radial(p)
|
|
|
|
|
|
+ timer.delay(interval, repeating, function() -- <4>
|
|
|
|
+ self.count = self.count + 1 -- <5>
|
|
|
|
+ local p = self.time % 60 -- <6>
|
|
|
|
+ update_numeric(p) -- <7>
|
|
|
|
+ update_radial(p) -- <8>
|
|
end)
|
|
end)
|
|
-end
|
|
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+--[[
|
|
|
|
+1. Start the count with value 0.
|
|
|
|
+2. We will use interval of 1 [s].
|
|
|
|
+3. We will be repeating the timer endlessly.
|
|
|
|
+4. Start the timer with interval (1s) and repeating (true) and pass a callback function.
|
|
|
|
+5. The function will be called every 1s, so increase the count by 1 each time.
|
|
|
|
+6. Get the modulo of 60, because the timer will be reset every 60s.
|
|
|
|
+7. Update the numeric display of seconds passed.
|
|
|
|
+8. Update the radial indicator of seconds passed.
|
|
|
|
+--]]
|