Builtin: Backport MT5 minor changes
parent
54f5679db3
commit
b3a34dd850
|
@ -97,7 +97,7 @@ end
|
|||
|
||||
if INIT == "client" then
|
||||
core.register_chatcommand("help", {
|
||||
params = gettext("[all/<cmd>]"),
|
||||
params = gettext("[all | <cmd>]"),
|
||||
description = gettext("Get help for commands"),
|
||||
func = function(param)
|
||||
return do_help_cmd(nil, param)
|
||||
|
@ -105,7 +105,7 @@ if INIT == "client" then
|
|||
})
|
||||
else
|
||||
core.register_chatcommand("help", {
|
||||
params = "[all/privs/<cmd>]",
|
||||
params = "[all | privs | <cmd>]",
|
||||
description = "Get help for commands or list privileges",
|
||||
func = do_help_cmd,
|
||||
})
|
||||
|
|
|
@ -250,7 +250,6 @@ end
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
function compare_worlds(world1,world2)
|
||||
|
||||
if world1.path ~= world2.path then
|
||||
return false
|
||||
end
|
||||
|
@ -268,7 +267,6 @@ end
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
function sort_worlds_alphabetic(self)
|
||||
|
||||
table.sort(self.m_processed_list, function(a, b)
|
||||
--fixes issue #857 (crash due to sorting nil in worldlist)
|
||||
if a == nil or b == nil then
|
||||
|
@ -285,7 +283,6 @@ end
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
function sort_mod_list(self)
|
||||
|
||||
table.sort(self.m_processed_list, function(a, b)
|
||||
-- Show game mods at bottom
|
||||
if a.typ ~= b.typ then
|
||||
|
|
|
@ -204,17 +204,3 @@ function core.deserialize(str, safe)
|
|||
return nil, data
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Unit tests
|
||||
local test_in = {cat={sound="nyan", speed=400}, dog={sound="woof"}}
|
||||
local test_out = core.deserialize(core.serialize(test_in))
|
||||
|
||||
assert(test_in.cat.sound == test_out.cat.sound)
|
||||
assert(test_in.cat.speed == test_out.cat.speed)
|
||||
assert(test_in.dog.sound == test_out.dog.sound)
|
||||
|
||||
test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
|
||||
test_out = core.deserialize(core.serialize(test_in))
|
||||
assert(test_in.escape_chars == test_out.escape_chars)
|
||||
assert(test_in.non_european == test_out.non_european)
|
||||
|
|
|
@ -66,24 +66,26 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
local function get_formspec(self)
|
||||
local formspec = ""
|
||||
local name = self.tablist[self.last_tab_index].name
|
||||
local tabname = name == "local" and name or name == "online" and name or nil
|
||||
|
||||
if not self.hidden and (self.parent == nil or not self.parent.hidden) then
|
||||
local name = self.tablist[self.last_tab_index].name
|
||||
local tabname = (name == "local" or name == "online") and name or nil
|
||||
|
||||
if self.parent == nil then
|
||||
local tsize = self.tablist[self.last_tab_index].tabsize or
|
||||
{width=self.width, height=self.height}
|
||||
|
||||
formspec = formspec ..
|
||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
||||
dump(self.fixed_size))
|
||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
||||
dump(self.fixed_size)) ..
|
||||
get_bg(tsize, tabname)
|
||||
|
||||
formspec = formspec .. get_bg(tsize, tabname)
|
||||
end
|
||||
formspec = formspec .. self:tab_header()
|
||||
formspec = formspec ..
|
||||
self.tablist[self.last_tab_index].get_formspec(
|
||||
self, name,
|
||||
self,
|
||||
name,
|
||||
self.tablist[self.last_tab_index].tabdata,
|
||||
self.tablist[self.last_tab_index].tabsize
|
||||
)
|
||||
|
|
|
@ -79,12 +79,11 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
function ui.update()
|
||||
local formspec = ""
|
||||
local restart_btn
|
||||
|
||||
-- attempt auto restart
|
||||
if gamedata ~= nil and gamedata.errormessage ~= nil and
|
||||
core.settings:get_bool("auto_connect") == true and
|
||||
tonumber(core.settings:get("connect_time")) < os.time() - 30 and
|
||||
core.settings:get("connect_time") and tonumber(core.settings:get("connect_time")) < os.time() - 30 and
|
||||
not gamedata.errormessage:find("Kicked") then
|
||||
if core.settings:get("maintab_LAST") == "local" then
|
||||
gamedata.singleplayer = true
|
||||
|
@ -111,12 +110,13 @@ function ui.update()
|
|||
formspec = wordwrap_quickhack(gamedata.errormessage)
|
||||
local error_title
|
||||
if gamedata.errormessage:find("ModError") then
|
||||
error_title = fgettext("An error occured in a Lua script, such as a mod:")
|
||||
error_title = fgettext("An error occurred in a Lua script:")
|
||||
else
|
||||
error_title = fgettext("An error occured:")
|
||||
error_title = fgettext("An error occurred:")
|
||||
end
|
||||
local restart_btn
|
||||
if core.settings:get("maintab_LAST") == "local" and
|
||||
tonumber(core.settings:get("connect_time")) < os.time() - 30 then
|
||||
core.settings:get("connect_time") and tonumber(core.settings:get("connect_time")) < os.time() - 30 then
|
||||
restart_btn = "]button[6,4.6;3,0.5;btn_reconnect_no;" .. fgettext("Close") .. "]" ..
|
||||
"button[3,4.6;3,0.5;btn_reconnect_yes;" .. fgettext("Restart") .. "]"
|
||||
else
|
||||
|
@ -182,7 +182,6 @@ end
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
function ui.handle_events(event)
|
||||
|
||||
for _, value in pairs(ui.childlist) do
|
||||
if value.handle_events ~= nil then
|
||||
local retval = value:handle_events(event)
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
local scriptpath = core.get_builtin_path()..DIR_DELIM
|
||||
local commonpath = scriptpath.."common"..DIR_DELIM
|
||||
local gamepath = scriptpath.."game"..DIR_DELIM
|
||||
local scriptpath = core.get_builtin_path()
|
||||
local commonpath = scriptpath .. "common" .. DIR_DELIM
|
||||
local gamepath = scriptpath .. "game" .. DIR_DELIM
|
||||
|
||||
-- Shared between builtin files, but
|
||||
-- not exposed to outer context
|
||||
local builtin_shared = {}
|
||||
|
||||
dofile(commonpath.."vector.lua")
|
||||
dofile(commonpath .. "vector.lua")
|
||||
|
||||
dofile(gamepath.."constants.lua")
|
||||
assert(loadfile(gamepath.."item.lua"))(builtin_shared)
|
||||
dofile(gamepath.."register.lua")
|
||||
dofile(gamepath .. "constants.lua")
|
||||
assert(loadfile(gamepath .. "item.lua"))(builtin_shared)
|
||||
dofile(gamepath .. "register.lua")
|
||||
|
||||
if core.settings:get_bool("profiler.load") then
|
||||
profiler = dofile(scriptpath.."profiler"..DIR_DELIM.."init.lua")
|
||||
profiler = dofile(scriptpath .. "profiler" .. DIR_DELIM .. "init.lua")
|
||||
end
|
||||
|
||||
dofile(commonpath .. "after.lua")
|
||||
dofile(gamepath.."item_entity.lua")
|
||||
dofile(gamepath.."misc.lua")
|
||||
dofile(gamepath.."privileges.lua")
|
||||
dofile(gamepath.."auth.lua")
|
||||
dofile(gamepath .. "item_entity.lua")
|
||||
dofile(gamepath .. "misc.lua")
|
||||
dofile(gamepath .. "privileges.lua")
|
||||
dofile(gamepath .. "auth.lua")
|
||||
dofile(commonpath .. "chatcommands.lua")
|
||||
dofile(gamepath.."chatcommands.lua")
|
||||
dofile(gamepath.."static_spawn.lua")
|
||||
dofile(gamepath.."detached_inventory.lua")
|
||||
assert(loadfile(gamepath.."falling.lua"))(builtin_shared)
|
||||
dofile(gamepath.."voxelarea.lua")
|
||||
dofile(gamepath.."forceloading.lua")
|
||||
dofile(gamepath.."hud.lua")
|
||||
dofile(gamepath.."statbars.lua")
|
||||
dofile(gamepath.."hunger.lua")
|
||||
dofile(gamepath.."weather.lua")
|
||||
dofile(gamepath .. "chat.lua")
|
||||
dofile(gamepath .. "static_spawn.lua")
|
||||
dofile(gamepath .. "detached_inventory.lua")
|
||||
assert(loadfile(gamepath .. "falling.lua"))(builtin_shared)
|
||||
dofile(gamepath .. "voxelarea.lua")
|
||||
dofile(gamepath .. "forceloading.lua")
|
||||
dofile(gamepath .. "hud.lua")
|
||||
dofile(gamepath .. "statbars.lua")
|
||||
dofile(gamepath .. "hunger.lua")
|
||||
dofile(gamepath .. "weather.lua")
|
||||
|
||||
profiler = nil
|
||||
|
|
|
@ -97,9 +97,9 @@ function render_serverlist_row(spec, is_favorite, is_approved)
|
|||
end
|
||||
end
|
||||
|
||||
local details = ""
|
||||
local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
|
||||
|
||||
local details
|
||||
if is_favorite then
|
||||
details = "1,"
|
||||
else
|
||||
|
@ -126,11 +126,11 @@ function render_serverlist_row(spec, is_favorite, is_approved)
|
|||
end
|
||||
|
||||
if spec.clients and spec.clients_max then
|
||||
local clients_color = ''
|
||||
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||
|
||||
-- Choose a color depending on how many clients are connected
|
||||
-- (relatively to clients_max)
|
||||
local clients_color
|
||||
if grey_out then clients_color = '#aaaaaa'
|
||||
elseif spec.clients == 0 then clients_color = '' -- 0 players: default/white
|
||||
elseif clients_percent <= 60 then clients_color = '#a1e587' -- 0-60%: green
|
||||
|
@ -173,15 +173,28 @@ os.tempfolder = function()
|
|||
local filetocheck = os.tmpname()
|
||||
os.remove(filetocheck)
|
||||
|
||||
local randname = "MTTempModFolder_" .. math.random(0,10000)
|
||||
if DIR_DELIM == "\\" then
|
||||
-- luacheck: ignore
|
||||
-- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/
|
||||
-- The C runtime (CRT) function called by os.tmpname is tmpnam.
|
||||
-- Microsofts tmpnam implementation in older CRT / MSVC releases is defective.
|
||||
-- tmpnam return values starting with a backslash characterize this behavior.
|
||||
-- https://sourceforge.net/p/mingw-w64/bugs/555/
|
||||
-- MinGW tmpnam implementation is forwarded to the CRT directly.
|
||||
-- https://sourceforge.net/p/mingw-w64/discussion/723797/thread/55520785/
|
||||
-- MinGW links to an older CRT release (msvcrt.dll).
|
||||
-- Due to legal concerns MinGW will never use a newer CRT.
|
||||
--
|
||||
-- Make use of TEMP to compose the temporary filename if an old
|
||||
-- style tmpnam return value is detected.
|
||||
if filetocheck:sub(1, 1) == "\\" then
|
||||
local tempfolder = os.getenv("TEMP")
|
||||
return tempfolder .. filetocheck
|
||||
else
|
||||
local backstring = filetocheck:reverse()
|
||||
return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
|
||||
end
|
||||
|
||||
local randname = "MTTempModFolder_" .. math.random(0,10000)
|
||||
local backstring = filetocheck:reverse()
|
||||
return filetocheck:sub(0, filetocheck:len() - backstring:find(DIR_DELIM) + 1) ..
|
||||
randname
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -191,7 +204,7 @@ function menu_render_worldlist()
|
|||
|
||||
for _, v in ipairs(current_worldlist) do
|
||||
if retval ~= "" then retval = retval .. "," end
|
||||
retval = retval .. core.formspec_escape(v.name) .. ""
|
||||
retval = retval .. core.formspec_escape(v.name)
|
||||
end
|
||||
|
||||
return retval
|
||||
|
|
|
@ -121,12 +121,12 @@ local function get_formspec(_, _, tabdata)
|
|||
local favs = core.get_favorites("local")
|
||||
if #favs > 0 then
|
||||
for i = 1, #favs do
|
||||
for j = 1, #menudata.favorites do
|
||||
if menudata.favorites[j].address == favs[i].address and
|
||||
menudata.favorites[j].port == favs[i].port then
|
||||
table.insert(menudata.favorites, i, table.remove(menudata.favorites, j))
|
||||
end
|
||||
for j = 1, #menudata.favorites do
|
||||
if menudata.favorites[j].address == favs[i].address and
|
||||
menudata.favorites[j].port == favs[i].port then
|
||||
table.insert(menudata.favorites, i, table.remove(menudata.favorites, j))
|
||||
end
|
||||
end
|
||||
if favs[i].address ~= menudata.favorites[i].address then
|
||||
table.insert(menudata.favorites, i, favs[i])
|
||||
end
|
||||
|
@ -293,8 +293,7 @@ local function main_button_handler(_, fields, _, tabdata)
|
|||
for k = 1, #keywords do
|
||||
local keyword = keywords[k]
|
||||
if server.name then
|
||||
local name = server.name:lower()
|
||||
local _, count = name:gsub(keyword, keyword)
|
||||
local _, count = (server.name:lower()):gsub(keyword, keyword)
|
||||
found = found + count * 4
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ local function get_bool_default(name, default)
|
|||
return val
|
||||
end
|
||||
|
||||
local profiler_path = core.get_builtin_path()..DIR_DELIM.."profiler"..DIR_DELIM
|
||||
local profiler_path = core.get_builtin_path().."profiler"..DIR_DELIM
|
||||
local profiler = {}
|
||||
local sampler = assert(loadfile(profiler_path .. "sampling.lua"))(profiler)
|
||||
local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler, get_bool_default)
|
||||
|
|
|
@ -88,7 +88,7 @@ local function instrument(def)
|
|||
if not def or not def.func then
|
||||
return
|
||||
end
|
||||
def.mod = def.mod or get_current_modname()
|
||||
def.mod = def.mod or get_current_modname() or "??"
|
||||
local modname = def.mod
|
||||
local instrument_name = generate_name(def)
|
||||
local func = def.func
|
||||
|
@ -117,7 +117,8 @@ end
|
|||
local function assert_can_be_called(func, func_name, level)
|
||||
if not can_be_called(func) then
|
||||
-- Then throw an *helpful* error, by pointing on our caller instead of us.
|
||||
error(format("Invalid argument to %s. Expected function-like type instead of '%s'.", func_name, type(func)), level + 1)
|
||||
error(format("Invalid argument to %s. Expected function-like type instead of '%s'.",
|
||||
func_name, type(func)), level + 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue