36 lines
886 B
Lua
36 lines
886 B
Lua
local state = runtime.import("state")
|
||
local ui = runtime.import("ui")
|
||
---@type RuntimeCommands
|
||
local commands = runtime.import("runtime_commands")
|
||
|
||
function smoke_test(ctx)
|
||
return ctx ~= nil
|
||
and ctx.runtimeApiVersion ~= nil
|
||
and ui.create_nodes ~= nil
|
||
and commands.toast ~= nil
|
||
end
|
||
|
||
function init(ctx)
|
||
state.status = "Template ready: " .. tostring(ctx.gameId or "template")
|
||
return {
|
||
render = { creates = ui.create_nodes() },
|
||
ui = {},
|
||
commands = {}
|
||
}
|
||
end
|
||
|
||
function on_event(event)
|
||
if event.handler == "template_start" then
|
||
state.started = true
|
||
state.clicks = state.clicks + 1
|
||
state.status = "收到 tap 事件,Lua 已返回 Diff 和 toast command。"
|
||
return {
|
||
ui = { updates = ui.state_updates() },
|
||
commands = {
|
||
commands.toast("Template event handled in Lua", { duration = 1.2 })
|
||
}
|
||
}
|
||
end
|
||
return {}
|
||
end
|