diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 5f94ffae8..d58d44756 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -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