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"),
|
infotext = S("Wardrobe cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=24,
|
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"),
|
infotext=S("Kitchen Cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=24,
|
size=24,
|
||||||
formspec="size[8,8]"..
|
|
||||||
"list[context;main;0,0;8,3;]"..
|
|
||||||
"list[current_player;main;0,4;8,4;]",
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -59,9 +56,6 @@ homedecor.register("kitchen_cabinet_half", {
|
|||||||
infotext=S("Kitchen Cabinet"),
|
infotext=S("Kitchen Cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=12,
|
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"),
|
infotext=S("Under-sink cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=16,
|
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"),
|
infotext=S("Medicine cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=16,
|
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"),
|
infotext=S("Cardboard box"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=8,
|
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"),
|
infotext=S("Filing cabinet"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=16,
|
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"),
|
infotext=S("One-drawer Nightstand"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=8,
|
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"),
|
infotext=S("Two-drawer Nightstand"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=16,
|
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"),
|
infotext=S("One-drawer Nightstand"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=8,
|
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"),
|
infotext=S("Two-drawer Nightstand"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=16,
|
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 = {
|
inventory = {
|
||||||
size=50,
|
size=50,
|
||||||
lockable=true,
|
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"),
|
infotext=S("Refrigerator"),
|
||||||
inventory = {
|
inventory = {
|
||||||
size=50,
|
size=50,
|
||||||
formspec="size[10,10]"..
|
lockable=true
|
||||||
"list[context;main;0,0;10,5;]"..
|
|
||||||
"list[current_player;main;1,6;8,4;]",
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -7,14 +7,39 @@ local default_can_dig = function(pos,player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local default_inventory_size = 32
|
local default_inventory_size = 32
|
||||||
local default_inventory_formspec = "size[8,9]"..
|
local default_inventory_formspecs = {
|
||||||
default.gui_bg..
|
["8"]="size[8,6]"..
|
||||||
default.gui_bg_img..
|
"list[context;main;0,0;8,1;]"..
|
||||||
default.gui_slots..
|
"list[current_player;main;0,2;8,4;]",
|
||||||
"list[current_name;main;0,0.3;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,4.85;8,1;]"..
|
||||||
"list[current_player;main;0,6.08;8,3;8]"..
|
"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
|
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
|
||||||
function homedecor.register(name, def)
|
function homedecor.register(name, def)
|
||||||
@ -37,17 +62,14 @@ function homedecor.register(name, def)
|
|||||||
def.inventory = nil
|
def.inventory = nil
|
||||||
|
|
||||||
if inventory then
|
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)
|
def.on_construct = def.on_construct or function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if infotext then
|
if infotext then
|
||||||
meta:set_string("infotext", infotext)
|
meta:set_string("infotext", infotext)
|
||||||
end
|
end
|
||||||
|
local size = inventory.size or default_inventory_size
|
||||||
meta:set_string("formspec", inventory.formspec or default_inventory_formspec)
|
meta:get_inventory():set_size("main", size)
|
||||||
meta:get_inventory():set_size("main", inventory.size or default_inventory_size)
|
meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
|
||||||
end
|
end
|
||||||
|
|
||||||
def.can_dig = def.can_dig or default_can_dig
|
def.can_dig = def.can_dig or default_can_dig
|
||||||
|
Loading…
Reference in New Issue
Block a user