Dealing on specific color seems to work
This commit is contained in:
parent
f761343c19
commit
ec8a764ea2
29
init.lua
29
init.lua
@ -490,10 +490,23 @@ local function cardtable_get_main_pos(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- return array of positions that list all blocks in a cardtable
|
-- return array of positions that list all blocks in a cardtable
|
||||||
local function cardtable_get_positions(pos)
|
local function cardtable_get_positions(pos,color)
|
||||||
local mainpos=cardtable_get_main_pos(pos)
|
local mainpos=cardtable_get_main_pos(pos)
|
||||||
local mainmeta=minetest.get_meta(mainpos)
|
local mainmeta=minetest.get_meta(mainpos)
|
||||||
return minetest.deserialize(mainmeta:get_string("cardtable_positions"))
|
local allpos=minetest.deserialize(mainmeta:get_string("cardtable_positions"))
|
||||||
|
if color==nil then
|
||||||
|
return allpos
|
||||||
|
end
|
||||||
|
local colored={}
|
||||||
|
local name=tableprefix..color
|
||||||
|
for i,p in ipairs(allpos) do
|
||||||
|
local n=minetest.get_node(p)
|
||||||
|
if n.name == name then
|
||||||
|
table.insert(colored,p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
log(table.getn(colored).." "..color.." cardtable pieces")
|
||||||
|
return colored
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Take all cards from cardtable at pos and place them in list of sender
|
-- Take all cards from cardtable at pos and place them in list of sender
|
||||||
@ -529,8 +542,14 @@ end
|
|||||||
-- Adds card to cardtable. Return true if card was added or false if cardtable was full.
|
-- Adds card to cardtable. Return true if card was added or false if cardtable was full.
|
||||||
local function cardtable_add_card(pos,cardname,color)
|
local function cardtable_add_card(pos,cardname,color)
|
||||||
local above={x=pos.x,y=pos.y+1,z=pos.z}
|
local above={x=pos.x,y=pos.y+1,z=pos.z}
|
||||||
if cardtable_try_add_card(above,cardname) then return true end
|
local positions=cardtable_get_positions(pos,color)
|
||||||
local positions=cardtable_get_positions(pos)
|
if debug_enabled then
|
||||||
|
if color == nil then
|
||||||
|
log("adding to cardtable, no color set")
|
||||||
|
else
|
||||||
|
log("adding to color "..color)
|
||||||
|
end
|
||||||
|
end
|
||||||
for i,p in ipairs(positions) do
|
for i,p in ipairs(positions) do
|
||||||
above={x=p.x,y=p.y+1,z=p.z}
|
above={x=p.x,y=p.y+1,z=p.z}
|
||||||
if cardtable_try_add_card(above,cardname) then return true end
|
if cardtable_try_add_card(above,cardname) then return true end
|
||||||
@ -640,7 +659,7 @@ local function deal_card_to_table(pos,formname,fields,sender)
|
|||||||
log("out of cards")
|
log("out of cards")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if cardtable_add_card(below,stack:get_name(),fields.deal_card_to_table) then
|
if cardtable_add_card(below,stack:get_name(),fields.deal_to_table) then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
log("Card did not fit on table.")
|
log("Card did not fit on table.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user