100 lines
2.2 KiB
Lua
100 lines
2.2 KiB
Lua
watcher=klass()
|
|
function watcher:init(ruleset,seed,stages)
|
|
self.ruleset=ruleset
|
|
self.seed=seed
|
|
self._stages=stages or {}
|
|
self._allow_tips=#self._stages == 0
|
|
end
|
|
function watcher:allow_tips()
|
|
return self._allow_tips
|
|
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
|
|
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)
|
|
|
|
local note=stage.note
|
|
if (not note) return
|
|
local w,h=measure_text(note)
|
|
local x=64-w\2
|
|
local y=88
|
|
rectfill(x-1,y-1,x+w-1,y+h-1,1)
|
|
rect(x-2,y-2,x+w,y+h,15)
|
|
print(note,x,y,15)
|
|
end
|
|
|
|
tutorial_grab=klass()
|
|
function tutorial_grab:init(src,dst,note)
|
|
self.src=src
|
|
self.dst=dst
|
|
self.note=note
|
|
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:grabbed_card() == nil then
|
|
-- show a hint for grabbing
|
|
layout=layouts:slot(self.src)
|
|
i=#board.slots[self.src].contents
|
|
draw_layout_hint(layout,i,15,false,true)
|
|
text="🅾️"
|
|
else
|
|
layout=layouts:slot(self.dst)
|
|
i=#board.slots[self.dst].contents+1
|
|
draw_layout_hint(layout,i,15,false,true)
|
|
text="🅾️"
|
|
end
|
|
return layout,i,text
|
|
end
|
|
|
|
|
|
tutorial_undo=klass()
|
|
function tutorial_undo:init(note)
|
|
self.note=note
|
|
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,true)
|
|
text="❎"
|
|
return layout,i,text
|
|
end
|
|
|
|
-- todo: restart? |