fortunes_foundation/watcher.lua

85 lines
1.9 KiB
Lua
Raw Normal View History

2024-02-11 04:40:12 +00:00
watcher=klass()
function watcher:init(ruleset,seed,stages)
self.ruleset=ruleset
self.seed=seed
self._stages=stages or {}
end
function watcher:active_stage(board)
local stage=self._stages[1]
if (stage and stage:active()) return stage
end
function watcher:intercept(x,arg)
local stage=self:active_stage()
if (not stage) return true
local allowed,drop=stage:intercept(x,arg)
if (drop) deli(self._stages,1)
return allowed
end
function watcher:draw(board)
local stage=self:active_stage()
if (not stage) return
local layouts=board.ruleset.layouts
local layout,i,x,y,text
layout,i,text=stage:draw(board,layouts)
x,y=layout:place_card(i)
local w,h=measure_text(text)
x+=1
y+=20
local lx=x+3
line(lx,y-4,lx,y,15)
rectfill(x-2,y-2,x+w,y+h,1)
rect(x-2,y-2,x+w,y+h,15)
print(text,x,y,15)
end
tutorial_grab=klass()
function tutorial_grab:init(src,dst)
self.src=src
self.dst=dst
end
function tutorial_grab:active()
return true
end
function tutorial_grab:intercept(x, slot)
if (x=="grab" and slot==self.src) return true,false
if (x=="drop" and slot==self.dst) return true,true
end
function tutorial_grab:draw(board,layouts)
local layout,i,text
if board.cursor:acceptance_state() == acceptance_state.not_grabbed then
-- show a hint for grabbing
layout=layouts:slot(self.src)
i=#board.slots[self.src].contents
draw_layout_hint(layout,i,15,false,0,0)
text="🅾️"
else
layout=layouts:slot(self.dst)
i=#board.slots[self.dst].contents+1
draw_layout_hint(layout,i,15,false,0,0)
text="🅾️"
end
return layout,i,text
end
tutorial_undo=klass()
function tutorial_undo:init() end
function tutorial_undo:active()
return true
end
function tutorial_undo:intercept(x)
if (x=="undo") return true,true
end
function tutorial_undo:draw(board,layouts)
local layout,i,text
layout=layouts:checkpoint()
draw_layout_hint(layout,0,15,false,0,0)
text=""
return layout,i,text
end
-- todo: restart?