@momo2555/koppeliajs 0.0.162 → 0.0.163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
1
1
  import { Console } from "./console.js";
2
2
  import { Message, MessageType, PeerType } from "./message.js";
3
3
  import { Resident } from "./resident.js";
4
+ /**
5
+ * Represents a physical or logical device connected to the console.
6
+ * Handles device-specific commands like LEDs, vibrations, and hardware module subscriptions.
7
+ */
4
8
  export class Device {
5
9
  _address;
6
10
  _color;
@@ -17,20 +21,17 @@ export class Device {
17
21
  this._attachedEvents = [];
18
22
  this.isAttachedToResident = false;
19
23
  }
20
- // public set color(color: Color) {
21
- // this._color = color;
22
- // // TODO : send a request to change the color
23
- // }
24
24
  get color() {
25
25
  return this._color;
26
26
  }
27
- // public set name(name: string) {
28
- // this._name = name;
29
- // // TODO : send a request to change the name
30
- // }
31
27
  get name() {
32
28
  return this._name;
33
29
  }
30
+ /**
31
+ * Subscribes to a specific hardware event for this device.
32
+ * @param eventName The name of the event to listen to.
33
+ * @param callback Function to execute when the event is triggered.
34
+ */
34
35
  onEvent(eventName, callback) {
35
36
  this._attachEvent(eventName);
36
37
  let consoleEvent = (device, from_addr, event) => {
@@ -40,6 +41,10 @@ export class Device {
40
41
  };
41
42
  this._console.onDeviceEvent(consoleEvent);
42
43
  }
44
+ /**
45
+ * Enables the cursor module and listens for coordinate updates.
46
+ * @param callback Function to execute with the incoming (x, y) coordinates.
47
+ */
43
48
  onCursor(callback) {
44
49
  this._enableModule("cursor");
45
50
  this._attachEvent("cursor");
@@ -49,6 +54,10 @@ export class Device {
49
54
  }
50
55
  });
51
56
  }
57
+ /**
58
+ * Enables the biking module and listens for speed updates.
59
+ * @param callback Function to execute with the incoming speed data.
60
+ */
52
61
  onBiking(callback) {
53
62
  this._enableModule("biking");
54
63
  this._attachEvent("biking");
@@ -58,6 +67,10 @@ export class Device {
58
67
  }
59
68
  });
60
69
  }
70
+ /**
71
+ * Enables the vertical detector module and listens for orientation updates.
72
+ * @param callback Function to execute with the boolean vertical state.
73
+ */
61
74
  onVerticalDetector(callback) {
62
75
  this._enableModule("vDetct");
63
76
  this._attachEvent("verticalDetector");
@@ -67,6 +80,10 @@ export class Device {
67
80
  }
68
81
  });
69
82
  }
83
+ /**
84
+ * Sends a request to the device to attach a specific event listener on the hardware side.
85
+ * @param event The event name to attach.
86
+ */
70
87
  _attachEvent(event) {
71
88
  if (!(event in this._attachedEvents)) {
72
89
  let request = new Message();
@@ -77,13 +94,21 @@ export class Device {
77
94
  this._attachedEvents.push(event);
78
95
  }
79
96
  }
80
- _enableModule(moduleNmae) {
97
+ /**
98
+ * Sends a request to the device to enable a specific hardware module.
99
+ * @param moduleName The name of the module to enable (Note: retains original code spelling).
100
+ */
101
+ _enableModule(moduleName) {
81
102
  let request = new Message();
82
- request.addParam("module", moduleNmae);
103
+ request.addParam("module", moduleName);
83
104
  request.setDestination(PeerType.DEVICE, this._address);
84
105
  request.setRequest("enableModule");
85
106
  this._console.sendMessage(request);
86
107
  }
108
+ /**
109
+ * Changes the current LED color of the device.
110
+ * @param color The RGB color configuration to apply.
111
+ */
87
112
  setColor(color) {
88
113
  this._color = color;
89
114
  let request = new Message();
@@ -92,6 +117,11 @@ export class Device {
92
117
  request.setRequest("setColor");
93
118
  this._console.sendMessage(request);
94
119
  }
120
+ /**
121
+ * Sends a predefined sequence of colors to the device.
122
+ * @param sequence Array of color sequence identifiers or configurations.
123
+ * @param reset Whether to interrupt the current sequence before starting the new one.
124
+ */
95
125
  setColorSequence(sequence, reset = false) {
96
126
  let request = new Message();
97
127
  request.setDestination(PeerType.DEVICE, this._address);
@@ -101,11 +131,11 @@ export class Device {
101
131
  this._console.sendMessage(request);
102
132
  }
103
133
  /**
104
- * Vibrate the device (use the motor vibrator)
105
- * @param time
106
- * @param blink
107
- * @param blinkOff
108
- * @param blinkCount
134
+ * Triggers the device's vibration motor.
135
+ * @param time Total vibration time in milliseconds.
136
+ * @param blink Enables pulsating/intermittent vibration.
137
+ * @param blinkOff The duration of the pause between pulses in milliseconds.
138
+ * @param blinkCount The number of pulsing cycles to execute.
109
139
  */
110
140
  vibrate(time, blink = false, blinkOff = 0, blinkCount = 0) {
111
141
  let vibration = {
@@ -124,8 +154,8 @@ export class Device {
124
154
  this._console.sendMessage(request);
125
155
  }
126
156
  /**
127
- * Convert this device object to a json object
128
- * @returns
157
+ * Serializes the Device object into a generic dictionary.
158
+ * @returns A plain object representing the device's current state.
129
159
  */
130
160
  toObject() {
131
161
  return {
@@ -135,8 +165,8 @@ export class Device {
135
165
  };
136
166
  }
137
167
  /**
138
- * set the device object from a json object
139
- * @param object
168
+ * Hydrates the Device instance using properties from a provided object.
169
+ * @param object The plain object containing device properties.
140
170
  */
141
171
  fromObject(object) {
142
172
  if (object.address !== undefined) {
@@ -5,6 +5,11 @@ import { Play } from "./play.js";
5
5
  import { Resident } from "./resident.js";
6
6
  import { type OptionChangedCallback } from "./option.js";
7
7
  import { Song } from "./song.js";
8
+ /**
9
+ * The main Koppelia framework entry point.
10
+ * Implements a Singleton pattern to provide global access to the console, state, stages,
11
+ * devices, and game synchronization features across the Svelte application.
12
+ */
8
13
  export declare class Koppelia {
9
14
  private _console;
10
15
  private _state;
@@ -12,114 +17,228 @@ export declare class Koppelia {
12
17
  private static _instance;
13
18
  private _option;
14
19
  private _callbacks;
15
- constructor();
20
+ private constructor();
21
+ /**
22
+ * Retrieves the singleton instance of the Koppelia class.
23
+ * Instantiates it if it does not yet exist.
24
+ */
16
25
  static get instance(): Koppelia;
26
+ /**
27
+ * Retrieves the global Svelte writable store representing the synchronized game state.
28
+ */
17
29
  get state(): Writable<AnyState>;
30
+ /**
31
+ * Merges a partial update into the current global state and broadcasts the change.
32
+ * @param stateUpdate A dictionary containing the keys/values to update.
33
+ */
18
34
  updateState(stateUpdate: AnyState): void;
35
+ /**
36
+ * Completely overwrites the global state with a new state object.
37
+ * @param newState The new state object to apply.
38
+ */
19
39
  setState(newState: AnyState): void;
40
+ /**
41
+ * Checks if the underlying WebSocket console connection is fully established.
42
+ */
20
43
  get ready(): boolean;
44
+ /**
45
+ * Enables or disables debug mode for extended console logging.
46
+ * @param enable True to enable debug logs, false to disable.
47
+ */
21
48
  setDebugMode(enable: boolean): void;
22
49
  /**
23
- * Add a callback that will be called when the connection to the console is entirely ready
24
- *
25
- * @param callback
50
+ * Registers a callback to execute when the console connection is fully ready.
51
+ * @param callback The function to execute.
26
52
  */
27
53
  onReady(callback: () => void): void;
28
54
  /**
29
- * Init the default state of the game and the list of all stages
30
- *
31
- * @param defaultState Default state that be initialized
32
- * @param stages List of all stages
55
+ * Initializes the default state and the routing stages of the game.
56
+ * Specifically executes for "monitor" peers to ensure the primary game view sets the rules.
57
+ * @param defaultState The initial state structure.
58
+ * @param stages An array of valid stage names for application routing.
33
59
  */
34
60
  init(defaultState: AnyState, stages: string[]): void;
35
61
  /**
36
- * Go to a stage, the stage must be in the stage list
37
- * Before changing the staging all callbacks will be destroyed
38
- * If the stage list is empty the console will return an error
39
- * @param stageName
62
+ * Requests a transition to a specific stage (view) across the network.
63
+ * Note: All active console event listeners will be destroyed before transition.
64
+ * @param stageName The target stage to navigate to.
40
65
  */
41
66
  goto(stageName: string): void;
67
+ /**
68
+ * Normalizes a media URL to ensure cross-client compatibility.
69
+ * @param mediaUrl The raw media URL.
70
+ * @returns The corrected URL.
71
+ */
42
72
  fixMediaUrl(mediaUrl: string): string;
73
+ /**
74
+ * Constructs the full URL for a given relative media path.
75
+ * @param path The relative media path.
76
+ * @returns The full URL string.
77
+ */
43
78
  getMediaLink(path: string): string;
44
79
  /**
45
- * Get the list of devices in a callback
46
- * @param callback
80
+ * Asynchronously fetches the list of available connected devices from the master peer.
81
+ * @returns A promise resolving to an array of instantiated Device objects.
47
82
  */
48
83
  getDevices(): Promise<Device[]>;
49
84
  /**
50
- * Get the game ID of the current game
51
- * @returns the game id as a string
85
+ * Retrieves the unique identifier of the currently loaded game.
86
+ * @returns The game ID string provided by public environment variables.
52
87
  */
53
88
  getGameId(): string;
54
89
  /**
55
- * Get the list of plays, the plays returned by this function doesn't include the raw
56
- * You have to call a function in from the play object to download all the raw files
57
- * @param count limit of plays to get
58
- * @param index index from which to start fetching the plays
59
- * @param orderBy order by date or name
60
- * @returns the List of plays an array of objects of type Play,
90
+ * Asynchronously fetches a paginated list of Play sessions.
91
+ * Note: This only fetches metadata. Specific Play content must be downloaded via Play methods.
92
+ * @param count Maximum number of plays to retrieve (default: 10).
93
+ * @param index The starting offset index (default: 0).
94
+ * @param orderBy Sorting criteria, e.g., "date" or "name" (default: "date").
95
+ * @returns A promise resolving to an array of Play instances.
61
96
  */
62
97
  getPlays(count?: number, index?: number, orderBy?: string): Promise<Play[]>;
98
+ /**
99
+ * Asynchronously fetches the list of registered residents/players.
100
+ * @returns A promise resolving to an array of Resident instances.
101
+ */
63
102
  getResidents(): Promise<Resident[]>;
103
+ /**
104
+ * Asynchronously fetches a specific song by its unique ID.
105
+ * @param songId The ID of the song to retrieve.
106
+ * @returns A promise resolving to the corresponding Song instance.
107
+ */
64
108
  getSongById(songId: string): Promise<Song>;
109
+ /**
110
+ * Asynchronously fetches a dictionary of all songs associated with the currently active play.
111
+ * @returns A promise resolving to a map of song IDs to Song instances.
112
+ */
65
113
  getCurrentPlaySongs(): Promise<{
66
114
  [key: string]: Song;
67
115
  }>;
68
116
  /**
69
- * Get the current play that has been set
70
- * @returns the current play
117
+ * Asynchronously retrieves the currently active Play instance set on the server.
118
+ * @returns A promise resolving to the active Play.
71
119
  */
72
120
  getCurrentPlay(): Promise<Play>;
73
121
  /**
74
- * This function enables the difficulty cursor, to change the difficulty live when playing from Koppeli'App
75
- * @param callback : callback to call when difficulty changes
122
+ * Enables a live difficulty cursor, allowing difficulty changes during gameplay.
123
+ * @param callback Function to execute when the difficulty changes.
76
124
  */
77
125
  enableDifficultyCursor(callback: (difficulty: number) => void): Promise<void>;
78
126
  /**
79
- * @param id
80
- * @param onGrowChange
127
+ * Registers a new growable element on the network and listens for state changes.
128
+ * @param id The unique identifier for the growable element.
129
+ * @param onGrowChange Callback triggered when the 'grown' state of the element changes.
81
130
  */
82
131
  registerNewGrowableElement(id: string, onGrowChange: (grown: boolean) => void): Promise<void>;
83
132
  /**
84
- * @param id
85
- * @param grown
133
+ * Updates the 'grown' state of a registered growable element across the network.
134
+ * @param id The unique identifier of the element.
135
+ * @param grown True if the element is in a grown state, false otherwise.
86
136
  */
87
137
  updateGrowableElement(id: string, grown: boolean): Promise<void>;
88
138
  /**
89
- * Add a new resizable text element and define the callback that will be executed when receive and a resizable
90
- * text update notification form koppelia application
139
+ * Registers a new resizable text element with a default font size (Monitor only).
140
+ * @param id The unique identifier for the text element.
141
+ * @param defaultSize The default font size.
91
142
  */
92
143
  registerNewResizableText(id: string, defaultSize: number): Promise<void>;
144
+ /**
145
+ * Subscribes to size change notifications for a specific resizable text element.
146
+ * @param id The unique identifier of the text element.
147
+ * @param onTextResized Callback executed with the new font size.
148
+ * @returns The unique subscription ID used for unsubscribing.
149
+ */
93
150
  onResizableTextChanged(id: string, onTextResized: (newSize: number) => void): string;
151
+ /**
152
+ * Unsubscribes a previously registered resizable text listener.
153
+ * @param callbackId The subscription ID returned by onResizableTextChanged.
154
+ */
94
155
  unsubResizableText(callbackId: string): void;
156
+ /**
157
+ * Retrieves the list of all registered resizable text elements from the master.
158
+ * @returns A promise resolving to an array of resizable element data objects.
159
+ */
95
160
  getResizableTexts(): Promise<{
96
161
  [key: string]: any;
97
162
  }[]>;
163
+ /**
164
+ * Writes configuration data to the master peer, optionally binding it to the current play.
165
+ * @param config_id The unique identifier for this configuration data.
166
+ * @param config_value The dictionary containing the configuration payload.
167
+ * @param current_play Whether to bind this configuration to the active play session (default: true).
168
+ */
98
169
  writeGameConfig(config_id: string, config_value: {
99
170
  [key: string]: any;
100
171
  }, current_play?: boolean): Promise<void>;
172
+ /**
173
+ * Retrieves persistent configuration data from the master peer.
174
+ * @param config_id The unique identifier of the configuration data to fetch.
175
+ * @param current_play True to fetch data bound specifically to the active play, false otherwise.
176
+ * @returns A promise resolving to the configuration dictionary.
177
+ */
101
178
  getGameConfig(config_id: string, current_play: boolean): Promise<{
102
179
  [key: string]: any;
103
180
  }>;
104
181
  /**
105
- * @param sentence
182
+ * Broadcasts a Text-to-Speech synthesis request to the Maestro peer.
183
+ * @param sentence The text string to be spoken out loud.
106
184
  */
107
185
  say(sentence: string): void;
108
186
  /**
109
- * Set a new or edit a game option
110
- * @param name Name fo the option
111
- * @param value Value of the option
187
+ * Assigns a basic value to a registered game option via the option manager.
188
+ * @param name The unique name of the option.
189
+ * @param value The value to set.
112
190
  */
113
191
  setOption(name: string, value: any): void;
192
+ /**
193
+ * Creates or updates an interactive slider option.
194
+ * @param name The unique identifier for the slider.
195
+ * @param label The display label for the UI.
196
+ * @param value The current numeric value.
197
+ * @param min The minimum allowed value.
198
+ * @param max The maximum allowed value.
199
+ * @param step The increment step size.
200
+ */
114
201
  createSliderOtption(name: string, label: string, value: number, min: number, max: number, step: number): void;
202
+ /**
203
+ * Creates or updates an interactive toggle switch option.
204
+ * @param name The unique identifier for the switch.
205
+ * @param label The display label for the UI.
206
+ * @param value The current boolean state.
207
+ */
115
208
  createSwitchOption(name: string, label: string, value: boolean): void;
209
+ /**
210
+ * Creates or updates a multiple-choice selection option.
211
+ * @param name The unique identifier for the option.
212
+ * @param label The display label for the UI.
213
+ * @param value The currently selected choice.
214
+ * @param choices An array of available string choices.
215
+ */
116
216
  createChoicesOption(name: string, label: string, value: string, choices: string[]): void;
217
+ /**
218
+ * Registers a callback listener to trigger whenever a specific option's value changes.
219
+ * @param name The name of the option to observe.
220
+ * @param callback The function to execute on change.
221
+ */
117
222
  onOptionChanged(name: string, callback: OptionChangedCallback): void;
223
+ /**
224
+ * Executes a broadcasted network request to trigger a registered custom callback.
225
+ * @param callbackName The unique registered name of the custom callback.
226
+ * @param args Dictionary of arguments to pass to the callback.
227
+ */
118
228
  run(callbackName: string, args: {
119
229
  [key: string]: any;
120
230
  }): void;
231
+ /**
232
+ * Registers a local function to listen for network execution of a custom callback.
233
+ * @param callbackName The identifier for this callback.
234
+ * @param callback The local function to execute.
235
+ */
121
236
  on(callbackName: string, callback: (args: {
122
237
  [key: string]: any;
123
238
  }) => void): void;
239
+ /**
240
+ * Unregisters a locally listening custom callback.
241
+ * @param callbackName The identifier of the callback to remove.
242
+ */
124
243
  unsub(callbackName: string): void;
125
244
  }