Initial flame_lua_runtime package
This commit is contained in:
35
example/assets/games/template/scripts/main.lua
Normal file
35
example/assets/games/template/scripts/main.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
Reference in New Issue
Block a user