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:
-18
@@ -1,25 +1,7 @@
|
|||||||
std = "lua51+minetest"
|
|
||||||
unused_args = false
|
unused_args = false
|
||||||
allow_defined_top = true
|
|
||||||
max_line_length = 999
|
|
||||||
|
|
||||||
stds.minetest = {
|
|
||||||
read_globals = {
|
read_globals = {
|
||||||
"minetest",
|
"minetest",
|
||||||
"VoxelManip",
|
|
||||||
"VoxelArea",
|
|
||||||
"PseudoRandom",
|
|
||||||
"ItemStack",
|
|
||||||
"default",
|
"default",
|
||||||
table = {
|
|
||||||
fields = {
|
|
||||||
"copy",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
read_globals = {
|
|
||||||
"pipeworks",
|
"pipeworks",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-16
@@ -1,17 +1,18 @@
|
|||||||
local function get_inventory_auth_string(player, meta, pos, label)
|
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
|
end
|
||||||
|
|
||||||
|
local function has_locked_chest_privilege(meta, player)
|
||||||
function has_locked_chest_privilege(meta, player)
|
|
||||||
if player:get_player_name() ~= meta:get_string("owner") then
|
if player:get_player_name() ~= meta:get_string("owner") then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_allow_metadata_inventory_move(t)
|
||||||
function get_allow_metadata_inventory_move(t)
|
|
||||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||||
local label, check_privs = t[1], t.check_privs
|
local label, check_privs = t[1], t.check_privs
|
||||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
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
|
||||||
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}})
|
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||||
local label, check_privs = t[1], t.check_privs
|
local label, check_privs = t[1], t.check_privs
|
||||||
return function(pos, listname, index, stack, player)
|
return function(pos, listname, index, stack, player)
|
||||||
@@ -37,7 +38,7 @@ function get_allow_metadata_inventory_put(t)
|
|||||||
end
|
end
|
||||||
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}})
|
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||||
local label, check_privs = t[1], t.check_privs
|
local label, check_privs = t[1], t.check_privs
|
||||||
return function(pos, listname, index, stack, player)
|
return function(pos, listname, index, stack, player)
|
||||||
@@ -50,35 +51,33 @@ function get_allow_metadata_inventory_take(t)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function get_inventory_action_string(player, pos, action, label)
|
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
|
end
|
||||||
|
|
||||||
|
local function get_on_metadata_inventory_move(label)
|
||||||
function get_on_metadata_inventory_move(label)
|
|
||||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
minetest.log("action", get_inventory_action_string(player, pos, "in", label)
|
minetest.log("action", get_inventory_action_string(player, pos, "in", label)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_on_metadata_inventory_put(label)
|
local function get_on_metadata_inventory_put(label)
|
||||||
return function(pos, listname, index, stack, player)
|
return function(pos, listname, index, stack, player)
|
||||||
minetest.log("action", get_inventory_action_string(player, pos, "to", label))
|
minetest.log("action", get_inventory_action_string(player, pos, "to", label))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_on_metadata_inventory_take(label)
|
local function get_on_metadata_inventory_take(label)
|
||||||
return function(pos, listname, index, stack, player)
|
return function(pos, listname, index, stack, player)
|
||||||
minetest.log("action", get_inventory_action_string(player, pos, "from", label))
|
minetest.log("action", get_inventory_action_string(player, pos, "from", label))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local actions = {
|
||||||
actions = {
|
|
||||||
has_locked_chest_privilege = has_locked_chest_privilege,
|
has_locked_chest_privilege = has_locked_chest_privilege,
|
||||||
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
||||||
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
||||||
|
|||||||
+14
-8
@@ -1,6 +1,6 @@
|
|||||||
-- NOTE: `require` is not allowed with mod security on
|
-- NOTE: `require` is not allowed with mod security on
|
||||||
-- `dofile` with a return on the module is used instead
|
-- `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 actions = dofile(minetest.get_modpath("more_chests").."/utils/actions.lua")
|
||||||
local S = minetest.get_translator("more_chests")
|
local S = minetest.get_translator("more_chests")
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ local function parse_action(value, default_getter)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function generate_chest_def(def)
|
local function generate_chest_def(def)
|
||||||
-- TODO assert def.size in ("big", "small")
|
-- TODO assert def.size in ("big", "small")
|
||||||
local out = {
|
local out = {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
@@ -59,12 +59,18 @@ function generate_chest_def(def)
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
-- register log actions, NOTE passing an anonymous function to avoid getting the default if not necessary
|
-- 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_move = parse_action(def.allow_metadata_inventory_move,
|
||||||
out.allow_metadata_inventory_put = parse_action(def.allow_metadata_inventory_put, function() actions.get_allow_metadata_inventory_put{def.type} end)
|
function() actions.get_allow_metadata_inventory_move{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.allow_metadata_inventory_put = parse_action(def.allow_metadata_inventory_put,
|
||||||
out.on_metadata_inventory_move = parse_action(def.on_metadata_inventory_move, function() actions.get_on_metadata_inventory_move(def.type) end)
|
function() actions.get_allow_metadata_inventory_put{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.allow_metadata_inventory_take = parse_action(def.allow_metadata_inventory_take,
|
||||||
out.on_metadata_inventory_take = parse_action(def.on_metadata_inventory_take, function() actions.get_on_metadata_inventory_take(def.type) end)
|
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 model is not a simple block handle node_box attribute
|
||||||
if def.node_box then
|
if def.node_box then
|
||||||
out.drawtype = "nodebox"
|
out.drawtype = "nodebox"
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
function generate(size, inventory_name)
|
local function generate(size, inventory_name)
|
||||||
local cfg
|
local cfg
|
||||||
|
|
||||||
-- chest inventory name
|
-- chest inventory name
|
||||||
|
|||||||
Reference in New Issue
Block a user