-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpile_cell.lua
63 lines (54 loc) · 1.32 KB
/
pile_cell.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- class Cell, derived from Pile
local Pile = require 'pile'
local Util = require 'util'
---@class (exact) Cell: Pile
---@field __index Cell
---@field new function
local Cell = {}
Cell.__index = Cell
setmetatable(Cell, {__index = Pile})
function Cell.new(o)
o.category = 'Cell'
o.fanType = 'FAN_NONE'
o.moveType = 'MOVE_TOP_ONLY'
o = Pile.prepare(o)
table.insert(_G.BAIZE.piles, o)
table.insert(_G.BAIZE.cells, o)
return setmetatable(o, Cell)
end
---@return string|nil
function Cell:acceptTailError(tail)
if #self.cards ~= 0 then
return 'A Cell can only contain one card'
end
if #tail > 1 then
return 'Can only move one card to a Cell'
end
if tail[1].prone then
-- eg being dragged from Stock
return 'Cannot add a face down card to a Cell'
end
return nil
end
-- use Pile.tailTapped
-- use Pile.collect
---@return integer
function Cell:unsortedPairs()
return 0
end
function Cell:movableTails()
-- same as Reserve:movableTails
local tails = {}
if #self.cards > 0 then
local card = self:peek() -- card should never be prone
if not card.prone then
local tail = {card}
local homes = Util.findHomesForTail(tail)
for _, home in ipairs(homes) do
table.insert(tails, {tail=tail, dst=home.dst})
end
end
end
return tails
end
return Cell