Colored cardtable works

This commit is contained in:
Mikko Tuumanen 2023-10-28 21:22:08 +03:00
parent 7929e019d9
commit 5295e23e74

View File

@ -585,6 +585,15 @@ local function inventory_to_cardtable(list,pos,sender,which)
return false return false
end end
local function is_cardtable(pos)
local prefix="deck:cardtable_"
local n=minetest.get_node(pos)
if string.sub(n.name,1,string.len(prefix)) == prefix then
return true
end
return false
end
-- return true if pos is deal position -- return true if pos is deal position
local function is_deal_position(pos) local function is_deal_position(pos)
local around={ local around={
@ -594,8 +603,7 @@ local function is_deal_position(pos)
} }
local tablenodes=0 local tablenodes=0
for key,p in ipairs(around) do for key,p in ipairs(around) do
local n=minetest.get_node(p) if is_cardtable(p) then
if n.name == "deck:cardtable" then
tablenodes=tablenodes+1 tablenodes=tablenodes+1
end end
end end
@ -619,9 +627,8 @@ end
local function deal_card_to_table(pos,formname,fields,sender) local function deal_card_to_table(pos,formname,fields,sender)
log("deal cards at "..minetest.pos_to_string(pos)) log("deal cards at "..minetest.pos_to_string(pos))
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 belownode=minetest.get_node(below)
local dp local dp
if belownode.name == "deck:cardtable" then if is_cardtable(below) then
log("below is cardtable") log("below is cardtable")
local from_pile_meta=minetest.get_meta(pos) local from_pile_meta=minetest.get_meta(pos)
local from_pile_inv=from_pile_meta:get_inventory() local from_pile_inv=from_pile_meta:get_inventory()
@ -648,9 +655,8 @@ end
local function deal_cards(pos,formname,fields,sender) local function deal_cards(pos,formname,fields,sender)
log("deal cards at "..minetest.pos_to_string(pos)) log("deal cards at "..minetest.pos_to_string(pos))
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 belownode=minetest.get_node(below)
local dp local dp
if belownode.name == "deck:cardtable" then if is_cardtable(below) then
log("below is cardtable") log("below is cardtable")
dp=cardtable_get_deal_positions(below) dp=cardtable_get_deal_positions(below)
else else
@ -846,8 +852,7 @@ local function on_construct_cardtable(pos)
) )
for key,p in ipairs(around) do for key,p in ipairs(around) do
local n=minetest.get_node(p) if is_cardtable(p) then
if n.name == "deck:cardtable" then
add_node_to_cardtable(cardtable_get_main_pos(p),pos) add_node_to_cardtable(cardtable_get_main_pos(p),pos)
return return
end end
@ -945,16 +950,16 @@ for _, row in ipairs(dye.dyes) do
local name = "deck:cardtable_"..color local name = "deck:cardtable_"..color
local colorize = tablecolorize[color] local colorize = tablecolorize[color]
if colorize == nil then colorize = color end if colorize == nil then colorize = color end
local tile = "deck_table_g.png^[colorize:"..colorize..":alpha" local tile = "deck_table_g.png^[colorize:"..colorize..":127"
log(name..": "..tile) log(name..": "..tile)
minetest.register_node(name, { minetest.register_node(name, {
description = "Table where cards can be easily dealt", description = "Table where cards can be easily dealt",
tiles = { tile }, tiles = { tile },
on_construct = on_construct_cardtable, on_construct = on_construct_cardtable,
groups = {cracky=3, cardtable=1}, groups = {cracky=3, cardtable=1},
after_dig_node = after_dig_cardtable, after_dig_node = after_dig_cardtable,
on_receive_fields = fields_cardtable, on_receive_fields = fields_cardtable,
}) })
end end
-- ABM enables adding cards to a pile by placing card on the pile. -- ABM enables adding cards to a pile by placing card on the pile.