mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-01-09 22:37:36 +01:00
outsource config loading
This commit is contained in:
parent
6ff6638476
commit
7cbb032a43
53
init.lua
53
init.lua
@ -1,48 +1,31 @@
|
|||||||
-- Convert a given x,y string into a table {x=given_x, y=given_y} and return
|
-- 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
|
-- it to be used of the screen location parameters in the HUD definition
|
||||||
local _mtimer_location_value = function (o)
|
local mtimer_location_value = function (o)
|
||||||
local x = o:gsub(',[^,]+$', '')
|
local x = o:gsub(',[^,]+$', '')
|
||||||
local y = o:gsub('^[^,]+,', '')
|
local y = o:gsub('^[^,]+,', '')
|
||||||
return {x=x, y=y}
|
return {x=x, y=y}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local modpath = minetest.get_modpath(minetest.get_current_modname())..DIR_DELIM
|
||||||
|
local options = dofile(modpath..'system'..DIR_DELIM..'get_options.lua')
|
||||||
|
|
||||||
local _mtimer_get_options = function ()
|
local interval = options['mtimer_update_interval']
|
||||||
local path = minetest.get_modpath(minetest.get_current_modname())
|
local placeholder = options['mtimer_placeholder']
|
||||||
local file = io.open(path..DIR_DELIM..'settingtypes.txt', 'rb')
|
local font_color = options['mtimer_font_color']
|
||||||
local result = {}
|
|
||||||
|
|
||||||
for line in file:lines() do
|
|
||||||
if line:match("^([a-zA-Z])") then
|
|
||||||
local name = line:gsub(' .+', '')
|
|
||||||
local default_value = line:gsub('^[^ ]+ %b() %a+ ', '')
|
|
||||||
local set_value = minetest.setting_get(name)
|
|
||||||
result[name] = set_value or default_value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
local _options = _mtimer_get_options()
|
|
||||||
|
|
||||||
local interval = _options['mtimer_update_interval']
|
|
||||||
local placeholder = _options['mtimer_placeholder']
|
|
||||||
local font_color = _options['mtimer_font_color']
|
|
||||||
|
|
||||||
local format = {
|
local format = {
|
||||||
locale = _options['mtimer_locale'],
|
locale = options['mtimer_locale'],
|
||||||
start = _options['mtimer_session_start'],
|
start = options['mtimer_session_start'],
|
||||||
runtime = _options['mtimer_session_runtime'],
|
runtime = options['mtimer_session_runtime'],
|
||||||
current = _options['mtimer_current_time'],
|
current = options['mtimer_current_time'],
|
||||||
ingame = _options['mtimer_ingame_time'],
|
ingame = options['mtimer_ingame_time'],
|
||||||
output = _options['mtimer_output_format']
|
output = options['mtimer_output_format']
|
||||||
}
|
}
|
||||||
|
|
||||||
local location = {
|
local location = {
|
||||||
position = _mtimer_location_value(_options['mtimer_position']),
|
position = mtimer_location_value(options['mtimer_position']),
|
||||||
alignment = _mtimer_location_value(_options['mtimer_alignment']),
|
alignment = mtimer_location_value(options['mtimer_alignment']),
|
||||||
offset = _mtimer_location_value(_options['mtimer_offset'])
|
offset = mtimer_location_value(options['mtimer_offset'])
|
||||||
}
|
}
|
||||||
|
|
||||||
local playerData = {}
|
local playerData = {}
|
||||||
@ -63,7 +46,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
startTime = os.time(),
|
startTime = os.time(),
|
||||||
hudID = _hudID
|
hudID = _hudID
|
||||||
}
|
}
|
||||||
minetest.after(5, _mtimer_changeText, player)
|
minetest.after(5, mtimer_changeText, player)
|
||||||
end, player)
|
end, player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -74,7 +57,7 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
function _mtimer_changeText(player)
|
function mtimer_changeText(player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
if playerName == '' then return end
|
if playerName == '' then return end
|
||||||
|
|
||||||
@ -108,5 +91,5 @@ function _mtimer_changeText(player)
|
|||||||
os.setlocale(currentLocale) -- Restore game-detected locale
|
os.setlocale(currentLocale) -- Restore game-detected locale
|
||||||
|
|
||||||
player:hud_change(hudID, 'text', res)
|
player:hud_change(hudID, 'text', res)
|
||||||
minetest.after(interval, _mtimer_changeText, player)
|
minetest.after(interval, mtimer_changeText, player)
|
||||||
end
|
end
|
||||||
|
14
system/get_options.lua
Normal file
14
system/get_options.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
local file = io.open(path..DIR_DELIM..'settingtypes.txt', 'rb')
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
for line in file:lines() do
|
||||||
|
if line:match("^([a-zA-Z])") then
|
||||||
|
local name = line:gsub(' .+', '')
|
||||||
|
local default_value = line:gsub('^[^ ]+ %b() %a+ ', '')
|
||||||
|
local set_value = minetest.setting_get(name)
|
||||||
|
result[name] = set_value or default_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
Loading…
Reference in New Issue
Block a user