@momo2555/koppeliajs 0.0.148 → 0.0.149
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.
|
@@ -61,6 +61,7 @@ export declare class Console {
|
|
|
61
61
|
*/
|
|
62
62
|
onReady(callback: () => void): void;
|
|
63
63
|
onDeviceEvent(callback: DeviceEventCallback): void;
|
|
64
|
+
onDataExchange(callback: DataExchangeCallback): void;
|
|
64
65
|
onRequest(callback: AnyRequestCallback): void;
|
|
65
66
|
/**
|
|
66
67
|
* Get if the connection with the console is ready
|
package/dist/scripts/console.js
CHANGED
|
@@ -102,6 +102,9 @@ export class Console {
|
|
|
102
102
|
onDeviceEvent(callback) {
|
|
103
103
|
this._deviceEventHandlers.push(callback);
|
|
104
104
|
}
|
|
105
|
+
onDataExchange(callback) {
|
|
106
|
+
this._dataExchangeHandlers.push(callback);
|
|
107
|
+
}
|
|
105
108
|
onRequest(callback) {
|
|
106
109
|
this._anyRequestHandlers.push(callback);
|
|
107
110
|
}
|
|
@@ -226,7 +229,6 @@ export class Console {
|
|
|
226
229
|
destroyEvents() {
|
|
227
230
|
this._deviceEventHandlers = [];
|
|
228
231
|
this._deviceDataHandlers = [];
|
|
229
|
-
this._dataExchangeHandlers = [];
|
|
230
232
|
this._anyRequestHandlers = [];
|
|
231
233
|
logger.log("destroy events event handlers");
|
|
232
234
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Console } from "./console.js";
|
|
2
|
+
export declare class CustomCallbacks {
|
|
3
|
+
private _console;
|
|
4
|
+
private _customCallbacks;
|
|
5
|
+
constructor(console: Console);
|
|
6
|
+
runCustomCallback(name: string, args: {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}): void;
|
|
9
|
+
registerCustomCallback(name: string, callback: (args: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}) => void): void;
|
|
12
|
+
unregisterCustomCallback(name: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Message, MessageType, PeerType } from "./message.js";
|
|
2
|
+
export class CustomCallbacks {
|
|
3
|
+
_console;
|
|
4
|
+
_customCallbacks;
|
|
5
|
+
constructor(console) {
|
|
6
|
+
this._console = console;
|
|
7
|
+
this._console.onReady(() => {
|
|
8
|
+
});
|
|
9
|
+
this._customCallbacks = {};
|
|
10
|
+
this._console.onDataExchange((from, data) => {
|
|
11
|
+
if (data.custumCallbackName != undefined &&
|
|
12
|
+
data.customCallbackArgs != undefined) {
|
|
13
|
+
if (Object.hasOwn(this._customCallbacks, data.custumCallbackName)) {
|
|
14
|
+
this._customCallbacks[data.custumCallbackName](data.customCallbackArgs);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
runCustomCallback(name, args) {
|
|
20
|
+
let customCallbackRequest = new Message();
|
|
21
|
+
customCallbackRequest.setType(MessageType.DATA_EXCHANGE);
|
|
22
|
+
customCallbackRequest.addData("custumCallbackName", name);
|
|
23
|
+
customCallbackRequest.addData("customCallbackArgs", args);
|
|
24
|
+
customCallbackRequest.setDestination(PeerType.MASTER, "");
|
|
25
|
+
this._console.sendMessage(customCallbackRequest);
|
|
26
|
+
}
|
|
27
|
+
registerCustomCallback(name, callback) {
|
|
28
|
+
this._customCallbacks[name] = callback;
|
|
29
|
+
}
|
|
30
|
+
unregisterCustomCallback(name) {
|
|
31
|
+
if (Object.hasOwn(this._customCallbacks, name)) {
|
|
32
|
+
delete this._customCallbacks[name];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -10,6 +10,7 @@ export declare class Koppelia {
|
|
|
10
10
|
private _stage;
|
|
11
11
|
private static _instance;
|
|
12
12
|
private _option;
|
|
13
|
+
private _callbacks;
|
|
13
14
|
constructor();
|
|
14
15
|
static get instance(): Koppelia;
|
|
15
16
|
get state(): Writable<AnyState>;
|
|
@@ -104,4 +105,11 @@ export declare class Koppelia {
|
|
|
104
105
|
createSwitchOption(name: string, label: string, value: boolean): void;
|
|
105
106
|
createChoicesOption(name: string, label: string, value: string, choices: string[]): void;
|
|
106
107
|
onOptionChanged(name: string, callback: OptionChangedCallback): void;
|
|
108
|
+
run(callbackName: string, args: {
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
}): void;
|
|
111
|
+
on(callbackName: string, callback: (args: {
|
|
112
|
+
[key: string]: any;
|
|
113
|
+
}) => void): void;
|
|
114
|
+
unsub(callbackName: string): void;
|
|
107
115
|
}
|
package/dist/scripts/koppelia.js
CHANGED
|
@@ -10,14 +10,17 @@ import { PUBLIC_GAME_ID } from "$env/static/public";
|
|
|
10
10
|
import { Resident } from "./resident.js";
|
|
11
11
|
import { Option } from "./option.js";
|
|
12
12
|
import { logger, setDebugMode } from "./logger.js";
|
|
13
|
+
import { CustomCallbacks } from "./customCallback.js";
|
|
13
14
|
export class Koppelia {
|
|
14
15
|
_console;
|
|
15
16
|
_state;
|
|
16
17
|
_stage;
|
|
17
18
|
static _instance;
|
|
18
19
|
_option;
|
|
20
|
+
_callbacks;
|
|
19
21
|
constructor() {
|
|
20
22
|
this._console = new Console();
|
|
23
|
+
this._callbacks = new CustomCallbacks(this._console);
|
|
21
24
|
this._console.onReady(() => {
|
|
22
25
|
let type = get(routeType);
|
|
23
26
|
if (type == "controller") {
|
|
@@ -32,9 +35,7 @@ export class Koppelia {
|
|
|
32
35
|
logger.log("Cannot identifiy type ", type);
|
|
33
36
|
}
|
|
34
37
|
});
|
|
35
|
-
this._state = new State(this._console, {
|
|
36
|
-
hey: "coucou",
|
|
37
|
-
});
|
|
38
|
+
this._state = new State(this._console, {});
|
|
38
39
|
this._stage = new Stage(this._console);
|
|
39
40
|
this._option = new Option(this._console);
|
|
40
41
|
}
|
|
@@ -337,4 +338,13 @@ export class Koppelia {
|
|
|
337
338
|
onOptionChanged(name, callback) {
|
|
338
339
|
this._option.onOptionChanged(name, callback);
|
|
339
340
|
}
|
|
341
|
+
run(callbackName, args) {
|
|
342
|
+
this._callbacks.runCustomCallback(callbackName, args);
|
|
343
|
+
}
|
|
344
|
+
on(callbackName, callback) {
|
|
345
|
+
this._callbacks.registerCustomCallback(callbackName, callback);
|
|
346
|
+
}
|
|
347
|
+
unsub(callbackName) {
|
|
348
|
+
this._callbacks.unregisterCustomCallback(callbackName);
|
|
349
|
+
}
|
|
340
350
|
}
|