Stockpile improvements

Fix darkening stockpile when last card is dealt to table from table color
drop down menu.

Adding card from player inventory to stockpile: One slot of player craft
list is shown on stockpile invnetory view. Above it there is a button for
placing card from craft list to top of the stockpile.
This commit is contained in:
Mikko Tuumanen 2023-11-04 20:38:05 +02:00
parent ec8a764ea2
commit cbc1b9470a

View File

@ -315,6 +315,28 @@ local function defragment_pile(pos)
end end
end end
-- Takes card from first slot of player's inventory's craft list and places it on top of the pile at pos
local function put_craft_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 stack=player_inv:get_stack("craft",1)
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
if pile_peek_first(pile_inv) == nil then
lighten_pile(pos)
end
add_to_inv(pile_inv, cardname)
player_inv:set_stack("craft",1,stack)
defragment_pile(pos)
end
end
end
end
-- Takes all cards from player main inventory list and places them on the pile at pos -- Takes all cards from player main inventory list and places them on the pile at pos
local function put_all_to_pile(pos,formname,fields,sender) local function put_all_to_pile(pos,formname,fields,sender)
local player_inv=minetest.get_inventory({type="player", name=sender:get_player_name()}) local player_inv=minetest.get_inventory({type="player", name=sender:get_player_name()})
@ -660,7 +682,10 @@ local function deal_card_to_table(pos,formname,fields,sender)
return false return false
end end
if cardtable_add_card(below,stack:get_name(),fields.deal_to_table) then if cardtable_add_card(below,stack:get_name(),fields.deal_to_table) then
return true if pile_peek_first(from_pile_inv) == nil then
darken_pile(pos)
return true
end
else else
log("Card did not fit on table.") log("Card did not fit on table.")
pile_add_card(from_pile_inv,stack:get_name()) pile_add_card(from_pile_inv,stack:get_name())
@ -753,6 +778,8 @@ local function draw_card(pos,formname,fields,sender)
convert_pile(pos,"deck:stockpile") convert_pile(pos,"deck:stockpile")
elseif fields.alltopile then elseif fields.alltopile then
put_all_to_pile(pos,formname,fields,sender) put_all_to_pile(pos,formname,fields,sender)
elseif fields.crafttopile then
put_craft_to_pile(pos,formname,fields,sender)
elseif fields.deal then elseif fields.deal then
deal_cards(pos,formname,fields,sender) deal_cards(pos,formname,fields,sender)
elseif fields.deal_to_table then elseif fields.deal_to_table then
@ -936,10 +963,10 @@ minetest.register_node("deck:chestpile", {
on_construct = function(pos) on_construct = function(pos)
pile_inv_setup(pos) pile_inv_setup(pos)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
meta:set_string("formspec", "size[13,11]".. meta:set_string("formspec", "size[13,12]"..
"list[context;main;0,0;13,4;]".. "list[context;main;0,0;13,8;]"..
"button[0,4;2,1;draw;Draw]".. "button[0,4;2,1;draw;Draw one]"..
"button[2,4;2,1;drawall;Draw all]".. "button[0,6;2,1;drawall;Draw all]"..
"button[4,4;2,1;alltopile;Add all to pile]".. "button[4,4;2,1;alltopile;Add all to pile]"..
"button[6,4;2,1;shuffle;Shuffle cards]".. "button[6,4;2,1;shuffle;Shuffle cards]"..
"button[8,4;2,1;sort;Sort cards]".. "button[8,4;2,1;sort;Sort cards]"..
@ -967,23 +994,29 @@ minetest.register_node("deck:stockpile", {
local below={x=pos.x,y=pos.y-1,z=pos.z} local below={x=pos.x,y=pos.y-1,z=pos.z}
local colors=cardtable_get_colors(below) local colors=cardtable_get_colors(below)
local dealmenu local dealmenu
local deallabel
if table.getn(colors) == 1 then if table.getn(colors) == 1 then
deallabel=""
dealmenu="button[10,0;2,1;deal_to_table;Deal to table]" dealmenu="button[10,0;2,1;deal_to_table;Deal to table]"
else else
dealmenu="dropdown[10,0;2;deal_to_table;" deallabel="label[10,0;Deal to table]"
dealmenu="dropdown[10,1;2;deal_to_table;"
for key,value in ipairs(colors) do for key,value in ipairs(colors) do
dealmenu=dealmenu..value.."," dealmenu=dealmenu..value..","
end end
dealmenu=dealmenu..";1]" dealmenu=dealmenu..";1]"
end end
meta:set_string("formspec","size[13,6]".. local add_to_pile_inv=minetest.create
"button[0,0;2,1;draw;Draw]".. meta:set_string("formspec","size[13,7]"..
"button[2,0;2,1;drawall;Draw all]".. "button[0,0;2,1;draw;Draw one]"..
"button[4,0;2,1;alltopile;Add all to pile]".. "button[0,1;2,1;drawall;Draw all]"..
"button[6,0;2,1;shuffle;Shuffle cards]".. "button[2,0;2,1;crafttopile;Add to pile]"..
"list[current_player;craft;2,1;1,1;]"..
"button[4,1;3,1;alltopile;Add all to pile]"..
"button[4,0;3,1;shuffle;Shuffle cards]"..
"button[8,0;2,1;deal;Deal cards]".. "button[8,0;2,1;deal;Deal cards]"..
dealmenu.. deallabel..dealmenu..
"list[current_player;main;0,1;13,5;]" "list[current_player;main;0,2;13,5;]"
) )
end, end,
on_dig = on_dig_pile_getpile, on_dig = on_dig_pile_getpile,