mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
implement automatic update via globalstep
This commit is contained in:
parent
2e3cc57297
commit
574a962371
3
init.lua
3
init.lua
@ -44,9 +44,10 @@ dofile(syspath..'formspec'..DIR_DELIM..'formspec_creation.lua')
|
||||
|
||||
-- Load system
|
||||
dofile(syspath..'chat_command.lua')
|
||||
dofile(syspath..'timer_update.lua')
|
||||
dofile(syspath..'update_timer.lua')
|
||||
dofile(syspath..'on_receive_fields.lua')
|
||||
dofile(syspath..'on_joinplayer.lua')
|
||||
dofile(syspath..'get_times.lua')
|
||||
dofile(syspath..'get_timer_data.lua')
|
||||
dofile(syspath..'register_globalstep.lua')
|
||||
|
||||
|
@ -11,6 +11,7 @@ Real-World Time Format=Realzeit-Format
|
||||
Session Start Time Format=Sitzungsstartzeit-Format
|
||||
Session Duration Format=Sitzungsdauer-Format
|
||||
Timer Format=Timerformat
|
||||
Reset Everything=Alles zurücksetzen
|
||||
Open Main Menu=Hauptmenü öffnen
|
||||
|
||||
# Visibility
|
||||
@ -20,7 +21,7 @@ Invisible=Unsichtbar
|
||||
# Positioning
|
||||
Click the position you want to place the timer at.=Auf die Stelle klicken, an der der Timer angezeigt werden soll.
|
||||
|
||||
# Set Color
|
||||
# Color
|
||||
Use `@1` format only!=Ausschließlich `@1`-Format benutzen!
|
||||
|
||||
# Timezone Offset
|
||||
|
@ -6,7 +6,7 @@ local fe = minetest.formspec_escape
|
||||
|
||||
mtimer.show_formspec.main_menu = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:main_menu', [[
|
||||
size[4,10.25]
|
||||
size[4,11.25]
|
||||
label[0,-0.125;]]..S('mTimer Configuration')..[[]
|
||||
|
||||
button[0,0.5;4,1;set_visibility;]]..S('Visibility')..[[]
|
||||
@ -18,7 +18,8 @@ mtimer.show_formspec.main_menu = function (player_name)
|
||||
button[0,6.5;4,1;session_start_time_format;]]..S('Session Start Time Format')..[[]
|
||||
button[0,7.5;4,1;session_duration_format;]]..S('Session Duration Format')..[[]
|
||||
button[0,8.5;4,1;timer_format;]]..S('Timer Format')..[[]
|
||||
button_exit[0,9.5;4,1;exit;]]..S('Exit')..[[]
|
||||
button[0,9.5;4,1;reset_everything;]]..S('Reset Everything')..[[]
|
||||
button_exit[0,10.5;4,1;exit;]]..S('Exit')..[[]
|
||||
]])
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,6 @@ minetest.register_on_joinplayer(function(player)
|
||||
number = '0x000000',
|
||||
position = {x=0,y=0},
|
||||
alignment = {x=0,y=0},
|
||||
direction = 0,
|
||||
offset = {x=0,y=0}
|
||||
}))
|
||||
end)
|
||||
|
@ -132,6 +132,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Back to menu from all formspecs and conditionally update timer
|
||||
if fields.main_menu then f.main_menu(name) end
|
||||
if formname ~= 'mtimer:main_menu' then mtimer.timer_update(name) end
|
||||
if formname ~= 'mtimer:main_menu' then m.update_timer(name) end
|
||||
|
||||
|
||||
-- Reset everything
|
||||
if fields.reset_everything then
|
||||
for _,def in pairs(m.meta) do
|
||||
meta:set_string(def.key, def.default)
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
|
14
system/register_globalstep.lua
Normal file
14
system/register_globalstep.lua
Normal file
@ -0,0 +1,14 @@
|
||||
local m = mtimer
|
||||
local connected_players = minetest.get_connected_players
|
||||
local timer = 0
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime;
|
||||
if timer < 1 then return end
|
||||
|
||||
for _,player in pairs(connected_players()) do
|
||||
m.update_timer(player:get_player_name())
|
||||
end
|
||||
|
||||
timer = 0
|
||||
end)
|
@ -20,7 +20,7 @@ local get_hud_positions = function (pos)
|
||||
end
|
||||
|
||||
|
||||
mtimer.timer_update = function (player_name)
|
||||
mtimer.update_timer = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local meta = player:get_meta()
|
||||
local m = m.meta
|
Loading…
Reference in New Issue
Block a user