[WIP] better parameter handling for mcl_formspec.create_itemslot_bg().

This commit is contained in:
iliekprogrammar 2021-09-30 19:48:02 +08:00
parent 0226aaf8d8
commit d24fbe1a8e
1 changed files with 33 additions and 10 deletions

View File

@ -79,21 +79,44 @@ local function create_itemslot_bg(i, j, x, y, iu, bu, factor)
}
end
function mcl_formspec.create_itemslot_bg(x, y, w, h, iu, bu, border, spacing, factor)
local iu = iu or mcl_formspec.itemslot_iu
local bu = bu or mcl_formspec.itemslot_bu
if border and spacing and factor then
iu = mcl_formspec.itemslot_unit(1, border, spacing, factor)
bu = factor * border
function mcl_formspec.create_itemslot_bg(x, y, w, h, def)
-- Optional params: def
-- Params:
-- (x, y, w, h, def*)
-- def params:
-- {
-- < iu = ..., bu = ... >*
-- < border = ..., spacing = ..., factor = ..., >*
-- }
-- or {
-- < iu = ..., bu = ... >*
-- border = nil, spacing = nil, < factor = ..., >*
-- }
-- * indicates that the argument (or set of arguments) may be nil.
local iu, bu, border, spacing, factor
if def then
if def.border and def.spacing and def.factor then
iu = mcl_formspec.itemslot_unit(1, border, spacing, factor)
bu = factor * border
else
iu = def.iu or mcl_formspec.itemslot_iu
bu = def.bu or mcl_formspec.itemslot_bu
end
border = def.border or mcl_formspec.itemslot_border_size
spacing = def.spacing or mcl_formspec.itemslot_spacing_size
factor = def.factor or mcl_formspec.get_factor(border, spacing)
else
iu = mcl_formspec.itemslot_iu
bu = mcl_formspec.itemslot_bu
border = mcl_formspec.itemslot_border_size
spacing = mcl_formspec.itemslot_spacing_size
factor = mcl_formspec.get_factor(border, spacing)
end
local border = border or mcl_formspec.itemslot_border_size
local spacing = spacing or mcl_formspec.itemslot_spacing_size
local factor = factor or mcl_formspec.get_factor(border, spacing)
local out = ""
for i = 0, w - 1, 1 do
for j = 0, h - 1, 1 do
out = out .. create_itemslot_bg(i, j, x, y, iu, border, spacing, factor)
out = out .. create_itemslot_bg(i, j, x, y, iu, bu, factor)
end
end
return out