mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-12-01 03:33:56 +01:00
39 lines
1.6 KiB
Lua
39 lines
1.6 KiB
Lua
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
|