---@class (exact) RuntimeCommandOpts ---@field id? string ---@field group? string ---@field commandGroup? string ---@field scope? string ---@field onComplete? string ---@field duration? number ---@class (exact) RuntimeAudioCommandOpts: RuntimeCommandOpts ---@field volume? number ---@class (exact) RuntimeBgmCommandOpts: RuntimeAudioCommandOpts ---@field channel? string ---@field loop? boolean ---@class (exact) RuntimeSpineCommandOpts: RuntimeCommandOpts ---@field track? integer ---@field loop? boolean ---@field queue? boolean ---@field delay? number ---@class (exact) RuntimeResourceCommandOpts: RuntimeCommandOpts ---@field failOnError? boolean ---@class RuntimeCommands local commands = {} ---@param opts? table ---@return table local function copy_opts(opts) local result = {} if opts ~= nil then for key, value in pairs(opts) do result[key] = value end end return result end ---@param command_type RuntimeCommandType ---@param opts? table ---@return RuntimeCommand local function with_type(command_type, opts) local command = copy_opts(opts) command.type = command_type return command end ---@param text string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.toast(text, opts) local command = with_type("toast", opts) command.text = text return command end ---@param text string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.copy_text(text, opts) local command = with_type("copy_text", opts) command.text = text return command end ---@param duration number ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.delay(duration, opts) local command = with_type("delay", opts) command.duration = duration return command end ---@param items RuntimeCommand[] ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.sequence(items, opts) local command = with_type("sequence", opts) command.commands = items or {} return command end ---@param items RuntimeCommand[] ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.parallel(items, opts) local command = with_type("parallel", opts) command.commands = items or {} return command end ---@param target string ---@param path RuntimePoint[] ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.move_path(target, path, opts) local command = with_type("move_path", opts) command.target = target command.path = path or {} return command end ---@param target string ---@param x number ---@param y number ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.move_to(target, x, y, opts) local command = with_type("move_to", opts) command.target = target command.x = x command.y = y return command end ---@param target string ---@param alpha number ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.fade_to(target, alpha, opts) local command = with_type("fade_to", opts) command.target = target command.alpha = alpha return command end ---@param target string ---@param scale number ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.scale_to(target, scale, opts) local command = with_type("scale_to", opts) command.target = target command.scale = scale return command end ---@param target string ---@param angle number ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.rotate_to(target, angle, opts) local command = with_type("rotate_to", opts) command.target = target command.angle = angle return command end ---@param target string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.remove_node(target, opts) local command = with_type("remove_node", opts) command.target = target return command end ---@param target string ---@param animation string ---@param opts? RuntimeSpineCommandOpts ---@return RuntimeCommand function commands.play_spine_animation(target, animation, opts) local command = with_type("play_spine_animation", opts) command.target = target command.animation = animation if command.loop == nil then command.loop = true end return command end ---@param asset string ---@param opts? RuntimeAudioCommandOpts ---@return RuntimeCommand function commands.play_sound(asset, opts) local command = with_type("play_sound", opts) command.asset = asset return command end ---@param asset string ---@param opts? RuntimeBgmCommandOpts ---@return RuntimeCommand function commands.play_bgm(asset, opts) local command = with_type("play_bgm", opts) command.asset = asset if command.channel == nil then command.channel = "bgm" end if command.loop == nil then command.loop = true end return command end ---@param channel? string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.pause_bgm(channel, opts) local command = with_type("pause_bgm", opts) command.channel = channel or "bgm" return command end ---@param channel? string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.resume_bgm(channel, opts) local command = with_type("resume_bgm", opts) command.channel = channel or "bgm" return command end ---@param channel? string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.stop_bgm(channel, opts) local command = with_type("stop_bgm", opts) command.channel = channel or "bgm" return command end ---@param group string ---@param opts? RuntimeResourceCommandOpts ---@return RuntimeCommand function commands.preload_group(group, opts) local command = with_type("preload_resources", opts) command.group = group return command end ---@param group string ---@param opts? RuntimeCommandOpts ---@return RuntimeCommand function commands.evict_group(group, opts) local command = with_type("evict_resources", opts) command.group = group return command end ---@param id string ---@return RuntimeCommand function commands.cancel_id(id) return { type = "cancel_commands", id = id } end ---@param group string ---@return RuntimeCommand function commands.cancel_group(group) return { type = "cancel_commands", group = group } end ---@param scope string ---@return RuntimeCommand function commands.cancel_scope(scope) return { type = "cancel_commands", scope = scope } end return commands