From b4948f1993889c2275c00cc954f2ba8d90089f6d Mon Sep 17 00:00:00 2001 From: A K Date: Mon, 6 Mar 2023 11:29:43 +0100 Subject: [PATCH 1/4] wip ludobits, added broadcast --- packages/ludobits/ludobits-7.3.0.d.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 packages/ludobits/ludobits-7.3.0.d.ts diff --git a/packages/ludobits/ludobits-7.3.0.d.ts b/packages/ludobits/ludobits-7.3.0.d.ts new file mode 100644 index 0000000..144fcfb --- /dev/null +++ b/packages/ludobits/ludobits-7.3.0.d.ts @@ -0,0 +1,13 @@ +/// +/** @noSelfInFile **/ + +/** @noResolution */ +declare module "ludobits.m.broadcast" { + export function register(name: string): void; + + export function unregister(name: string): void; + + export function on_message(message_id: hash, message: any, sender: any): void; + + export function send(message_id: hash, message: any): void; +} From a96f5e70a3ae30de44ce540f348cc1aff20eae97 Mon Sep 17 00:00:00 2001 From: A K Date: Mon, 6 Mar 2023 11:31:57 +0100 Subject: [PATCH 2/4] add library.json --- packages/ludobits/library.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/ludobits/library.json diff --git a/packages/ludobits/library.json b/packages/ludobits/library.json new file mode 100644 index 0000000..2b3f6a5 --- /dev/null +++ b/packages/ludobits/library.json @@ -0,0 +1,4 @@ +{ + "name": "ludobits", + "url": "https://github.com/britzl/ludobits" +} From 9e399e2b5a0e51492da039b340092772eb7cf362 Mon Sep 17 00:00:00 2001 From: A K Date: Tue, 6 Jun 2023 16:42:16 +0200 Subject: [PATCH 3/4] add flow types --- packages/ludobits/ludobits-7.3.0.d.ts | 14 +- packages/ludobits/ludobits.m.broadcast.d.ts | 12 ++ packages/ludobits/ludobits.m.flow.d.ts | 222 ++++++++++++++++++++ 3 files changed, 236 insertions(+), 12 deletions(-) create mode 100644 packages/ludobits/ludobits.m.broadcast.d.ts create mode 100644 packages/ludobits/ludobits.m.flow.d.ts diff --git a/packages/ludobits/ludobits-7.3.0.d.ts b/packages/ludobits/ludobits-7.3.0.d.ts index 144fcfb..b857a95 100644 --- a/packages/ludobits/ludobits-7.3.0.d.ts +++ b/packages/ludobits/ludobits-7.3.0.d.ts @@ -1,13 +1,3 @@ /// -/** @noSelfInFile **/ - -/** @noResolution */ -declare module "ludobits.m.broadcast" { - export function register(name: string): void; - - export function unregister(name: string): void; - - export function on_message(message_id: hash, message: any, sender: any): void; - - export function send(message_id: hash, message: any): void; -} +/// +/// diff --git a/packages/ludobits/ludobits.m.broadcast.d.ts b/packages/ludobits/ludobits.m.broadcast.d.ts new file mode 100644 index 0000000..84a26ae --- /dev/null +++ b/packages/ludobits/ludobits.m.broadcast.d.ts @@ -0,0 +1,12 @@ +/** @noSelfInFile **/ + +/** @noResolution */ +declare module "ludobits.m.broadcast" { + export function register(name: string): void; + + export function unregister(name: string): void; + + export function on_message(message_id: hash, message: any, sender: any): void; + + export function send(message_id: hash, message: any): void; +} diff --git a/packages/ludobits/ludobits.m.flow.d.ts b/packages/ludobits/ludobits.m.flow.d.ts new file mode 100644 index 0000000..7656268 --- /dev/null +++ b/packages/ludobits/ludobits.m.flow.d.ts @@ -0,0 +1,222 @@ +/** @noSelfInFile **/ + +/** @noResolution */ +declare module "ludobits.m.flow" { + export enum FlowType { + READY = "READY", + RUNNING = "RUNNING", + RESUMING = "RESUMING", + WAITING = "WAITING", + } + + export type FlowInstance = { + id: string; + url: url; + state: FlowType; + co: hash | url | string; + timer_id: hash | string; + }; + + /* + Start a new flow. If this function is called from + -- within an existing flow the existing flow can either + -- wait for the new flow to finish or run in parallel + -- @param fn The function to run within the flow + -- @param options Key value pairs. Allowed keys: + -- parallel = true if running flow shouldn't wait for this flow + -- @param on_error Function to call if something goes wrong while + -- running the flow + -- @return The created flow instance + */ + export function start( + fn: () => void, + options: { parallel?: boolean }, + on_error: () => void + ): FlowInstance; + + export function parallel(fn: () => void, on_error: () => void): FlowInstance; + + /* + Wait until a certain time has elapsed + -- @param seconds + */ + export function delay(seconds: number): LuaMultiReturn; + + /* + Stop a created flow before it has completed + -- @param instance This can be either the returned value from + -- a call to @{start}, a coroutine or URL. Defaults to the URL of the + -- running script + */ + export function stop(instance: FlowInstance): void; + + /* + Wait until a certain number of frames have elapsed + -- @param frames + */ + export function frames(frames: number): LuaMultiReturn; + + export function yield(): LuaMultiReturn; + + /* + Wait until a function returns true + -- @param fn + */ + export function until_true(fn: () => boolean): LuaMultiReturn; + + /* + Wait until any message is received + -- @return message_id + -- @return message + -- @return sender + */ + export function until_any_message(): LuaMultiReturn; + + /* + Wait until a specific message is received + -- @param message_1 Message to wait for + -- @param message_2 Message to wait for + -- @param message_n Message to wait for + -- @return message_id + -- @return message + -- @return sender + */ + export function until_message(messages: hash[]): LuaMultiReturn; + + /* + Wait until input action with pressed state + -- @param action_1 Action to wait for (nil for any action) + -- @param action_2 Action to wait for + -- @param action_n Action to wait for + -- @return action_id + -- @return action + */ + export function until_input_pressed(messages: hash[]): LuaMultiReturn; + + /* + --- Wait until input action with released state + -- @param action_1 Action to wait for (nil for any action) + -- @param action_2 Action to wait for + -- @param action_n Action to wait for + -- @return action_id + -- @return action + */ + export function until_input_released(messages: hash[]): LuaMultiReturn; + + /* + Wait until a callback function is invoked + -- @param fn The function to call. The function must take a callback function as its first argument + -- @param arg1 Additional argument to pass to fn + -- @param arg2 Additional argument to pass to fn + -- @param argn Additional argument to pass to fn + -- @return Any values passed to the callback function + */ + export function until_callback( + fn: () => void, + messages: hash[] + ): LuaMultiReturn; + + /* + Load a collection asynchronously and wait until it is loaded and enabled + -- @param collection_url + */ + export function load_async( + collection_url: string | hash | url + ): LuaMultiReturn; + + /* + Unload a collection and wait until it is unloaded + -- @param collection_url The collection to unload + */ + export function unload( + collection_url: string | hash | url + ): LuaMultiReturn; + + /* + Load the resources used by a factory + -- @param factory_url The factory to load resources for + -- @return True if resources were loaded sucessfully + */ + export function load_factory( + factory_url: string | hash | url + ): LuaMultiReturn; + + /* + Load the resources used by a collection factory +-- @param factory_url The collection factory to load resources for +-- @return True if resources were loaded sucessfully +*/ + export function load_collection_factory( + collection_url: url + ): LuaMultiReturn; + + /* + Call go.animate and wait until it has finished +-- @param url +-- @param property +-- @param playback +-- @param to +-- @param easing +-- @param duration +-- @param delay +*/ + export function go_animate( + url: string | hash | url, + property: string | hash, + playback: any, + to: number | vmath.vector3 | vmath.vector4 | vmath.quaternion, + easing: any, + duration: number, + delay?: number + ): LuaMultiReturn; + + /* + Call gui.animate and wait until it has finished + -- NOTE: The argument order differs from gui.animate() (playback is shifted + -- to the same position as for go.animate) + -- @param node + -- @param property + -- @param playback + -- @param to + -- @param easing + -- @param duration + -- @param delay + */ + export function gui_animate( + node: node, + property: any, + to: vmath.vector3 | vmath.vector4, + easing: any, + duration: number, + delay?: number + ): LuaMultiReturn; + + /* + Play a sprite animation and wait until it has finished + -- @param sprite_url + -- @param id + */ + export function play_animation( + sprite_url: string | hash | url, + id: string | hash | url + ): LuaMultiReturn; + + /* + Wait until other flow coroutines were finished + -- @param flows one coroutine or array of coroutines* + */ + export function until_flows(flows: FlowInstance[]): LuaMultiReturn; + + /* + Forward any received messages in your scripts to this function + */ + export function on_message(message_id: any, message: any, sender: any): void; + + export function on_input(action_id: any, action: any): void; + + // TODO: how to do module call function + // + export function constructor(fn: () => void): FlowInstance; + + export default constructor; +} From 2a3940127360a0c52e18723a24a45a207392f976 Mon Sep 17 00:00:00 2001 From: A K Date: Tue, 6 Jun 2023 16:52:10 +0200 Subject: [PATCH 4/4] add example for flow --- packages/ludobits/ludobits.m.flow.d.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/ludobits/ludobits.m.flow.d.ts b/packages/ludobits/ludobits.m.flow.d.ts index 7656268..a8dc9ca 100644 --- a/packages/ludobits/ludobits.m.flow.d.ts +++ b/packages/ludobits/ludobits.m.flow.d.ts @@ -27,11 +27,21 @@ declare module "ludobits.m.flow" { -- @param on_error Function to call if something goes wrong while -- running the flow -- @return The created flow instance + + Example: + + ```js + import * as flow from "ludobits.m.flow" + + flow.start(() => { + // your flow code here. + }); + ``` */ export function start( fn: () => void, - options: { parallel?: boolean }, - on_error: () => void + options?: { parallel?: boolean }, + on_error?: () => void ): FlowInstance; export function parallel(fn: () => void, on_error: () => void): FlowInstance; @@ -213,10 +223,4 @@ declare module "ludobits.m.flow" { export function on_message(message_id: any, message: any, sender: any): void; export function on_input(action_id: any, action: any): void; - - // TODO: how to do module call function - // - export function constructor(fn: () => void): FlowInstance; - - export default constructor; }