mirror of
https://github.com/minetest-mods/more_chests.git
synced 2026-07-06 10:36:52 -06:00
Localize global variables and strengthen luacheck config (#34)
This commit is contained in:
+2
-20
@@ -1,25 +1,7 @@
|
||||
std = "lua51+minetest"
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
max_line_length = 999
|
||||
|
||||
stds.minetest = {
|
||||
read_globals = {
|
||||
"minetest",
|
||||
"VoxelManip",
|
||||
"VoxelArea",
|
||||
"PseudoRandom",
|
||||
"ItemStack",
|
||||
"default",
|
||||
table = {
|
||||
fields = {
|
||||
"copy",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
"minetest",
|
||||
"default",
|
||||
"pipeworks",
|
||||
}
|
||||
|
||||
|
||||
+22
-23
@@ -1,17 +1,18 @@
|
||||
local function get_inventory_auth_string(player, meta, pos, label)
|
||||
return player:get_player_name() .. " tried to access a locked " .. label .. " belonging to " .. meta:get_string("owner") .. " at " .. minetest.pos_to_string(pos)
|
||||
local name = player:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
return ("%s tried to access a locked %s belonging to %s at %s"):format(name, label, owner, pos_str)
|
||||
end
|
||||
|
||||
|
||||
function has_locked_chest_privilege(meta, player)
|
||||
local function has_locked_chest_privilege(meta, player)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function get_allow_metadata_inventory_move(t)
|
||||
local function get_allow_metadata_inventory_move(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
@@ -24,7 +25,7 @@ function get_allow_metadata_inventory_move(t)
|
||||
end
|
||||
end
|
||||
|
||||
function get_allow_metadata_inventory_put(t)
|
||||
local function get_allow_metadata_inventory_put(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, listname, index, stack, player)
|
||||
@@ -37,7 +38,7 @@ function get_allow_metadata_inventory_put(t)
|
||||
end
|
||||
end
|
||||
|
||||
function get_allow_metadata_inventory_take(t)
|
||||
local function get_allow_metadata_inventory_take(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, listname, index, stack, player)
|
||||
@@ -50,41 +51,39 @@ function get_allow_metadata_inventory_take(t)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function get_inventory_action_string(player, pos, action, label)
|
||||
return player:get_player_name() .. " moves stuff " .. action .. " locked " .. label .. " at " .. minetest.pos_to_string(pos)
|
||||
local name = player:get_player_name()
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
return ("%s moves stuff %s locked %s at %s"):format(name, action, label, pos_str)
|
||||
end
|
||||
|
||||
|
||||
function get_on_metadata_inventory_move(label)
|
||||
local function get_on_metadata_inventory_move(label)
|
||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "in", label)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function get_on_metadata_inventory_put(label)
|
||||
local function get_on_metadata_inventory_put(label)
|
||||
return function(pos, listname, index, stack, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "to", label))
|
||||
end
|
||||
end
|
||||
|
||||
function get_on_metadata_inventory_take(label)
|
||||
local function get_on_metadata_inventory_take(label)
|
||||
return function(pos, listname, index, stack, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "from", label))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
actions = {
|
||||
has_locked_chest_privilege = has_locked_chest_privilege,
|
||||
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
||||
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
||||
get_allow_metadata_inventory_take = get_allow_metadata_inventory_take,
|
||||
get_on_metadata_inventory_move = get_on_metadata_inventory_move,
|
||||
get_on_metadata_inventory_put = get_on_metadata_inventory_put,
|
||||
get_on_metadata_inventory_take = get_on_metadata_inventory_take,
|
||||
local actions = {
|
||||
has_locked_chest_privilege = has_locked_chest_privilege,
|
||||
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
||||
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
||||
get_allow_metadata_inventory_take = get_allow_metadata_inventory_take,
|
||||
get_on_metadata_inventory_move = get_on_metadata_inventory_move,
|
||||
get_on_metadata_inventory_put = get_on_metadata_inventory_put,
|
||||
get_on_metadata_inventory_take = get_on_metadata_inventory_take,
|
||||
}
|
||||
return actions
|
||||
|
||||
+14
-8
@@ -1,6 +1,6 @@
|
||||
-- NOTE: `require` is not allowed with mod security on
|
||||
-- `dofile` with a return on the module is used instead
|
||||
generate_formspec_string = dofile(minetest.get_modpath("more_chests").."/utils/formspec.lua")
|
||||
local generate_formspec_string = dofile(minetest.get_modpath("more_chests").."/utils/formspec.lua")
|
||||
local actions = dofile(minetest.get_modpath("more_chests").."/utils/actions.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
@@ -14,7 +14,7 @@ local function parse_action(value, default_getter)
|
||||
end
|
||||
end
|
||||
|
||||
function generate_chest_def(def)
|
||||
local function generate_chest_def(def)
|
||||
-- TODO assert def.size in ("big", "small")
|
||||
local out = {
|
||||
description = def.description,
|
||||
@@ -59,12 +59,18 @@ function generate_chest_def(def)
|
||||
end,
|
||||
}
|
||||
-- register log actions, NOTE passing an anonymous function to avoid getting the default if not necessary
|
||||
out.allow_metadata_inventory_move = parse_action(def.allow_metadata_inventory_move, function() actions.get_allow_metadata_inventory_move{def.type} end)
|
||||
out.allow_metadata_inventory_put = parse_action(def.allow_metadata_inventory_put, function() actions.get_allow_metadata_inventory_put{def.type} end)
|
||||
out.allow_metadata_inventory_take = parse_action(def.allow_metadata_inventory_take, function() actions.get_allow_metadata_inventory_take{def.type} end)
|
||||
out.on_metadata_inventory_move = parse_action(def.on_metadata_inventory_move, function() actions.get_on_metadata_inventory_move(def.type) end)
|
||||
out.on_metadata_inventory_put = parse_action(def.on_metadata_inventory_put, function() actions.get_on_metadata_inventory_put(def.type) end)
|
||||
out.on_metadata_inventory_take = parse_action(def.on_metadata_inventory_take, function() actions.get_on_metadata_inventory_take(def.type) end)
|
||||
out.allow_metadata_inventory_move = parse_action(def.allow_metadata_inventory_move,
|
||||
function() actions.get_allow_metadata_inventory_move{def.type} end)
|
||||
out.allow_metadata_inventory_put = parse_action(def.allow_metadata_inventory_put,
|
||||
function() actions.get_allow_metadata_inventory_put{def.type} end)
|
||||
out.allow_metadata_inventory_take = parse_action(def.allow_metadata_inventory_take,
|
||||
function() actions.get_allow_metadata_inventory_take{def.type} end)
|
||||
out.on_metadata_inventory_move = parse_action(def.on_metadata_inventory_move,
|
||||
function() actions.get_on_metadata_inventory_move(def.type) end)
|
||||
out.on_metadata_inventory_put = parse_action(def.on_metadata_inventory_put,
|
||||
function() actions.get_on_metadata_inventory_put(def.type) end)
|
||||
out.on_metadata_inventory_take = parse_action(def.on_metadata_inventory_take,
|
||||
function() actions.get_on_metadata_inventory_take(def.type) end)
|
||||
-- if model is not a simple block handle node_box attribute
|
||||
if def.node_box then
|
||||
out.drawtype = "nodebox"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
function generate(size, inventory_name)
|
||||
local function generate(size, inventory_name)
|
||||
local cfg
|
||||
|
||||
-- chest inventory name
|
||||
|
||||
Reference in New Issue
Block a user