mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-02-16 08:32:27 +01:00
implement timer update function
This commit is contained in:
2
init.lua
2
init.lua
@ -8,7 +8,7 @@ mtimer = {
|
|||||||
meta = {
|
meta = {
|
||||||
visible = { key = 'mtimer:visible', default = 'true' },
|
visible = { key = 'mtimer:visible', default = 'true' },
|
||||||
position = { key = 'mtimer:position', default = 'bl' },
|
position = { key = 'mtimer:position', default = 'bl' },
|
||||||
color = { key = 'mtimer:color', default = '#ffffffFF' },
|
color = { key = 'mtimer:color', default = '#ffffff' },
|
||||||
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
||||||
ingame_time = {
|
ingame_time = {
|
||||||
key = 'mtimer:ingame_time_format',
|
key = 'mtimer:ingame_time_format',
|
||||||
|
@ -8,8 +8,8 @@ Color=Farbe
|
|||||||
Timezone Offset=Zeitzonenunterschied
|
Timezone Offset=Zeitzonenunterschied
|
||||||
Ingame Time Format=Spielzeit-Format
|
Ingame Time Format=Spielzeit-Format
|
||||||
Real-World Time Format=Realzeit-Format
|
Real-World Time Format=Realzeit-Format
|
||||||
Session Start Time Format=Session-Startzeit-Format
|
Session Start Time Format=Sitzungsstartzeit-Format
|
||||||
Session Duration Format=Session-Dauer-Format
|
Session Duration Format=Sitzungsdauer-Format
|
||||||
Timer Format=Timerformat
|
Timer Format=Timerformat
|
||||||
Open Main Menu=Hauptmenü öffnen
|
Open Main Menu=Hauptmenü öffnen
|
||||||
|
|
||||||
@ -46,10 +46,17 @@ ISO 8601 Time=Zeit nach ISO 8601
|
|||||||
Timestamp=Zeitstempel
|
Timestamp=Zeitstempel
|
||||||
Current Result=Aktuelles Ergebnis
|
Current Result=Aktuelles Ergebnis
|
||||||
|
|
||||||
|
# Timer Format
|
||||||
|
Real-World Date=Realzeit/-datum
|
||||||
|
In-Game Time=Spielzeit
|
||||||
|
Session Start Time=Sitzungs-Startzeit
|
||||||
|
Session Duration=Sitzungsdauer
|
||||||
|
|
||||||
# Generic Formspec Strings
|
# Generic Formspec Strings
|
||||||
Default=Standard
|
Default=Standard
|
||||||
Exit=Verlassen
|
Exit=Verlassen
|
||||||
Main Menu=Hauptmenü
|
Main Menu=Hauptmenü
|
||||||
|
Apply=Anwenden
|
||||||
|
|
||||||
# Timer Weekdays
|
# Timer Weekdays
|
||||||
Monday=Montag
|
Monday=Montag
|
||||||
|
@ -63,15 +63,14 @@ mtimer.show_formspec.set_color = function (player_name)
|
|||||||
'#',
|
'#',
|
||||||
minetest.colorize('#ce5c00', 'rr'),
|
minetest.colorize('#ce5c00', 'rr'),
|
||||||
minetest.colorize('#4e9a06', 'gg'),
|
minetest.colorize('#4e9a06', 'gg'),
|
||||||
minetest.colorize('#729fcf', 'bb'),
|
minetest.colorize('#729fcf', 'bb')
|
||||||
'AA'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.show_formspec(player_name, 'mtimer:set_color',
|
minetest.show_formspec(player_name, 'mtimer:set_color',
|
||||||
build_frame(6, 2.7, S('Color'))..[[
|
build_frame(6, 2.7, S('Color'))..[[
|
||||||
field_close_on_enter[color;false]
|
field_close_on_enter[color;false]
|
||||||
field[0.25,0.75;3,1;color;;]]..color..[[]
|
field[0.25,0.75;3,1;color;;]]..color..[[]
|
||||||
box[3,0.55;0.65,0.65;]]..color..[[]
|
box[3,0.55;0.65,0.65;]]..color..[[ff]
|
||||||
label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[]
|
label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[]
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
|
@ -2,9 +2,21 @@ local m = mtimer
|
|||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
|
|
||||||
for _,def in pairs(m.meta) do
|
for _,def in pairs(m.meta) do
|
||||||
local current = meta:get_string(def.key)
|
local current = meta:get_string(def.key)
|
||||||
if current == '' then meta:set_string(def.key, def.default) end
|
if current == '' then meta:set_string(def.key, def.default) end
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_string('mtimer:session_start', os.time())
|
meta:set_string('mtimer:session_start', os.time())
|
||||||
|
|
||||||
|
meta:set_string('mtimer:hud_id', player:hud_add({
|
||||||
|
hud_elem_type = 'text',
|
||||||
|
text = '',
|
||||||
|
number = '0x000000',
|
||||||
|
position = {x=0,y=0},
|
||||||
|
alignment = {x=0,y=0},
|
||||||
|
direction = 0,
|
||||||
|
offset = {x=0,y=0}
|
||||||
|
}))
|
||||||
end)
|
end)
|
||||||
|
@ -53,7 +53,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
local color = ''
|
local color = ''
|
||||||
|
|
||||||
if fields.color then
|
if fields.color then
|
||||||
local valid = fields.color:match('^#'..('[0-9a-fA-F]'):rep(8)..'$')
|
local valid = fields.color:match('^#'..('[0-9a-fA-F]'):rep(6)..'$')
|
||||||
local color = valid and fields.color or attr.default
|
local color = valid and fields.color or attr.default
|
||||||
meta:set_string(attr.key, color)
|
meta:set_string(attr.key, color)
|
||||||
end
|
end
|
||||||
@ -130,10 +130,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Back to menu from all formspecs
|
-- Back to menu from all formspecs and conditionally update timer
|
||||||
if fields.main_menu then f.main_menu(name) end
|
if fields.main_menu then f.main_menu(name) end
|
||||||
|
if formname ~= 'mtimer:main_menu' then mtimer.timer_update(name) end
|
||||||
|
|
||||||
|
|
||||||
-- DEBUG: Print all player meta data
|
|
||||||
print(dump(meta:to_table()))
|
|
||||||
end)
|
end)
|
||||||
|
@ -1 +1,38 @@
|
|||||||
local m = mtimer
|
local m = mtimer
|
||||||
|
|
||||||
|
|
||||||
|
local get_hud_positions = function (pos)
|
||||||
|
local p = { x = 0, y = 0 }
|
||||||
|
local a = { x = 0, y = 0 }
|
||||||
|
local o = { x = 0, y = 0 }
|
||||||
|
|
||||||
|
if pos == 'tl' then p = {x=0, y=0 } a = {x=1, y=1 } o = {x=5, y=3} end
|
||||||
|
if pos == 'tc' then p = {x=0.5,y=0 } a = {x=0, y=1 } o = {x=0, y=3} end
|
||||||
|
if pos == 'tr' then p = {x=1, y=0 } a = {x=-1,y=1 } o = {x=-6,y=3} end
|
||||||
|
if pos == 'ml' then p = {x=0, y=0.5} a = {x=1, y=0 } o = {x=5, y=0} end
|
||||||
|
if pos == 'mc' then p = {x=0.5,y=0.5} a = {x=0, y=0 } o = {x=0, y=0} end
|
||||||
|
if pos == 'mr' then p = {x=1, y=0.5} a = {x=-1,y=0 } o = {x=-6,y=0} end
|
||||||
|
if pos == 'bl' then p = {x=0, y=1 } a = {x=1, y=-1} o = {x=5, y=0} end
|
||||||
|
if pos == 'bc' then p = {x=0.5,y=1 } a = {x=0, y=-1} o = {x=0, y=0} end
|
||||||
|
if pos == 'br' then p = {x=1, y=1 } a = {x=-1,y=-1} o = {x=-6,y=0} end
|
||||||
|
|
||||||
|
return { position = p, alignment = a, offset = o }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
mtimer.timer_update = function (player_name)
|
||||||
|
local player = minetest.get_player_by_name(player_name)
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local m = m.meta
|
||||||
|
local hud_id = meta:get_string('mtimer:hud_id')
|
||||||
|
|
||||||
|
local text = mtimer.get_timer_data(player_name).formatted
|
||||||
|
local number = meta:get_string(m.color.key):gsub('#', '0x')
|
||||||
|
local orientation = get_hud_positions(meta:get_string(m.position.key))
|
||||||
|
|
||||||
|
player:hud_change(hud_id, 'text', text)
|
||||||
|
player:hud_change(hud_id, 'number', number)
|
||||||
|
player:hud_change(hud_id, 'position', orientation.position)
|
||||||
|
player:hud_change(hud_id, 'alignment', orientation.alignment)
|
||||||
|
player:hud_change(hud_id, 'offset', orientation.offset)
|
||||||
|
end
|
||||||
|
Reference in New Issue
Block a user