forked from Mirrorlandia_minetest/minetest
Add luacheck to check builtin (#7895)
This commit is contained in:
parent
8da35c22d1
commit
8e757859d6
74
.luacheckrc
Normal file
74
.luacheckrc
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
ignore = {
|
||||||
|
"131", -- Unused global variable
|
||||||
|
"431", -- Shadowing an upvalue
|
||||||
|
"432", -- Shadowing an upvalue argument
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
"ItemStack",
|
||||||
|
"INIT",
|
||||||
|
"DIR_DELIM",
|
||||||
|
"dump", "dump2",
|
||||||
|
"fgettext", "fgettext_ne",
|
||||||
|
"vector",
|
||||||
|
"VoxelArea",
|
||||||
|
"profiler",
|
||||||
|
"Settings",
|
||||||
|
|
||||||
|
string = {fields = {"split"}},
|
||||||
|
table = {fields = {"copy", "getn", "indexof", "insert_all"}},
|
||||||
|
math = {fields = {"hypot"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"core",
|
||||||
|
"gamedata",
|
||||||
|
os = { fields = { "tempfolder" } },
|
||||||
|
"_",
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/client/register.lua"] = {
|
||||||
|
globals = {
|
||||||
|
debug = {fields={"getinfo"}},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/common/misc_helpers.lua"] = {
|
||||||
|
globals = {
|
||||||
|
"dump", "dump2", "table", "math", "string",
|
||||||
|
"fgettext", "fgettext_ne", "basic_dump", "game", -- ???
|
||||||
|
"file_exists", "get_last_folder", "cleanup_path", -- ???
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/common/vector.lua"] = {
|
||||||
|
globals = { "vector" },
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/game/voxelarea.lua"] = {
|
||||||
|
globals = { "VoxelArea" },
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/game/init.lua"] = {
|
||||||
|
globals = { "profiler" },
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/common/filterlist.lua"] = {
|
||||||
|
globals = {
|
||||||
|
"filterlist",
|
||||||
|
"compare_worlds", "sort_worlds_alphabetic", "sort_mod_list", -- ???
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
files["builtin/mainmenu"] = {
|
||||||
|
globals = {
|
||||||
|
"gamedata",
|
||||||
|
},
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
"PLATFORM",
|
||||||
|
},
|
||||||
|
}
|
@ -26,9 +26,9 @@ core.register_on_sending_chat_message(function(message)
|
|||||||
local cmd_def = core.registered_chatcommands[cmd]
|
local cmd_def = core.registered_chatcommands[cmd]
|
||||||
if cmd_def then
|
if cmd_def then
|
||||||
core.set_last_run_mod(cmd_def.mod_origin)
|
core.set_last_run_mod(cmd_def.mod_origin)
|
||||||
local _, message = cmd_def.func(param)
|
local _, result = cmd_def.func(param)
|
||||||
if message then
|
if result then
|
||||||
core.display_chat_message(message)
|
core.display_chat_message(result)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
|
core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
|
||||||
|
@ -250,7 +250,6 @@ end
|
|||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function compare_worlds(world1,world2)
|
function compare_worlds(world1,world2)
|
||||||
|
|
||||||
if world1.path ~= world2.path then
|
if world1.path ~= world2.path then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,6 @@ local mod_cmds = {}
|
|||||||
local function load_mod_command_tree()
|
local function load_mod_command_tree()
|
||||||
mod_cmds = {}
|
mod_cmds = {}
|
||||||
|
|
||||||
local check_player_privs = core.check_player_privs
|
|
||||||
for name, def in pairs(core.registered_chatcommands) do
|
for name, def in pairs(core.registered_chatcommands) do
|
||||||
mod_cmds[def.mod_origin] = mod_cmds[def.mod_origin] or {}
|
mod_cmds[def.mod_origin] = mod_cmds[def.mod_origin] or {}
|
||||||
local cmds = mod_cmds[def.mod_origin]
|
local cmds = mod_cmds[def.mod_origin]
|
||||||
@ -86,8 +85,8 @@ end
|
|||||||
|
|
||||||
local function build_privs_formspec(name)
|
local function build_privs_formspec(name)
|
||||||
local privs = {}
|
local privs = {}
|
||||||
for name, def in pairs(core.registered_privileges) do
|
for priv_name, def in pairs(core.registered_privileges) do
|
||||||
privs[#privs + 1] = { name, def }
|
privs[#privs + 1] = { priv_name, def }
|
||||||
end
|
end
|
||||||
table.sort(privs, function(a, b) return a[1] < b[1] end)
|
table.sort(privs, function(a, b) return a[1] < b[1] end)
|
||||||
|
|
||||||
|
@ -128,6 +128,7 @@ function dump(o, indent, nested, level)
|
|||||||
if t ~= "table" then
|
if t ~= "table" then
|
||||||
return basic_dump(o)
|
return basic_dump(o)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Contains table -> true/nil of currently nested tables
|
-- Contains table -> true/nil of currently nested tables
|
||||||
nested = nested or {}
|
nested = nested or {}
|
||||||
if nested[o] then
|
if nested[o] then
|
||||||
@ -136,10 +137,11 @@ function dump(o, indent, nested, level)
|
|||||||
nested[o] = true
|
nested[o] = true
|
||||||
indent = indent or "\t"
|
indent = indent or "\t"
|
||||||
level = level or 1
|
level = level or 1
|
||||||
local t = {}
|
|
||||||
|
local ret = {}
|
||||||
local dumped_indexes = {}
|
local dumped_indexes = {}
|
||||||
for i, v in ipairs(o) do
|
for i, v in ipairs(o) do
|
||||||
t[#t + 1] = dump(v, indent, nested, level + 1)
|
ret[#ret + 1] = dump(v, indent, nested, level + 1)
|
||||||
dumped_indexes[i] = true
|
dumped_indexes[i] = true
|
||||||
end
|
end
|
||||||
for k, v in pairs(o) do
|
for k, v in pairs(o) do
|
||||||
@ -148,7 +150,7 @@ function dump(o, indent, nested, level)
|
|||||||
k = "["..dump(k, indent, nested, level + 1).."]"
|
k = "["..dump(k, indent, nested, level + 1).."]"
|
||||||
end
|
end
|
||||||
v = dump(v, indent, nested, level + 1)
|
v = dump(v, indent, nested, level + 1)
|
||||||
t[#t + 1] = k.." = "..v
|
ret[#ret + 1] = k.." = "..v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
nested[o] = nil
|
nested[o] = nil
|
||||||
@ -157,10 +159,10 @@ function dump(o, indent, nested, level)
|
|||||||
local end_indent_str = "\n"..string.rep(indent, level - 1)
|
local end_indent_str = "\n"..string.rep(indent, level - 1)
|
||||||
return string.format("{%s%s%s}",
|
return string.format("{%s%s%s}",
|
||||||
indent_str,
|
indent_str,
|
||||||
table.concat(t, ","..indent_str),
|
table.concat(ret, ","..indent_str),
|
||||||
end_indent_str)
|
end_indent_str)
|
||||||
end
|
end
|
||||||
return "{"..table.concat(t, ", ").."}"
|
return "{"..table.concat(ret, ", ").."}"
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -407,9 +409,8 @@ if INIT == "game" then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local old_itemstack = ItemStack(itemstack)
|
local old_itemstack = ItemStack(itemstack)
|
||||||
local new_itemstack, removed = core.item_place_node(
|
local new_itemstack = core.item_place_node(itemstack, placer,
|
||||||
itemstack, placer, pointed_thing, param2, prevent_after_place
|
pointed_thing, param2, prevent_after_place)
|
||||||
)
|
|
||||||
return infinitestacks and old_itemstack or new_itemstack
|
return infinitestacks and old_itemstack or new_itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -218,4 +218,3 @@ test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
|
|||||||
test_out = core.deserialize(core.serialize(test_in))
|
test_out = core.deserialize(core.serialize(test_in))
|
||||||
assert(test_in.escape_chars == test_out.escape_chars)
|
assert(test_in.escape_chars == test_out.escape_chars)
|
||||||
assert(test_in.non_european == test_out.non_european)
|
assert(test_in.non_european == test_out.non_european)
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ core.register_on_chat_message(function(name, message)
|
|||||||
local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
|
local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
|
||||||
if has_privs then
|
if has_privs then
|
||||||
core.set_last_run_mod(cmd_def.mod_origin)
|
core.set_last_run_mod(cmd_def.mod_origin)
|
||||||
local success, message = cmd_def.func(name, param)
|
local _, result = cmd_def.func(name, param)
|
||||||
if message then
|
if result then
|
||||||
core.chat_send_player(name, message)
|
core.chat_send_player(name, message)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -261,11 +261,12 @@ core.register_chatcommand("setpassword", {
|
|||||||
toname = param:match("^([^ ]+) *$")
|
toname = param:match("^([^ ]+) *$")
|
||||||
raw_password = nil
|
raw_password = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if not toname then
|
if not toname then
|
||||||
return false, "Name field required"
|
return false, "Name field required"
|
||||||
end
|
end
|
||||||
local act_str_past = "?"
|
|
||||||
local act_str_pres = "?"
|
local act_str_past, act_str_pres
|
||||||
if not raw_password then
|
if not raw_password then
|
||||||
core.set_player_password(toname, "")
|
core.set_player_password(toname, "")
|
||||||
act_str_past = "cleared"
|
act_str_past = "cleared"
|
||||||
@ -277,13 +278,14 @@ core.register_chatcommand("setpassword", {
|
|||||||
act_str_past = "set"
|
act_str_past = "set"
|
||||||
act_str_pres = "sets"
|
act_str_pres = "sets"
|
||||||
end
|
end
|
||||||
|
|
||||||
if toname ~= name then
|
if toname ~= name then
|
||||||
core.chat_send_player(toname, "Your password was "
|
core.chat_send_player(toname, "Your password was "
|
||||||
.. act_str_past .. " by " .. name)
|
.. act_str_past .. " by " .. name)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.log("action", name .. " " .. act_str_pres
|
core.log("action", name .. " " .. act_str_pres ..
|
||||||
.. " password of " .. toname .. ".")
|
" password of " .. toname .. ".")
|
||||||
|
|
||||||
return true, "Password of player \"" .. toname .. "\" " .. act_str_past
|
return true, "Password of player \"" .. toname .. "\" " .. act_str_past
|
||||||
end,
|
end,
|
||||||
@ -367,35 +369,35 @@ core.register_chatcommand("teleport", {
|
|||||||
return pos, false
|
return pos, false
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
|
||||||
local p = {}
|
local p = {}
|
||||||
p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
||||||
p.x = tonumber(p.x)
|
p.x = tonumber(p.x)
|
||||||
p.y = tonumber(p.y)
|
p.y = tonumber(p.y)
|
||||||
p.z = tonumber(p.z)
|
p.z = tonumber(p.z)
|
||||||
if p.x and p.y and p.z then
|
if p.x and p.y and p.z then
|
||||||
|
|
||||||
local lm = 31000
|
local lm = 31000
|
||||||
if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then
|
if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then
|
||||||
return false, "Cannot teleport out of map bounds!"
|
return false, "Cannot teleport out of map bounds!"
|
||||||
end
|
end
|
||||||
teleportee = core.get_player_by_name(name)
|
local teleportee = core.get_player_by_name(name)
|
||||||
if teleportee then
|
if teleportee then
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
return true, "Teleporting to "..core.pos_to_string(p)
|
return true, "Teleporting to "..core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
local target_name = param:match("^([^ ]+)$")
|
||||||
local p = nil
|
local teleportee = core.get_player_by_name(name)
|
||||||
local target_name = nil
|
|
||||||
target_name = param:match("^([^ ]+)$")
|
p = nil
|
||||||
teleportee = core.get_player_by_name(name)
|
|
||||||
if target_name then
|
if target_name then
|
||||||
local target = core.get_player_by_name(target_name)
|
local target = core.get_player_by_name(target_name)
|
||||||
if target then
|
if target then
|
||||||
p = target:get_pos()
|
p = target:get_pos()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if teleportee and p then
|
if teleportee and p then
|
||||||
p = find_free_position_near(p)
|
p = find_free_position_near(p)
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
@ -407,9 +409,9 @@ core.register_chatcommand("teleport", {
|
|||||||
return false, "You don't have permission to teleport other players (missing bring privilege)"
|
return false, "You don't have permission to teleport other players (missing bring privilege)"
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
teleportee = nil
|
||||||
local p = {}
|
p = {}
|
||||||
local teleportee_name = nil
|
local teleportee_name
|
||||||
teleportee_name, p.x, p.y, p.z = param:match(
|
teleportee_name, p.x, p.y, p.z = param:match(
|
||||||
"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
||||||
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
|
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
|
||||||
@ -422,10 +424,8 @@ core.register_chatcommand("teleport", {
|
|||||||
.. " to " .. core.pos_to_string(p)
|
.. " to " .. core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
teleportee = nil
|
||||||
local p = nil
|
p = nil
|
||||||
local teleportee_name = nil
|
|
||||||
local target_name = nil
|
|
||||||
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
|
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
|
||||||
if teleportee_name then
|
if teleportee_name then
|
||||||
teleportee = core.get_player_by_name(teleportee_name)
|
teleportee = core.get_player_by_name(teleportee_name)
|
||||||
@ -459,7 +459,8 @@ core.register_chatcommand("set", {
|
|||||||
core.settings:set(setname, setvalue)
|
core.settings:set(setname, setvalue)
|
||||||
return true, setname .. " = " .. setvalue
|
return true, setname .. " = " .. setvalue
|
||||||
end
|
end
|
||||||
local setname, setvalue = string.match(param, "([^ ]+) (.+)")
|
|
||||||
|
setname, setvalue = string.match(param, "([^ ]+) (.+)")
|
||||||
if setname and setvalue then
|
if setname and setvalue then
|
||||||
if not core.settings:get(setname) then
|
if not core.settings:get(setname) then
|
||||||
return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
|
return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
|
||||||
@ -467,14 +468,16 @@ core.register_chatcommand("set", {
|
|||||||
core.settings:set(setname, setvalue)
|
core.settings:set(setname, setvalue)
|
||||||
return true, setname .. " = " .. setvalue
|
return true, setname .. " = " .. setvalue
|
||||||
end
|
end
|
||||||
local setname = string.match(param, "([^ ]+)")
|
|
||||||
|
setname = string.match(param, "([^ ]+)")
|
||||||
if setname then
|
if setname then
|
||||||
local setvalue = core.settings:get(setname)
|
setvalue = core.settings:get(setname)
|
||||||
if not setvalue then
|
if not setvalue then
|
||||||
setvalue = "<not set>"
|
setvalue = "<not set>"
|
||||||
end
|
end
|
||||||
return true, setname .. " = " .. setvalue
|
return true, setname .. " = " .. setvalue
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, "Invalid parameters (see /help set)."
|
return false, "Invalid parameters (see /help set)."
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -771,7 +774,7 @@ core.register_chatcommand("rollback", {
|
|||||||
end
|
end
|
||||||
local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
|
local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
|
||||||
if not target_name then
|
if not target_name then
|
||||||
local player_name = nil
|
local player_name
|
||||||
player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
|
player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
|
||||||
if not player_name then
|
if not player_name then
|
||||||
return false, "Invalid parameters. See /help rollback"
|
return false, "Invalid parameters. See /help rollback"
|
||||||
|
@ -206,7 +206,6 @@ function core.get_node_drops(node, toolname)
|
|||||||
-- Extended drop table
|
-- Extended drop table
|
||||||
local got_items = {}
|
local got_items = {}
|
||||||
local got_count = 0
|
local got_count = 0
|
||||||
local _, item, tool
|
|
||||||
for _, item in ipairs(drop.items) do
|
for _, item in ipairs(drop.items) do
|
||||||
local good_rarity = true
|
local good_rarity = true
|
||||||
local good_tool = true
|
local good_tool = true
|
||||||
@ -614,15 +613,10 @@ function core.node_dig(pos, node, digger)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
local _, callback
|
|
||||||
for _, callback in ipairs(core.registered_on_dignodes) do
|
for _, callback in ipairs(core.registered_on_dignodes) do
|
||||||
local origin = core.callback_origins[callback]
|
local origin = core.callback_origins[callback]
|
||||||
if origin then
|
if origin then
|
||||||
core.set_last_run_mod(origin.mod)
|
core.set_last_run_mod(origin.mod)
|
||||||
--print("Running " .. tostring(callback) ..
|
|
||||||
-- " (a " .. origin.name .. " callback in " .. origin.mod .. ")")
|
|
||||||
else
|
|
||||||
--print("No data associated with callback")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Copy pos and node because callback can modify them
|
-- Copy pos and node because callback can modify them
|
||||||
|
@ -62,7 +62,7 @@ end
|
|||||||
core.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
player_list[player_name] = player
|
player_list[player_name] = player
|
||||||
if not minetest.is_singleplayer() then
|
if not core.is_singleplayer() then
|
||||||
local status = core.get_server_status(player_name, true)
|
local status = core.get_server_status(player_name, true)
|
||||||
if status and status ~= "" then
|
if status and status ~= "" then
|
||||||
core.chat_send_player(player_name, status)
|
core.chat_send_player(player_name, status)
|
||||||
|
@ -18,7 +18,7 @@ function core.register_privilege(name, param)
|
|||||||
def.description = "(no description)"
|
def.description = "(no description)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local def = {}
|
local def
|
||||||
if type(param) == "table" then
|
if type(param) == "table" then
|
||||||
def = param
|
def = param
|
||||||
else
|
else
|
||||||
|
@ -303,7 +303,6 @@ end
|
|||||||
|
|
||||||
-- Alias the forbidden item names to "" so they can't be
|
-- Alias the forbidden item names to "" so they can't be
|
||||||
-- created via itemstrings (e.g. /give)
|
-- created via itemstrings (e.g. /give)
|
||||||
local name
|
|
||||||
for name in pairs(forbidden_item_names) do
|
for name in pairs(forbidden_item_names) do
|
||||||
core.registered_aliases[name] = ""
|
core.registered_aliases[name] = ""
|
||||||
register_alias_raw(name, "")
|
register_alias_raw(name, "")
|
||||||
@ -363,9 +362,9 @@ core.register_node(":ignore", {
|
|||||||
drop = "",
|
drop = "",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
minetest.chat_send_player(
|
core.chat_send_player(
|
||||||
placer:get_player_name(),
|
placer:get_player_name(),
|
||||||
minetest.colorize("#FF0000",
|
core.colorize("#FF0000",
|
||||||
"You can't place 'ignore' nodes!"))
|
"You can't place 'ignore' nodes!"))
|
||||||
return ""
|
return ""
|
||||||
end,
|
end,
|
||||||
@ -413,10 +412,6 @@ function core.run_callbacks(callbacks, mode, ...)
|
|||||||
local origin = core.callback_origins[callbacks[i]]
|
local origin = core.callback_origins[callbacks[i]]
|
||||||
if origin then
|
if origin then
|
||||||
core.set_last_run_mod(origin.mod)
|
core.set_last_run_mod(origin.mod)
|
||||||
--print("Running " .. tostring(callbacks[i]) ..
|
|
||||||
-- " (a " .. origin.name .. " callback in " .. origin.mod .. ")")
|
|
||||||
else
|
|
||||||
--print("No data associated with callback")
|
|
||||||
end
|
end
|
||||||
local cb_ret = callbacks[i](...)
|
local cb_ret = callbacks[i](...)
|
||||||
|
|
||||||
@ -537,7 +532,7 @@ end
|
|||||||
core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } }
|
core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } }
|
||||||
|
|
||||||
function core.registered_on_player_hpchange(player, hp_change, reason)
|
function core.registered_on_player_hpchange(player, hp_change, reason)
|
||||||
local last = false
|
local last
|
||||||
for i = #core.registered_on_player_hpchanges.modifiers, 1, -1 do
|
for i = #core.registered_on_player_hpchanges.modifiers, 1, -1 do
|
||||||
local func = core.registered_on_player_hpchanges.modifiers[i]
|
local func = core.registered_on_player_hpchanges.modifiers[i]
|
||||||
hp_change, last = func(player, hp_change, reason)
|
hp_change, last = func(player, hp_change, reason)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
-- cache setting
|
-- cache setting
|
||||||
local enable_damage = core.settings:get_bool("enable_damage")
|
local enable_damage = core.settings:get_bool("enable_damage")
|
||||||
|
|
||||||
local health_bar_definition =
|
local health_bar_definition = {
|
||||||
{
|
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
position = { x=0.5, y=1 },
|
position = { x=0.5, y=1 },
|
||||||
text = "heart.png",
|
text = "heart.png",
|
||||||
@ -12,8 +11,7 @@ local health_bar_definition =
|
|||||||
offset = { x=(-10*24)-25, y=-(48+24+16)},
|
offset = { x=(-10*24)-25, y=-(48+24+16)},
|
||||||
}
|
}
|
||||||
|
|
||||||
local breath_bar_definition =
|
local breath_bar_definition = {
|
||||||
{
|
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
position = { x=0.5, y=1 },
|
position = { x=0.5, y=1 },
|
||||||
text = "bubble.png",
|
text = "bubble.png",
|
||||||
@ -125,14 +123,14 @@ local function player_event_handler(player,eventname)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.hud_replace_builtin(name, definition)
|
function core.hud_replace_builtin(hud_name, definition)
|
||||||
|
|
||||||
if type(definition) ~= "table" or
|
if type(definition) ~= "table" or
|
||||||
definition.hud_elem_type ~= "statbar" then
|
definition.hud_elem_type ~= "statbar" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if name == "health" then
|
if hud_name == "health" then
|
||||||
health_bar_definition = definition
|
health_bar_definition = definition
|
||||||
|
|
||||||
for name, ids in pairs(hud_ids) do
|
for name, ids in pairs(hud_ids) do
|
||||||
@ -146,7 +144,7 @@ function core.hud_replace_builtin(name, definition)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if name == "breath" then
|
if hud_name == "breath" then
|
||||||
breath_bar_definition = definition
|
breath_bar_definition = definition
|
||||||
|
|
||||||
for name, ids in pairs(hud_ids) do
|
for name, ids in pairs(hud_ids) do
|
||||||
|
@ -93,9 +93,9 @@ function render_serverlist_row(spec, is_favorite)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local details = ""
|
|
||||||
local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
|
local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
|
||||||
|
|
||||||
|
local details
|
||||||
if is_favorite then
|
if is_favorite then
|
||||||
details = "1,"
|
details = "1,"
|
||||||
else
|
else
|
||||||
@ -118,11 +118,11 @@ function render_serverlist_row(spec, is_favorite)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if spec.clients and spec.clients_max then
|
if spec.clients and spec.clients_max then
|
||||||
local clients_color = ''
|
|
||||||
local clients_percent = 100 * spec.clients / spec.clients_max
|
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||||
|
|
||||||
-- Choose a color depending on how many clients are connected
|
-- Choose a color depending on how many clients are connected
|
||||||
-- (relatively to clients_max)
|
-- (relatively to clients_max)
|
||||||
|
local clients_color
|
||||||
if grey_out then clients_color = '#aaaaaa'
|
if grey_out then clients_color = '#aaaaaa'
|
||||||
elseif spec.clients == 0 then clients_color = '' -- 0 players: default/white
|
elseif spec.clients == 0 then clients_color = '' -- 0 players: default/white
|
||||||
elseif clients_percent <= 60 then clients_color = '#a1e587' -- 0-60%: green
|
elseif clients_percent <= 60 then clients_color = '#a1e587' -- 0-60%: green
|
||||||
@ -171,6 +171,7 @@ os.tempfolder = function()
|
|||||||
local filetocheck = os.tmpname()
|
local filetocheck = os.tmpname()
|
||||||
os.remove(filetocheck)
|
os.remove(filetocheck)
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
-- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/
|
-- 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.
|
-- The C runtime (CRT) function called by os.tmpname is tmpnam.
|
||||||
-- Microsofts tmpnam implementation in older CRT / MSVC releases is defective.
|
-- Microsofts tmpnam implementation in older CRT / MSVC releases is defective.
|
||||||
|
@ -270,7 +270,6 @@ function store.load()
|
|||||||
assert(core.create_dir(tmpdir))
|
assert(core.create_dir(tmpdir))
|
||||||
|
|
||||||
local base_url = core.settings:get("contentdb_url")
|
local base_url = core.settings:get("contentdb_url")
|
||||||
local show_nonfree = core.settings:get_bool("show_nonfree_packages")
|
|
||||||
local url = base_url ..
|
local url = base_url ..
|
||||||
"/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
|
"/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
|
||||||
core.get_max_supp_proto()
|
core.get_max_supp_proto()
|
||||||
|
@ -24,9 +24,9 @@ local function create_world_formspec(dialogdata)
|
|||||||
local current_mg = core.settings:get("mg_name")
|
local current_mg = core.settings:get("mg_name")
|
||||||
local gameid = core.settings:get("menu_last_game")
|
local gameid = core.settings:get("menu_last_game")
|
||||||
|
|
||||||
local game, gameidx = nil , 0
|
local gameidx = 0
|
||||||
if gameid ~= nil then
|
if gameid ~= nil then
|
||||||
game, gameidx = pkgmgr.find_by_gameid(gameid)
|
_, gameidx = pkgmgr.find_by_gameid(gameid)
|
||||||
|
|
||||||
if gameidx == nil then
|
if gameidx == nil then
|
||||||
gameidx = 0
|
gameidx = 0
|
||||||
@ -111,10 +111,10 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
local random_world_name = "Unnamed" .. random_number
|
local random_world_name = "Unnamed" .. random_number
|
||||||
worldname = random_world_name
|
worldname = random_world_name
|
||||||
end
|
end
|
||||||
local message = nil
|
|
||||||
|
|
||||||
core.settings:set("fixed_map_seed", fields["te_seed"])
|
core.settings:set("fixed_map_seed", fields["te_seed"])
|
||||||
|
|
||||||
|
local message
|
||||||
if not menudata.worldlist:uid_exists_raw(worldname) then
|
if not menudata.worldlist:uid_exists_raw(worldname) then
|
||||||
core.settings:set("mg_name",fields["dd_mapgen"])
|
core.settings:set("mg_name",fields["dd_mapgen"])
|
||||||
message = core.create_world(worldname,gameindex)
|
message = core.create_world(worldname,gameindex)
|
||||||
|
@ -148,9 +148,9 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
|
|||||||
local values = {}
|
local values = {}
|
||||||
local ti = 1
|
local ti = 1
|
||||||
local index = 1
|
local index = 1
|
||||||
for line in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
|
for match in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
|
||||||
index = default:find("[+-]?[%d.-e]+", index) + line:len()
|
index = default:find("[+-]?[%d.-e]+", index) + match:len()
|
||||||
table.insert(values, line)
|
table.insert(values, match)
|
||||||
ti = ti + 1
|
ti = ti + 1
|
||||||
if ti > 9 then
|
if ti > 9 then
|
||||||
break
|
break
|
||||||
@ -322,9 +322,11 @@ end
|
|||||||
-- read_all: whether to ignore certain setting types for GUI or not
|
-- read_all: whether to ignore certain setting types for GUI or not
|
||||||
-- parse_mods: whether to parse settingtypes.txt in mods and games
|
-- parse_mods: whether to parse settingtypes.txt in mods and games
|
||||||
local function parse_config_file(read_all, parse_mods)
|
local function parse_config_file(read_all, parse_mods)
|
||||||
|
local settings = {}
|
||||||
|
|
||||||
|
do
|
||||||
local builtin_path = core.get_builtin_path() .. FILENAME
|
local builtin_path = core.get_builtin_path() .. FILENAME
|
||||||
local file = io.open(builtin_path, "r")
|
local file = io.open(builtin_path, "r")
|
||||||
local settings = {}
|
|
||||||
if not file then
|
if not file then
|
||||||
core.log("error", "Can't load " .. FILENAME)
|
core.log("error", "Can't load " .. FILENAME)
|
||||||
return settings
|
return settings
|
||||||
@ -333,6 +335,7 @@ local function parse_config_file(read_all, parse_mods)
|
|||||||
parse_single_file(file, builtin_path, read_all, settings, 0, true)
|
parse_single_file(file, builtin_path, read_all, settings, 0, true)
|
||||||
|
|
||||||
file:close()
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
if parse_mods then
|
if parse_mods then
|
||||||
-- Parse games
|
-- Parse games
|
||||||
@ -344,7 +347,7 @@ local function parse_config_file(read_all, parse_mods)
|
|||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
if file then
|
if file then
|
||||||
if not games_category_initialized then
|
if not games_category_initialized then
|
||||||
local translation = fgettext_ne("Games"), -- not used, but needed for xgettext
|
fgettext_ne("Games") -- not used, but needed for xgettext
|
||||||
table.insert(settings, {
|
table.insert(settings, {
|
||||||
name = "Games",
|
name = "Games",
|
||||||
level = 0,
|
level = 0,
|
||||||
@ -377,7 +380,7 @@ local function parse_config_file(read_all, parse_mods)
|
|||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
if file then
|
if file then
|
||||||
if not mods_category_initialized then
|
if not mods_category_initialized then
|
||||||
local translation = fgettext_ne("Mods"), -- not used, but needed for xgettext
|
fgettext_ne("Mods") -- not used, but needed for xgettext
|
||||||
table.insert(settings, {
|
table.insert(settings, {
|
||||||
name = "Mods",
|
name = "Mods",
|
||||||
level = 0,
|
level = 0,
|
||||||
@ -753,7 +756,7 @@ local function create_change_setting_formspec(dialogdata)
|
|||||||
" (" .. setting.name .. ")"
|
" (" .. setting.name .. ")"
|
||||||
end
|
end
|
||||||
|
|
||||||
local comment_text = ""
|
local comment_text
|
||||||
if setting.comment == "" then
|
if setting.comment == "" then
|
||||||
comment_text = fgettext_ne("(No description of setting given)")
|
comment_text = fgettext_ne("(No description of setting given)")
|
||||||
else
|
else
|
||||||
@ -918,7 +921,7 @@ local function handle_change_setting_buttons(this, fields)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_settings_formspec(tabview, name, tabdata)
|
local function create_settings_formspec(tabview, _, tabdata)
|
||||||
local formspec = "size[12,5.4;true]" ..
|
local formspec = "size[12,5.4;true]" ..
|
||||||
"tablecolumns[color;tree;text,width=28;text]" ..
|
"tablecolumns[color;tree;text,width=28;text]" ..
|
||||||
"tableoptions[background=#00000000;border=false]" ..
|
"tableoptions[background=#00000000;border=false]" ..
|
||||||
@ -950,7 +953,7 @@ local function create_settings_formspec(tabview, name, tabdata)
|
|||||||
formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
|
formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
|
||||||
.. value .. ","
|
.. value .. ","
|
||||||
|
|
||||||
elseif entry.type == "key" then
|
elseif entry.type == "key" then --luacheck: ignore
|
||||||
-- ignore key settings, since we have a special dialog for them
|
-- ignore key settings, since we have a special dialog for them
|
||||||
|
|
||||||
elseif entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then
|
elseif entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then
|
||||||
@ -1029,8 +1032,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
|
|||||||
if fields["btn_edit"] or list_enter then
|
if fields["btn_edit"] or list_enter then
|
||||||
local setting = settings[selected_setting]
|
local setting = settings[selected_setting]
|
||||||
if setting and setting.type ~= "category" then
|
if setting and setting.type ~= "category" then
|
||||||
local edit_dialog = dialog_create("change_setting", create_change_setting_formspec,
|
local edit_dialog = dialog_create("change_setting",
|
||||||
handle_change_setting_buttons)
|
create_change_setting_formspec, handle_change_setting_buttons)
|
||||||
edit_dialog:set_parent(this)
|
edit_dialog:set_parent(this)
|
||||||
this:hide()
|
this:hide()
|
||||||
edit_dialog:show()
|
edit_dialog:show()
|
||||||
@ -1076,4 +1079,5 @@ end
|
|||||||
-- For RUN_IN_PLACE the generated files may appear in the 'bin' folder.
|
-- For RUN_IN_PLACE the generated files may appear in the 'bin' folder.
|
||||||
-- See comment and alternative line at the end of 'generate_from_settingtypes.lua'.
|
-- See comment and alternative line at the end of 'generate_from_settingtypes.lua'.
|
||||||
|
|
||||||
--assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))
|
--assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM..
|
||||||
|
-- "generate_from_settingtypes.lua"))(parse_config_file(true, false))
|
||||||
|
@ -285,8 +285,6 @@ function pkgmgr.identify_modname(modpath,filename)
|
|||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function pkgmgr.render_packagelist(render_list)
|
function pkgmgr.render_packagelist(render_list)
|
||||||
local retval = ""
|
|
||||||
|
|
||||||
if render_list == nil then
|
if render_list == nil then
|
||||||
if pkgmgr.global_mods == nil then
|
if pkgmgr.global_mods == nil then
|
||||||
pkgmgr.refresh_globals()
|
pkgmgr.refresh_globals()
|
||||||
@ -295,7 +293,6 @@ function pkgmgr.render_packagelist(render_list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local list = render_list:get_list()
|
local list = render_list:get_list()
|
||||||
local last_modpack = nil
|
|
||||||
local retval = {}
|
local retval = {}
|
||||||
for i, v in ipairs(list) do
|
for i, v in ipairs(list) do
|
||||||
local color = ""
|
local color = ""
|
||||||
@ -465,7 +462,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
|
|||||||
else
|
else
|
||||||
return nil,
|
return nil,
|
||||||
fgettext("Install Mod: Unable to find suitable folder name for modpack $1",
|
fgettext("Install Mod: Unable to find suitable folder name for modpack $1",
|
||||||
modfilename)
|
path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif basefolder.type == "mod" then
|
elseif basefolder.type == "mod" then
|
||||||
@ -490,7 +487,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
|
|||||||
if targetfolder ~= nil and pkgmgr.isValidModname(targetfolder) then
|
if targetfolder ~= nil and pkgmgr.isValidModname(targetfolder) then
|
||||||
targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
|
targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
|
||||||
else
|
else
|
||||||
return nil, fgettext("Install Mod: Unable to find real mod name for: $1", modfilename)
|
return nil, fgettext("Install Mod: Unable to find real mod name for: $1", path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ local current_game, singleplayer_refresh_gamebar
|
|||||||
if enable_gamebar then
|
if enable_gamebar then
|
||||||
function current_game()
|
function current_game()
|
||||||
local last_game_id = core.settings:get("menu_last_game")
|
local last_game_id = core.settings:get("menu_last_game")
|
||||||
local game, index = pkgmgr.find_by_gameid(last_game_id)
|
local game = pkgmgr.find_by_gameid(last_game_id)
|
||||||
|
|
||||||
return game
|
return game
|
||||||
end
|
end
|
||||||
@ -222,7 +222,7 @@ local function main_button_handler(this, fields, name, tabdata)
|
|||||||
--update last game
|
--update last game
|
||||||
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
||||||
if world then
|
if world then
|
||||||
local game, index = pkgmgr.find_by_gameid(world.gameid)
|
local game = pkgmgr.find_by_gameid(world.gameid)
|
||||||
core.settings:set("menu_last_game", game.id)
|
core.settings:set("menu_last_game", game.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
-- Update the cached supported proto info,
|
-- Update the cached supported proto info,
|
||||||
-- it may have changed after a change by the settings menu.
|
-- it may have changed after a change by the settings menu.
|
||||||
common_update_cached_supp_proto()
|
common_update_cached_supp_proto()
|
||||||
local fav_selected = nil
|
local fav_selected
|
||||||
if menudata.search_result then
|
if menudata.search_result then
|
||||||
fav_selected = menudata.search_result[tabdata.fav_selected]
|
fav_selected = menudata.search_result[tabdata.fav_selected]
|
||||||
else
|
else
|
||||||
@ -273,8 +273,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
for k = 1, #keywords do
|
for k = 1, #keywords do
|
||||||
local keyword = keywords[k]
|
local keyword = keywords[k]
|
||||||
if server.name then
|
if server.name then
|
||||||
local name = server.name:lower()
|
local sername = server.name:lower()
|
||||||
local _, count = name:gsub(keyword, keyword)
|
local _, count = sername:gsub(keyword, keyword)
|
||||||
found = found + count * 4
|
found = found + count * 4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,11 +148,9 @@ local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
|
|||||||
|
|
||||||
core.create_world("singleplayerworld", 1)
|
core.create_world("singleplayerworld", 1)
|
||||||
worldlist = core.get_worlds()
|
worldlist = core.get_worlds()
|
||||||
found_singleplayerworld = false
|
|
||||||
|
|
||||||
for i = 1, #worldlist do
|
for i = 1, #worldlist do
|
||||||
if worldlist[i].name == "singleplayerworld" then
|
if worldlist[i].name == "singleplayerworld" then
|
||||||
found_singleplayerworld = true
|
|
||||||
gamedata.worldindex = i
|
gamedata.worldindex = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -117,7 +117,8 @@ end
|
|||||||
local function assert_can_be_called(func, func_name, level)
|
local function assert_can_be_called(func, func_name, level)
|
||||||
if not can_be_called(func) then
|
if not can_be_called(func) then
|
||||||
-- Then throw an *helpful* error, by pointing on our caller instead of us.
|
-- 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user