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:
parent
ec8a764ea2
commit
cbc1b9470a
59
init.lua
59
init.lua
@ -315,6 +315,28 @@ local function defragment_pile(pos)
|
||||
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
|
||||
local function put_all_to_pile(pos,formname,fields,sender)
|
||||
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
|
||||
end
|
||||
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
|
||||
log("Card did not fit on table.")
|
||||
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")
|
||||
elseif fields.alltopile then
|
||||
put_all_to_pile(pos,formname,fields,sender)
|
||||
elseif fields.crafttopile then
|
||||
put_craft_to_pile(pos,formname,fields,sender)
|
||||
elseif fields.deal then
|
||||
deal_cards(pos,formname,fields,sender)
|
||||
elseif fields.deal_to_table then
|
||||
@ -936,10 +963,10 @@ 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,11]"..
|
||||
"list[context;main;0,0;13,4;]"..
|
||||
"button[0,4;2,1;draw;Draw]"..
|
||||
"button[2,4;2,1;drawall;Draw all]"..
|
||||
meta:set_string("formspec", "size[13,12]"..
|
||||
"list[context;main;0,0;13,8;]"..
|
||||
"button[0,4;2,1;draw;Draw one]"..
|
||||
"button[0,6;2,1;drawall;Draw all]"..
|
||||
"button[4,4;2,1;alltopile;Add all to pile]"..
|
||||
"button[6,4;2,1;shuffle;Shuffle 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 colors=cardtable_get_colors(below)
|
||||
local dealmenu
|
||||
local deallabel
|
||||
if table.getn(colors) == 1 then
|
||||
deallabel=""
|
||||
dealmenu="button[10,0;2,1;deal_to_table;Deal to table]"
|
||||
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
|
||||
dealmenu=dealmenu..value..","
|
||||
end
|
||||
dealmenu=dealmenu..";1]"
|
||||
end
|
||||
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;alltopile;Add all to pile]"..
|
||||
"button[6,0;2,1;shuffle;Shuffle cards]"..
|
||||
local add_to_pile_inv=minetest.create
|
||||
meta:set_string("formspec","size[13,7]"..
|
||||
"button[0,0;2,1;draw;Draw one]"..
|
||||
"button[0,1;2,1;drawall;Draw all]"..
|
||||
"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]"..
|
||||
dealmenu..
|
||||
"list[current_player;main;0,1;13,5;]"
|
||||
deallabel..dealmenu..
|
||||
"list[current_player;main;0,2;13,5;]"
|
||||
)
|
||||
end,
|
||||
on_dig = on_dig_pile_getpile,
|
||||
|
Loading…
x
Reference in New Issue
Block a user