diff --git a/init.lua b/init.lua index 6bd3d8d..7efb498 100644 --- a/init.lua +++ b/init.lua @@ -154,6 +154,7 @@ end local function pile_pop(inv) local s=inv:get_size("main") + local i for i=1,s,1 do local stack=inv:get_stack("main",i) if stack:get_count() > 0 then @@ -202,6 +203,33 @@ local function lighten_pile(pos) minetest.set_node(pos,node) end +local function put_all_to_pile(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() + local s=player_inv:get_size("main") + local i + if pile_peek_first(pile_inv) == nil then + lighten_pile(pos) + end + for i=1,s,1 do + local stack=player_inv:get_stack("main",i) + if stack:get_count() > 0 then + local cardname=stack:get_name() + if string.sub(cardname,1,cardprefixlen) == cardprefix then + local item=stack:take_item(1) + if item ~= nil then + add_to_inv(pile_inv, cardname) + player_inv:set_stack("main",i,stack) + end + end + end + end + if pile_peek_first(pile_inv) == nil then + darken_pile(pos) + end +end + 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) @@ -273,6 +301,8 @@ local function draw_card(pos,formname,fields,sender) elseif fields.tostock then minetest.close_formspec(sender:get_player_name(),"") convert_pile(pos,"deck:stockpile") + elseif fields.alltopile then + put_all_to_pile(pos,formname,fields,sender) end end @@ -352,8 +382,9 @@ minetest.register_node("deck:chestpile", { "list[context;main;0,0;13,4;]".. "button[0,4;2,1;draw;Draw]".. "button[2,4;2,1;drawall;Draw all]".. - "button[4,4;2,1;shuffle;Shuffle cards]".. - "button[6,4;2,1;tostock;Make stockpile]".. + "button[4,4;2,1;alltopile;Add all to pile]".. + "button[6,4;2,1;shuffle;Shuffle cards]".. + "button[8,4;2,1;tostock;Make stockpile]".. "list[current_player;main;0,6;13,5;]") end, on_dig = on_dig_pile_getpile, @@ -375,7 +406,8 @@ minetest.register_node("deck:stockpile", { meta:set_string("formspec","size[13,6]".. "button[0,0;2,1;draw;Draw]".. "button[2,0;2,1;drawall;Draw all]".. - "button[4,0;2,1;shuffle;Shuffle cards]".. + "button[4,0;2,1;alltopile;Add all to pile]".. + "button[6,0;2,1;shuffle;Shuffle cards]".. "list[current_player;main;0,1;13,5;]" ) end,