putting xtend as only mod to the top directory

This commit is contained in:
Dirk Sohler 2017-02-09 17:03:52 +01:00
commit 12e48570c7
4 changed files with 84 additions and 0 deletions

2
depends.txt Normal file

@ -0,0 +1,2 @@
default
xtend_default

7
description.txt Normal file

@ -0,0 +1,7 @@
Creates a timer section on the bottom right of the screen.
The timer allows to show several game related times and dates. Let's play creators can show their viewers when the recording was made, how long the recording was, the current time while recording, and the ingame time.
The timer output is configurable in the advanced configuration of Minetest and provides the user with a set of variables to use and allows the date/time to be formatted as the user wants.
The creator of this mod is German so the default values are set up in a way to support the German language. Since it can be configured as wanted this can be changed.

75
init.lua Normal file

@ -0,0 +1,75 @@
-- 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 _xtimer_location_value = function (o)
local x = o:gsub(',[^,]+$', '')
local y = o:gsub('^[^,]+,', '')
return {x=x, y=y}
end
_xtend.v.xtimer = {
startDate = os.time(),
interval = _xtend.g('xtimer_update_interval'),
placeholder = _xtend.g('xtimer_placeholder'),
font_color = _xtend.g('xtimer_font_color'),
format = {
locale = _xtend.g('xtimer_locale'),
start = _xtend.g('xtimer_session_start'),
runtime = _xtend.g('xtimer_session_runtime'),
current = _xtend.g('xtimer_current_time'),
ingame = _xtend.g('xtimer_ingame_time'),
output = _xtend.g('xtimer_output_format')
},
location = {
position = _xtimer_location_value(_xtend.g('xtimer_position')),
alignment = _xtimer_location_value(_xtend.g('xtimer_alignment')),
offset = _xtimer_location_value(_xtend.g('xtimer_offset'))
}
}
minetest.register_on_joinplayer(function(player)
minetest.after(1, function(player)
local hud_id = player:hud_add({
hud_elem_type = 'text',
position = _xtend.v.xtimer.location.position,
alignment = _xtend.v.xtimer.location.alignment,
offset = _xtend.v.xtimer.location.offset,
text = _xtend.v.xtimer.placeholder,
number = '0x'.._xtend.v.xtimer.font_color
})
minetest.after(5, _xtimer_changeText, player, hud_id)
end, player)
end)
function _xtimer_changeText(player, hud_id)
-- 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)
os.setlocale(_xtend.v.xtimer.format.locale)
local time = 24*60*minetest.get_timeofday()
local h = tostring((math.floor(time/60) % 60))
local m = tostring((math.floor(time) % 60))
local res = _xtend.v.xtimer.format.output:gsub('(+.)', {
['+s'] = os.date(_xtend.v.xtimer.format.start, _xtend.v.xtimer.startDate),
['+c'] = os.date(_xtend.v.xtimer.format.current),
['+r'] = os.date('!'.._xtend.v.xtimer.format.runtime:gsub('(+.)', {
['+h'] = '%H',
['+m'] = '%M',
['+s'] = '%S'
}), os.time() - _xtend.v.xtimer.startDate),
['+i'] = _xtend.v.xtimer.format.ingame:gsub('(+.)', {
['+h'] = string.rep('0', 2-#h)..h,
['+m'] = string.rep('0', 2-#m)..m
}),
['+n'] = "\n"
})
os.setlocale(currentLocale) -- Restore game-detected locale
player:hud_change(hud_id, 'text', res)
minetest.after(_xtend.v.xtimer.interval,_xtimer_changeText,player,hud_id)
end

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB