Add draw all button to piles.

This commit is contained in:
Mikko Tuumanen 2020-05-15 20:40:11 +03:00 committed by Mikko Tuumanen
parent e9b4d253b6
commit 0d68aeccd0

@ -128,8 +128,7 @@ local function add_to_inv(inv, cardname)
return false
end
local function draw_card(pos,formname,fields,sender)
if fields.draw then
local function draw_one_card(pos,formname,fields,sender)
local player_inv=minetest.get_inventory({type="player", name=sender:get_player_name()})
local meta=minetest.get_meta(pos)
local pile_inv=meta:get_inventory()
@ -137,8 +136,18 @@ local function draw_card(pos,formname,fields,sender)
local stack=pile_pop(pile_inv)
if stack == nil then
minetest.log("empty pile")
return false
else
player_inv:add_item("main",stack)
return true
end
end
local function draw_card(pos,formname,fields,sender)
if fields.draw then
return draw_one_card(pos,formname,fields,sender)
elseif fields.drawall then
while draw_one_card(pos,formname,fields,sender) do
end
end
end
@ -208,7 +217,11 @@ minetest.register_node("deck:chestpile", {
on_construct = function(pos)
pile_inv_setup(pos)
local meta=minetest.get_meta(pos)
meta:set_string("formspec","size[13,10]list[context;main;0,0;13,4;]button[0,4;2,1;draw;Draw]list[current_player;main;0,6;8,4;]")
meta:set_string("formspec", "size[13,10]"..
"list[context;main;0,0;13,4;]"..
"button[0,4;2,1;draw;Draw]"..
"button[2,4;2,1;drawall;Draw all]"..
"list[current_player;main;0,6;8,4;]")
end,
on_dig = on_dig_pile_getpile,
stack_max = 1,
@ -223,7 +236,10 @@ minetest.register_node("deck:stockpile", {
on_construct = function(pos)
pile_inv_setup(pos)
local meta=minetest.get_meta(pos)
meta:set_string("formspec","size[8,5]button[0,0;2,1;draw;Draw]list[current_player;main;0,1;8,4;]"
meta:set_string("formspec","size[8,5]"..
"button[0,0;2,1;draw;Draw]"..
"button[2,0;2,1;drawall;Draw all]"..
"list[current_player;main;0,1;8,4;]"
)
end,
on_dig = on_dig_pile_getpile,