Skip to content

Commit c25c09e

Browse files
committed
add flow types
1 parent a96f5e7 commit c25c09e

File tree

3 files changed

+236
-12
lines changed

3 files changed

+236
-12
lines changed

packages/ludobits/ludobits-7.3.0.d.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
/// <library version="7.3.0" src="https://github.com/britzl/ludobits/archive/refs/tags/7.3.0.zip" />
2-
/** @noSelfInFile **/
3-
4-
/** @noResolution */
5-
declare module "ludobits.m.broadcast" {
6-
export function register(name: string): void;
7-
8-
export function unregister(name: string): void;
9-
10-
export function on_message(message_id: hash, message: any, sender: any): void;
11-
12-
export function send(message_id: hash, message: any): void;
13-
}
2+
/// <reference path="./ludobits.m.broadcast.d.ts" />
3+
/// <reference path="./ludobits.m.flow.d.ts" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @noSelfInFile **/
2+
3+
/** @noResolution */
4+
declare module "ludobits.m.broadcast" {
5+
export function register(name: string): void;
6+
7+
export function unregister(name: string): void;
8+
9+
export function on_message(message_id: hash, message: any, sender: any): void;
10+
11+
export function send(message_id: hash, message: any): void;
12+
}
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/** @noSelfInFile **/
2+
3+
/** @noResolution */
4+
declare module "ludobits.m.flow" {
5+
export enum FlowType {
6+
READY = "READY",
7+
RUNNING = "RUNNING",
8+
RESUMING = "RESUMING",
9+
WAITING = "WAITING",
10+
}
11+
12+
export type FlowInstance = {
13+
id: string;
14+
url: url;
15+
state: FlowType;
16+
co: hash | url | string;
17+
timer_id: hash | string;
18+
};
19+
20+
/*
21+
Start a new flow. If this function is called from
22+
-- within an existing flow the existing flow can either
23+
-- wait for the new flow to finish or run in parallel
24+
-- @param fn The function to run within the flow
25+
-- @param options Key value pairs. Allowed keys:
26+
-- parallel = true if running flow shouldn't wait for this flow
27+
-- @param on_error Function to call if something goes wrong while
28+
-- running the flow
29+
-- @return The created flow instance
30+
*/
31+
export function start(
32+
fn: () => void,
33+
options: { parallel?: boolean },
34+
on_error: () => void
35+
): FlowInstance;
36+
37+
export function parallel(fn: () => void, on_error: () => void): FlowInstance;
38+
39+
/*
40+
Wait until a certain time has elapsed
41+
-- @param seconds
42+
*/
43+
export function delay(seconds: number): LuaMultiReturn<any[]>;
44+
45+
/*
46+
Stop a created flow before it has completed
47+
-- @param instance This can be either the returned value from
48+
-- a call to @{start}, a coroutine or URL. Defaults to the URL of the
49+
-- running script
50+
*/
51+
export function stop(instance: FlowInstance): void;
52+
53+
/*
54+
Wait until a certain number of frames have elapsed
55+
-- @param frames
56+
*/
57+
export function frames(frames: number): LuaMultiReturn<any[]>;
58+
59+
export function yield(): LuaMultiReturn<any[]>;
60+
61+
/*
62+
Wait until a function returns true
63+
-- @param fn
64+
*/
65+
export function until_true(fn: () => boolean): LuaMultiReturn<any[]>;
66+
67+
/*
68+
Wait until any message is received
69+
-- @return message_id
70+
-- @return message
71+
-- @return sender
72+
*/
73+
export function until_any_message(): LuaMultiReturn<any[]>;
74+
75+
/*
76+
Wait until a specific message is received
77+
-- @param message_1 Message to wait for
78+
-- @param message_2 Message to wait for
79+
-- @param message_n Message to wait for
80+
-- @return message_id
81+
-- @return message
82+
-- @return sender
83+
*/
84+
export function until_message(messages: hash[]): LuaMultiReturn<any[]>;
85+
86+
/*
87+
Wait until input action with pressed state
88+
-- @param action_1 Action to wait for (nil for any action)
89+
-- @param action_2 Action to wait for
90+
-- @param action_n Action to wait for
91+
-- @return action_id
92+
-- @return action
93+
*/
94+
export function until_input_pressed(messages: hash[]): LuaMultiReturn<any[]>;
95+
96+
/*
97+
--- Wait until input action with released state
98+
-- @param action_1 Action to wait for (nil for any action)
99+
-- @param action_2 Action to wait for
100+
-- @param action_n Action to wait for
101+
-- @return action_id
102+
-- @return action
103+
*/
104+
export function until_input_released(messages: hash[]): LuaMultiReturn<any[]>;
105+
106+
/*
107+
Wait until a callback function is invoked
108+
-- @param fn The function to call. The function must take a callback function as its first argument
109+
-- @param arg1 Additional argument to pass to fn
110+
-- @param arg2 Additional argument to pass to fn
111+
-- @param argn Additional argument to pass to fn
112+
-- @return Any values passed to the callback function
113+
*/
114+
export function until_callback(
115+
fn: () => void,
116+
messages: hash[]
117+
): LuaMultiReturn<any[]>;
118+
119+
/*
120+
Load a collection asynchronously and wait until it is loaded and enabled
121+
-- @param collection_url
122+
*/
123+
export function load_async(
124+
collection_url: string | hash | url
125+
): LuaMultiReturn<any[]>;
126+
127+
/*
128+
Unload a collection and wait until it is unloaded
129+
-- @param collection_url The collection to unload
130+
*/
131+
export function unload(
132+
collection_url: string | hash | url
133+
): LuaMultiReturn<any[]>;
134+
135+
/*
136+
Load the resources used by a factory
137+
-- @param factory_url The factory to load resources for
138+
-- @return True if resources were loaded sucessfully
139+
*/
140+
export function load_factory(
141+
factory_url: string | hash | url
142+
): LuaMultiReturn<any[]>;
143+
144+
/*
145+
Load the resources used by a collection factory
146+
-- @param factory_url The collection factory to load resources for
147+
-- @return True if resources were loaded sucessfully
148+
*/
149+
export function load_collection_factory(
150+
collection_url: url
151+
): LuaMultiReturn<any[]>;
152+
153+
/*
154+
Call go.animate and wait until it has finished
155+
-- @param url
156+
-- @param property
157+
-- @param playback
158+
-- @param to
159+
-- @param easing
160+
-- @param duration
161+
-- @param delay
162+
*/
163+
export function go_animate(
164+
url: string | hash | url,
165+
property: string | hash,
166+
playback: any,
167+
to: number | vmath.vector3 | vmath.vector4 | vmath.quaternion,
168+
easing: any,
169+
duration: number,
170+
delay?: number
171+
): LuaMultiReturn<any[]>;
172+
173+
/*
174+
Call gui.animate and wait until it has finished
175+
-- NOTE: The argument order differs from gui.animate() (playback is shifted
176+
-- to the same position as for go.animate)
177+
-- @param node
178+
-- @param property
179+
-- @param playback
180+
-- @param to
181+
-- @param easing
182+
-- @param duration
183+
-- @param delay
184+
*/
185+
export function gui_animate(
186+
node: node,
187+
property: any,
188+
to: vmath.vector3 | vmath.vector4,
189+
easing: any,
190+
duration: number,
191+
delay?: number
192+
): LuaMultiReturn<any[]>;
193+
194+
/*
195+
Play a sprite animation and wait until it has finished
196+
-- @param sprite_url
197+
-- @param id
198+
*/
199+
export function play_animation(
200+
sprite_url: string | hash | url,
201+
id: string | hash | url
202+
): LuaMultiReturn<any[]>;
203+
204+
/*
205+
Wait until other flow coroutines were finished
206+
-- @param flows one coroutine or array of coroutines*
207+
*/
208+
export function until_flows(flows: FlowInstance[]): LuaMultiReturn<any[]>;
209+
210+
/*
211+
Forward any received messages in your scripts to this function
212+
*/
213+
export function on_message(message_id: any, message: any, sender: any): void;
214+
215+
export function on_input(action_id: any, action: any): void;
216+
217+
// TODO: how to do module call function
218+
//
219+
export function constructor(fn: () => void): FlowInstance;
220+
221+
export default constructor;
222+
}

0 commit comments

Comments
 (0)