forked from mtcontrib/homedecor_modpack
select a formspec automaticly from a table if none is supplied
This commit is contained in:
parent
0341a00f9f
commit
cc9a1a9c3c
@ -348,9 +348,6 @@ homedecor.register("wardrobe_bottom", {
|
||||
infotext = S("Wardrobe cabinet"),
|
||||
inventory = {
|
||||
size=24,
|
||||
formspec="size[8,8]"..
|
||||
"list[context;main;0,0;8,3;]"..
|
||||
"list[current_player;main;0,4;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -29,9 +29,6 @@ for _, mat in ipairs(counter_materials) do
|
||||
infotext=S("Kitchen Cabinet"),
|
||||
inventory = {
|
||||
size=24,
|
||||
formspec="size[8,8]"..
|
||||
"list[context;main;0,0;8,3;]"..
|
||||
"list[current_player;main;0,4;8,4;]",
|
||||
},
|
||||
})
|
||||
end
|
||||
@ -59,9 +56,6 @@ homedecor.register("kitchen_cabinet_half", {
|
||||
infotext=S("Kitchen Cabinet"),
|
||||
inventory = {
|
||||
size=12,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;1,0;6,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -77,8 +71,5 @@ homedecor.register("kitchen_cabinet_with_sink", {
|
||||
infotext=S("Under-sink cabinet"),
|
||||
inventory = {
|
||||
size=16,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
@ -90,9 +90,6 @@ homedecor.register("medicine_cabinet", {
|
||||
infotext=S("Medicine cabinet"),
|
||||
inventory = {
|
||||
size=16,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;1,0;6,1;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -328,9 +328,6 @@ homedecor.register("cardboard_box", {
|
||||
infotext=S("Cardboard box"),
|
||||
inventory = {
|
||||
size=8,
|
||||
formspec="size[8,6]"..
|
||||
"list[current_name;main;2,0;4,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -396,9 +393,6 @@ homedecor.register("filing_cabinet", {
|
||||
infotext=S("Filing cabinet"),
|
||||
inventory = {
|
||||
size=16,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -32,9 +32,6 @@ homedecor.register("nightstand_oak_one_drawer", {
|
||||
infotext=S("One-drawer Nightstand"),
|
||||
inventory = {
|
||||
size=8,
|
||||
formspec="size[8,6]"..
|
||||
"list[context;main;0,0;8,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -69,9 +66,6 @@ homedecor.register("nightstand_oak_two_drawers", {
|
||||
infotext=S("Two-drawer Nightstand"),
|
||||
inventory = {
|
||||
size=16,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -105,9 +99,6 @@ homedecor.register("nightstand_mahogany_one_drawer", {
|
||||
infotext=S("One-drawer Nightstand"),
|
||||
inventory = {
|
||||
size=8,
|
||||
formspec="size[8,6]"..
|
||||
"list[context;main;0,0;8,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -139,8 +130,5 @@ homedecor.register("nightstand_mahogany_two_drawers", {
|
||||
infotext=S("Two-drawer Nightstand"),
|
||||
inventory = {
|
||||
size=16,
|
||||
formspec="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
},
|
||||
})
|
||||
|
@ -60,9 +60,6 @@ homedecor.register("refrigerator_steel_bottom", {
|
||||
inventory = {
|
||||
size=50,
|
||||
lockable=true,
|
||||
formspec="size[10,10]"..
|
||||
"list[context;main;0,0;10,5;]"..
|
||||
"list[current_player;main;1,6;8,4;]",
|
||||
},
|
||||
})
|
||||
|
||||
@ -108,9 +105,7 @@ homedecor.register("refrigerator_white_bottom", {
|
||||
infotext=S("Refrigerator"),
|
||||
inventory = {
|
||||
size=50,
|
||||
formspec="size[10,10]"..
|
||||
"list[context;main;0,0;10,5;]"..
|
||||
"list[current_player;main;1,6;8,4;]",
|
||||
lockable=true
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -7,14 +7,39 @@ local default_can_dig = function(pos,player)
|
||||
end
|
||||
|
||||
local default_inventory_size = 32
|
||||
local default_inventory_formspec = "size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_name;main;0,0.3;8,4;]"..
|
||||
local default_inventory_formspecs = {
|
||||
["8"]="size[8,6]"..
|
||||
"list[context;main;0,0;8,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
|
||||
["12"]="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
|
||||
["16"]="size[8,7]"..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
|
||||
["24"]="size[8,8]"..
|
||||
"list[context;main;0,0;8,3;]"..
|
||||
"list[current_player;main;0,4;8,4;]",
|
||||
|
||||
["32"]="size[8,9]".. default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
|
||||
"list[context;main;0,0.3;8,4;]"..
|
||||
"list[current_player;main;0,4.85;8,1;]"..
|
||||
"list[current_player;main;0,6.08;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
default.get_hotbar_bg(0,4.85),
|
||||
|
||||
["50"]="size[10,10]"..
|
||||
"list[context;main;0,0;10,5;]"..
|
||||
"list[current_player;main;1,6;8,4;]",
|
||||
}
|
||||
|
||||
local function get_formspec_by_size(size)
|
||||
--TODO heuristic to use the "next best size"
|
||||
local formspec = default_inventory_formspecs[tostring(size)]
|
||||
return formspec or default_inventory_formspecs
|
||||
end
|
||||
|
||||
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
|
||||
function homedecor.register(name, def)
|
||||
@ -37,17 +62,14 @@ function homedecor.register(name, def)
|
||||
def.inventory = nil
|
||||
|
||||
if inventory then
|
||||
assert((inventory.formspec == nil) == (inventory.size == nil),
|
||||
"inventory.formspec and inventory.size either have both to be set or both be left nil" )
|
||||
|
||||
def.on_construct = def.on_construct or function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if infotext then
|
||||
meta:set_string("infotext", infotext)
|
||||
end
|
||||
|
||||
meta:set_string("formspec", inventory.formspec or default_inventory_formspec)
|
||||
meta:get_inventory():set_size("main", inventory.size or default_inventory_size)
|
||||
local size = inventory.size or default_inventory_size
|
||||
meta:get_inventory():set_size("main", size)
|
||||
meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
|
||||
end
|
||||
|
||||
def.can_dig = def.can_dig or default_can_dig
|
||||
|
Loading…
Reference in New Issue
Block a user