mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-24 16:23:44 +01:00
alter coding style (variables)
This commit is contained in:
parent
7cbb032a43
commit
9e4d98d896
46
init.lua
46
init.lua
@ -1,9 +1,9 @@
|
||||
-- Convert a given x,y string into a table {x=given_x, y=given_y} and return
|
||||
-- it to be used of the screen location parameters in the HUD definition
|
||||
local mtimer_location_value = function (o)
|
||||
local x = o:gsub(',[^,]+$', '')
|
||||
local y = o:gsub('^[^,]+,', '')
|
||||
return {x=x, y=y}
|
||||
local given_x = o:gsub(',[^,]+$', '')
|
||||
local given_y = o:gsub('^[^,]+,', '')
|
||||
return {x=given_x, y=given_y}
|
||||
end
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())..DIR_DELIM
|
||||
@ -28,13 +28,13 @@ local location = {
|
||||
offset = mtimer_location_value(options['mtimer_offset'])
|
||||
}
|
||||
|
||||
local playerData = {}
|
||||
local player_data = {}
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(1, function(player)
|
||||
local playerName = player:get_player_name()
|
||||
local _hudID = player:hud_add({
|
||||
local player_name = player:get_player_name()
|
||||
local _hud_id = player:hud_add({
|
||||
hud_elem_type = 'text',
|
||||
position = location.position,
|
||||
alignment = location.alignment,
|
||||
@ -42,45 +42,45 @@ minetest.register_on_joinplayer(function(player)
|
||||
text = placeholder,
|
||||
number = '0x'..font_color
|
||||
})
|
||||
playerData[playerName] = {
|
||||
startTime = os.time(),
|
||||
hudID = _hudID
|
||||
player_data[player_name] = {
|
||||
start_time = os.time(),
|
||||
hud_id = _hud_id
|
||||
}
|
||||
minetest.after(5, mtimer_changeText, player)
|
||||
minetest.after(5, change_text, player)
|
||||
end, player)
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local playerName = player:get_player_name()
|
||||
playerData[playerName] = nil
|
||||
local player_name = player:get_player_name()
|
||||
player_data[player_name] = nil
|
||||
end)
|
||||
|
||||
|
||||
function mtimer_changeText(player)
|
||||
local playerName = player:get_player_name()
|
||||
if playerName == '' then return end
|
||||
function change_text(player)
|
||||
local player_name = player:get_player_name()
|
||||
if player_name == '' then return end
|
||||
|
||||
-- Save the game-detected locale. Fun fact: changing the locale on runtime
|
||||
-- from within a mod causes the UI to glitch out completely.
|
||||
local currentLocale = os.setlocale(nil)
|
||||
local current_locale = os.setlocale(nil)
|
||||
os.setlocale(format.locale)
|
||||
|
||||
local startTime = playerData[playerName].startTime
|
||||
local hudID = playerData[playerName].hudID
|
||||
local start_time = player_data[player_name].start_time
|
||||
local hud_id = player_data[player_name].hud_id
|
||||
|
||||
local time = 24*60*minetest.get_timeofday()
|
||||
local h = tostring((math.floor(time/60) % 60))
|
||||
local m = tostring((math.floor(time) % 60))
|
||||
|
||||
local res = format.output:gsub('(+.)', {
|
||||
['+s'] = os.date(format.start, startTime),
|
||||
['+s'] = os.date(format.start, start_time),
|
||||
['+c'] = os.date(format.current),
|
||||
['+r'] = os.date('!'..format.runtime:gsub('(+.)', {
|
||||
['+h'] = '%H',
|
||||
['+m'] = '%M',
|
||||
['+s'] = '%S'
|
||||
}), os.time() - startTime),
|
||||
}), os.time() - start_time),
|
||||
['+i'] = format.ingame:gsub('(+.)', {
|
||||
['+h'] = string.rep('0', 2-#h)..h,
|
||||
['+m'] = string.rep('0', 2-#m)..m
|
||||
@ -88,8 +88,8 @@ function mtimer_changeText(player)
|
||||
['+n'] = "\n"
|
||||
})
|
||||
|
||||
os.setlocale(currentLocale) -- Restore game-detected locale
|
||||
os.setlocale(current_locale) -- Restore game-detected locale
|
||||
|
||||
player:hud_change(hudID, 'text', res)
|
||||
minetest.after(interval, mtimer_changeText, player)
|
||||
player:hud_change(hud_id, 'text', res)
|
||||
minetest.after(interval, change_text, player)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user