fortunes_foundation/tutorial_watcher.lua

59 lines
1.4 KiB
Lua
Raw Normal View History

2024-02-11 03:42:38 +00:00
tutorial_watcher=klass()
function tutorial_watcher:init(seed,stages)
self.seed=seed
self._stages=stages
end
function tutorial_watcher:update(board)
local stage=self._stages[1]
if (stage) stage:update(board)
end
function tutorial_watcher:active_stage(board)
local stage=self._stages[1]
if (stage and stage:active()) return stage
end
function tutorial_watcher:draw(board)
local stage=self:active_stage()
if (not stage) return
local layouts=board.ruleset.layouts
-- stop("calling: "..stage._layout_name)
local layout=layouts[stage._layout_name](layouts,stage._layout_arg)
local x,y=layout:place_card(stage._layout_arg_2)
local tx=stage._text
local w,h=measure_text(tx)
x+=4
x-=w\2
y+=25
local lx=x+w\2
line(lx,y-9,lx,y,15)
rectfill(x-2,y-2,x+w,y+h,1)
rect(x-2,y-2,x+w,y+h,15)
print(tx,x,y,15)
end
tutorial_stage=klass()
function tutorial_stage:init(layout_name,layout_arg,layout_arg_2,move,text,requirement_cb)
self._layout_name=layout_name
self._layout_arg=layout_arg
self._layout_arg_2=layout_arg_2
self._move=move
self._text=text
self._requirement_cb=requirement_cb
self._enabled=not self._requirement_cb
end
function tutorial_stage:update(board)
if (not self._enabled and self._requirement_cb(board)) self._enabled=true
end
function tutorial_stage:active()
return self._enabled
end
-- todo: restart?
function tutorial_move_undo()
return "undo"
end
function tutorial_move_slot(slot_src,slot_dst)
return tostr(slot_src).."->"..tostr(slot_dst)
end