summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-04-08 08:33:12 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-04-08 08:33:55 -0500
commit0e5c6cb8c170ff861f532ebdee3a5e4a73c6797e (patch)
treeadf8bdc4d62123a7d60061eee0e7931b0f68f831 /plugins
parentdb784e019f2a66fed750aebdccf0dd87f2047071 (diff)
plugins/timer: save to the correct file (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/timer/init.lua35
1 files changed, 23 insertions, 12 deletions
diff --git a/plugins/timer/init.lua b/plugins/timer/init.lua
index be96b019919..68fdee1ea4d 100644
--- a/plugins/timer/init.lua
+++ b/plugins/timer/init.lua
@@ -26,20 +26,25 @@ function timer.startplugin()
return path
end
+ local function save()
+ total_time = total_time + (os.time() - start_time)
+ os.remove(get_filename()) -- truncate file
+ file = io.open(get_filename(), "w")
+ if not file then
+ lfs.mkdir(timer_path)
+ file = io.open(get_filename(), "w")
+ end
+ if file then
+ file:write(total_time)
+ file:close()
+ end
+ end
+
+
emu.register_start(function()
local file
if timer_started then
- total_time = total_time + (os.time() - start_time)
- os.remove(get_filename()) -- truncate file
- file = io.open(get_filename(), "w")
- if not file then
- lfs.mkdir(timer_path)
- file = io.open(get_filename(), "w")
- end
- if file then
- file:write(total_time)
- file:close()
- end
+ save()
end
timer_started = true
local file = io.open(get_filename(), "r")
@@ -50,11 +55,17 @@ function timer.startplugin()
start_time = os.time()
end)
+ emu.register_stop(function()
+ timer_started = false
+ save()
+ total_time = 0
+ end)
+
local function sectohms(time)
local hrs = math.floor(time / 3600)
local min = math.floor((time % 3600) / 60)
local sec = math.floor(time % 60)
- return string.format("%02d:%02d:%02d", hrs, min, sec)
+ return string.format("%03d:%02d:%02d", hrs, min, sec)
end
local function menu_populate()