@momo2555/koppeliajs 0.0.91

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.
Files changed (46) hide show
  1. package/README.md +110 -0
  2. package/dist/components/DynamicCursor.svelte +0 -0
  3. package/dist/components/DynamicCursor.svelte.d.ts +26 -0
  4. package/dist/components/DynamicTextField.svelte +0 -0
  5. package/dist/components/DynamicTextField.svelte.d.ts +26 -0
  6. package/dist/components/GrowableElement.svelte +62 -0
  7. package/dist/components/GrowableElement.svelte.d.ts +29 -0
  8. package/dist/components/KBase.svelte +8 -0
  9. package/dist/components/KBase.svelte.d.ts +22 -0
  10. package/dist/components/KButton.svelte +0 -0
  11. package/dist/components/KButton.svelte.d.ts +26 -0
  12. package/dist/components/Koppelia.svelte +11 -0
  13. package/dist/components/Koppelia.svelte.d.ts +20 -0
  14. package/dist/components/ResizableText.svelte +0 -0
  15. package/dist/components/ResizableText.svelte.d.ts +26 -0
  16. package/dist/index.d.ts +11 -0
  17. package/dist/index.js +12 -0
  18. package/dist/scripts/console.d.ts +75 -0
  19. package/dist/scripts/console.js +180 -0
  20. package/dist/scripts/device.d.ts +49 -0
  21. package/dist/scripts/device.js +123 -0
  22. package/dist/scripts/game.d.ts +5 -0
  23. package/dist/scripts/game.js +8 -0
  24. package/dist/scripts/koppelia.d.ts +70 -0
  25. package/dist/scripts/koppelia.js +196 -0
  26. package/dist/scripts/koppeliaWebsocket.d.ts +77 -0
  27. package/dist/scripts/koppeliaWebsocket.js +159 -0
  28. package/dist/scripts/message.d.ts +116 -0
  29. package/dist/scripts/message.js +178 -0
  30. package/dist/scripts/play.d.ts +49 -0
  31. package/dist/scripts/play.js +107 -0
  32. package/dist/scripts/stage.d.ts +12 -0
  33. package/dist/scripts/stage.js +38 -0
  34. package/dist/scripts/state.d.ts +36 -0
  35. package/dist/scripts/state.js +82 -0
  36. package/dist/scripts/utils.d.ts +1 -0
  37. package/dist/scripts/utils.js +5 -0
  38. package/dist/server/index.d.ts +2 -0
  39. package/dist/server/index.js +2 -0
  40. package/dist/server/koppeliaServerApi.d.ts +7 -0
  41. package/dist/server/koppeliaServerApi.js +97 -0
  42. package/dist/stores/routeStore.d.ts +2 -0
  43. package/dist/stores/routeStore.js +21 -0
  44. package/dist/stores/stateStore.d.ts +1 -0
  45. package/dist/stores/stateStore.js +7 -0
  46. package/package.json +64 -0
@@ -0,0 +1,116 @@
1
+ export type AnyRequest = {
2
+ [key: string]: any;
3
+ };
4
+ export declare enum PeerType {
5
+ MONITOR = "monitor",
6
+ MASTER = "master",
7
+ CONTROLLER = "controller",
8
+ DEVICE = "device",
9
+ SPECTAKLE = "spectakle",
10
+ KOPPELIA = "koppelia",
11
+ NONE = "none"
12
+ }
13
+ export declare enum MessageType {
14
+ EMPTY = "empty",
15
+ REQUEST = "request",
16
+ RESPONSE = "response",
17
+ DATA_EXCHANGE = "data_exchange",
18
+ DEVICE_EVENT = "device_event",
19
+ DEVICE_DATA = "device_data",
20
+ IDENTIFICATION = "identification",
21
+ MODULE_ENABLE = "module_enable",
22
+ ERROR = "error"
23
+ }
24
+ type MessagetHeader = {
25
+ id: string;
26
+ type: string;
27
+ from: string;
28
+ to: string;
29
+ from_addr: string;
30
+ to_addr: string;
31
+ device: string;
32
+ };
33
+ export type MessageData = {
34
+ [key: string]: string;
35
+ };
36
+ type MessageEvent = string;
37
+ type DirectRequest = {
38
+ exec: string;
39
+ params: {
40
+ [key: string]: any;
41
+ };
42
+ };
43
+ /**
44
+ * The koppelia protocol
45
+ */
46
+ export declare class Message {
47
+ header: MessagetHeader;
48
+ data: MessageData;
49
+ request: DirectRequest;
50
+ event: MessageEvent;
51
+ constructor();
52
+ /**
53
+ * Parse a json request received from the network
54
+ * @param data
55
+ */
56
+ parse(data: AnyRequest): void;
57
+ /**
58
+ * Convert the request to json, to be sent on the network
59
+ * @returns
60
+ */
61
+ toObject(): AnyRequest;
62
+ /**
63
+ * Set the source device, type and address (if there is address)
64
+ * @param type
65
+ * @param address
66
+ */
67
+ setSource(type: PeerType, address?: string): void;
68
+ /**
69
+ * Set the destination device, type and address
70
+ * @param type
71
+ * @param address
72
+ */
73
+ setDestination(type: PeerType, address?: string): void;
74
+ /**
75
+ * Get event name of the request, if it is an event
76
+ * @returns
77
+ */
78
+ getEvent(): MessageEvent;
79
+ /**
80
+ * Set the type of the request
81
+ * @param type
82
+ */
83
+ setType(type: MessageType): void;
84
+ /**
85
+ * Set an event to the request
86
+ * @param event
87
+ */
88
+ setEvent(event: MessageEvent): void;
89
+ /**
90
+ * Add a param if the request is request type
91
+ * @param key
92
+ * @param value
93
+ */
94
+ addParam(key: string, value: any): void;
95
+ /**
96
+ * Add data to the request
97
+ * @param key
98
+ * @param value
99
+ */
100
+ addData(key: string, value: any): void;
101
+ /**
102
+ *
103
+ * @param data
104
+ */
105
+ setData(data: MessageData): void;
106
+ /**
107
+ * Set a new request with a request name
108
+ * @param execName name of
109
+ */
110
+ setRequest(execName: string): void;
111
+ getParam(paramName: string, def?: any): any;
112
+ setIdentification(peerToIdentify: PeerType): void;
113
+ generateRequestId(): void;
114
+ getRequestId(): string;
115
+ }
116
+ export {};
@@ -0,0 +1,178 @@
1
+ export var PeerType;
2
+ (function (PeerType) {
3
+ PeerType["MONITOR"] = "monitor";
4
+ PeerType["MASTER"] = "master";
5
+ PeerType["CONTROLLER"] = "controller";
6
+ PeerType["DEVICE"] = "device";
7
+ PeerType["SPECTAKLE"] = "spectakle";
8
+ PeerType["KOPPELIA"] = "koppelia";
9
+ PeerType["NONE"] = "none";
10
+ })(PeerType || (PeerType = {}));
11
+ ;
12
+ export var MessageType;
13
+ (function (MessageType) {
14
+ MessageType["EMPTY"] = "empty";
15
+ MessageType["REQUEST"] = "request";
16
+ MessageType["RESPONSE"] = "response";
17
+ MessageType["DATA_EXCHANGE"] = "data_exchange";
18
+ MessageType["DEVICE_EVENT"] = "device_event";
19
+ MessageType["DEVICE_DATA"] = "device_data";
20
+ MessageType["IDENTIFICATION"] = "identification";
21
+ MessageType["MODULE_ENABLE"] = "module_enable";
22
+ MessageType["ERROR"] = "error";
23
+ })(MessageType || (MessageType = {}));
24
+ /**
25
+ * The koppelia protocol
26
+ */
27
+ export class Message {
28
+ header;
29
+ data;
30
+ request;
31
+ event;
32
+ constructor() {
33
+ this.header = {
34
+ id: "",
35
+ type: MessageType.EMPTY,
36
+ from: PeerType.NONE,
37
+ to: PeerType.NONE,
38
+ from_addr: "",
39
+ to_addr: "",
40
+ device: "",
41
+ };
42
+ this.data = {};
43
+ this.request = {
44
+ exec: "",
45
+ params: {}
46
+ };
47
+ this.event = "";
48
+ }
49
+ /**
50
+ * Parse a json request received from the network
51
+ * @param data
52
+ */
53
+ parse(data) {
54
+ if (data.header !== undefined) {
55
+ for (let key in data.header) {
56
+ if (key in this.header) {
57
+ this.header[key] = data.header[key];
58
+ }
59
+ }
60
+ }
61
+ if (data.data !== undefined) {
62
+ this.data = data.data;
63
+ }
64
+ if (data.event !== undefined && typeof data.event === "string") {
65
+ this.event = data.event;
66
+ }
67
+ if (data.request !== undefined) {
68
+ if (data.request.exec !== undefined) {
69
+ this.request.exec = data.request.exec;
70
+ }
71
+ if (data.request.params !== undefined) {
72
+ this.request.params = data.request.params;
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * Convert the request to json, to be sent on the network
78
+ * @returns
79
+ */
80
+ toObject() {
81
+ return {
82
+ header: this.header,
83
+ request: this.request,
84
+ data: this.data,
85
+ event: this.event
86
+ };
87
+ }
88
+ /**
89
+ * Set the source device, type and address (if there is address)
90
+ * @param type
91
+ * @param address
92
+ */
93
+ setSource(type, address = "") {
94
+ this.header.from = type;
95
+ this.header.from_addr = address;
96
+ }
97
+ /**
98
+ * Set the destination device, type and address
99
+ * @param type
100
+ * @param address
101
+ */
102
+ setDestination(type, address = "") {
103
+ this.header.to = type;
104
+ this.header.to_addr = address;
105
+ }
106
+ /**
107
+ * Get event name of the request, if it is an event
108
+ * @returns
109
+ */
110
+ getEvent() {
111
+ return this.event;
112
+ }
113
+ /**
114
+ * Set the type of the request
115
+ * @param type
116
+ */
117
+ setType(type) {
118
+ this.header.type = type;
119
+ }
120
+ /**
121
+ * Set an event to the request
122
+ * @param event
123
+ */
124
+ setEvent(event) {
125
+ this.header.type = MessageType.REQUEST;
126
+ this.event = event;
127
+ }
128
+ /**
129
+ * Add a param if the request is request type
130
+ * @param key
131
+ * @param value
132
+ */
133
+ addParam(key, value) {
134
+ this.request.params[key] = value;
135
+ }
136
+ /**
137
+ * Add data to the request
138
+ * @param key
139
+ * @param value
140
+ */
141
+ addData(key, value) {
142
+ this.data[key] = value;
143
+ }
144
+ /**
145
+ *
146
+ * @param data
147
+ */
148
+ setData(data) {
149
+ this.data = data;
150
+ }
151
+ /**
152
+ * Set a new request with a request name
153
+ * @param execName name of
154
+ */
155
+ setRequest(execName) {
156
+ this.header.type = MessageType.REQUEST;
157
+ this.request.exec = execName;
158
+ }
159
+ getParam(paramName, def = null) {
160
+ if (paramName in this.request.params) {
161
+ return this.request.params[paramName];
162
+ }
163
+ else {
164
+ return def;
165
+ }
166
+ }
167
+ setIdentification(peerToIdentify) {
168
+ this.header.type = MessageType.IDENTIFICATION;
169
+ this.header.from = peerToIdentify;
170
+ }
171
+ generateRequestId() {
172
+ this.header.id = crypto.randomUUID();
173
+ ;
174
+ }
175
+ getRequestId() {
176
+ return this.header.id;
177
+ }
178
+ }
@@ -0,0 +1,49 @@
1
+ import { Console } from "./console.js";
2
+ export declare class Play {
3
+ private _playCreationDate;
4
+ private _playCreatorId;
5
+ private _playFileName;
6
+ private _playGameId;
7
+ private _playIsPrivate;
8
+ private _playImagebase64;
9
+ private _playMedias;
10
+ private _playName;
11
+ private _playId;
12
+ private _playData;
13
+ private _base64Medias;
14
+ private _console;
15
+ private _refreshed;
16
+ constructor(console: Console, playId: string, playRawObj: {
17
+ [key: string]: any;
18
+ });
19
+ refresh(): Promise<void>;
20
+ /**
21
+ * Get the list of all media files of the play
22
+ */
23
+ get mediasList(): string[];
24
+ /**
25
+ * Get the media file by using its name. This function returns a base64 file
26
+ * @param mediaName
27
+ * @returns
28
+ */
29
+ getMedia(mediaName: string): string | undefined;
30
+ /**
31
+ * Get the data of the play
32
+ */
33
+ get data(): {
34
+ [key: string]: any;
35
+ };
36
+ /**
37
+ * Get the id of the play
38
+ */
39
+ get id(): string;
40
+ /**
41
+ * Get the name of the play
42
+ */
43
+ get name(): string;
44
+ /**
45
+ * Get the image base64
46
+ */
47
+ get image(): string;
48
+ get isRefreshed(): boolean;
49
+ }
@@ -0,0 +1,107 @@
1
+ import { Console } from "./console.js";
2
+ import { Message, PeerType } from "./message.js";
3
+ export class Play {
4
+ _playCreationDate = "";
5
+ _playCreatorId = "";
6
+ _playFileName = "";
7
+ _playGameId = "";
8
+ _playIsPrivate = "";
9
+ _playImagebase64 = "";
10
+ _playMedias = [];
11
+ _playName = "";
12
+ _playId = "";
13
+ _playData = {};
14
+ _base64Medias = {};
15
+ _console;
16
+ _refreshed = true;
17
+ constructor(console, playId, playRawObj) {
18
+ this._console = console;
19
+ this._playId = playId;
20
+ if (playRawObj._play_data_json !== undefined) {
21
+ this._playData = playRawObj._play_data_json;
22
+ this._refreshed = true;
23
+ }
24
+ ;
25
+ if (playRawObj._play_medias_raw !== undefined) {
26
+ this._base64Medias = playRawObj._play_medias_raw;
27
+ }
28
+ if (playRawObj.playName !== undefined) {
29
+ this._playName = playRawObj.playName;
30
+ }
31
+ if (playRawObj.playMedias !== undefined) {
32
+ this._playMedias = playRawObj.playMedias;
33
+ }
34
+ if (playRawObj._play_image_raw !== undefined) {
35
+ this._playImagebase64 = playRawObj._play_image_raw;
36
+ }
37
+ }
38
+ async refresh() {
39
+ return new Promise((resolve, reject) => {
40
+ let getPlaysRequest = new Message();
41
+ getPlaysRequest.setRequest("getPlayRaw");
42
+ getPlaysRequest.addParam("playId", this.id);
43
+ getPlaysRequest.setDestination(PeerType.MASTER, "");
44
+ this._console.sendMessage(getPlaysRequest, (response) => {
45
+ let playRawObj = response.getParam("play", {});
46
+ if (playRawObj._play_data_json !== undefined) {
47
+ this._playData = playRawObj._play_data_json;
48
+ this._refreshed = true;
49
+ }
50
+ ;
51
+ if (playRawObj._play_medias_raw !== undefined) {
52
+ this._base64Medias = playRawObj._play_medias_raw;
53
+ }
54
+ if (playRawObj._play_image_raw !== undefined) {
55
+ this._playImagebase64 = playRawObj._play_image_raw;
56
+ }
57
+ resolve();
58
+ });
59
+ });
60
+ }
61
+ /**
62
+ * Get the list of all media files of the play
63
+ */
64
+ get mediasList() {
65
+ return Object.keys(this._base64Medias);
66
+ }
67
+ /**
68
+ * Get the media file by using its name. This function returns a base64 file
69
+ * @param mediaName
70
+ * @returns
71
+ */
72
+ getMedia(mediaName) {
73
+ if (this._base64Medias[mediaName] !== undefined) {
74
+ return this._base64Medias[mediaName];
75
+ }
76
+ else {
77
+ return undefined;
78
+ }
79
+ }
80
+ /**
81
+ * Get the data of the play
82
+ */
83
+ get data() {
84
+ return this._playData;
85
+ }
86
+ /**
87
+ * Get the id of the play
88
+ */
89
+ get id() {
90
+ return this._playId;
91
+ }
92
+ /**
93
+ * Get the name of the play
94
+ */
95
+ get name() {
96
+ return this._playName;
97
+ }
98
+ /**
99
+ * Get the image base64
100
+ */
101
+ get image() {
102
+ return this._playImagebase64;
103
+ }
104
+ get isRefreshed() {
105
+ return this._refreshed;
106
+ }
107
+ }
@@ -0,0 +1,12 @@
1
+ import { Console } from "./console.js";
2
+ export declare class Stage {
3
+ private _currentStage;
4
+ private _stages;
5
+ private _console;
6
+ constructor(console: Console);
7
+ updateFromServer(): void;
8
+ initStages(stages: string[]): void;
9
+ goto(stage: string): void;
10
+ private _initEvents;
11
+ private _onReceiveStage;
12
+ }
@@ -0,0 +1,38 @@
1
+ import { Console } from "./console.js";
2
+ import { Message } from "./message.js";
3
+ import { goto } from "$app/navigation";
4
+ import { routeType } from "../stores/routeStore.js";
5
+ import { get } from "svelte/store";
6
+ export class Stage {
7
+ _currentStage = "home";
8
+ _stages = ["home"];
9
+ _console;
10
+ constructor(console) {
11
+ this._console = console;
12
+ this._initEvents();
13
+ }
14
+ updateFromServer() {
15
+ }
16
+ initStages(stages) {
17
+ let req = new Message();
18
+ req.setRequest("initStages");
19
+ req.addParam("stages", stages);
20
+ this._console.sendMessage(req);
21
+ }
22
+ goto(stage) {
23
+ let req = new Message();
24
+ req.setRequest("changeStage");
25
+ req.addParam("stage", stage);
26
+ this._console.sendMessage(req);
27
+ }
28
+ _initEvents() {
29
+ // update the state when receive a change from console
30
+ this._console.onStageChange((from, stage) => {
31
+ this._onReceiveStage(from, stage);
32
+ });
33
+ }
34
+ _onReceiveStage(from, receivedStage) {
35
+ let path = "/game/" + get(routeType) + "/" + receivedStage;
36
+ goto(path);
37
+ }
38
+ }
@@ -0,0 +1,36 @@
1
+ import { Console } from "./console.js";
2
+ import { type Writable } from "svelte/store";
3
+ export type AnyState = {
4
+ [key: string]: string;
5
+ };
6
+ export declare class State {
7
+ private _globalState;
8
+ private _console;
9
+ private _access;
10
+ constructor(console: Console, defaultState?: AnyState);
11
+ get state(): Writable<AnyState>;
12
+ /**
13
+ * Update the state from the server
14
+ */
15
+ updateFromServer(): void;
16
+ /**
17
+ * Force change the state with a new one
18
+ * @param newState
19
+ */
20
+ setState(newState: AnyState): void;
21
+ /**
22
+ * Marge a new update to the last one
23
+ * @param stateUpdate
24
+ */
25
+ updateState(stateUpdate: AnyState): void;
26
+ /**
27
+ * Init all events
28
+ * @param from
29
+ * @param any
30
+ */
31
+ private _initEvents;
32
+ /**
33
+ * callback when a new state
34
+ */
35
+ private _onReceiveState;
36
+ }
@@ -0,0 +1,82 @@
1
+ import { Console } from "./console.js";
2
+ import { Message } from "./message.js";
3
+ import { get, writable } from "svelte/store";
4
+ export class State {
5
+ _globalState;
6
+ _console;
7
+ _access = true;
8
+ constructor(console, defaultState = {}) {
9
+ this._access = false;
10
+ this._globalState = writable(defaultState);
11
+ this._console = console;
12
+ this._initEvents();
13
+ this._access = true;
14
+ }
15
+ get state() {
16
+ return this._globalState;
17
+ }
18
+ /**
19
+ * Update the state from the server
20
+ */
21
+ updateFromServer() {
22
+ let req = new Message();
23
+ req.setRequest("getState");
24
+ this._console.sendMessage(req, (response) => {
25
+ let state = response.getParam('state', {});
26
+ this._onReceiveState(response.header.from, state);
27
+ });
28
+ }
29
+ /**
30
+ * Force change the state with a new one
31
+ * @param newState
32
+ */
33
+ setState(newState) {
34
+ this._globalState.set(newState);
35
+ }
36
+ /**
37
+ * Marge a new update to the last one
38
+ * @param stateUpdate
39
+ */
40
+ updateState(stateUpdate) {
41
+ let tempState = get(this._globalState);
42
+ for (let key in stateUpdate) {
43
+ tempState[key] = stateUpdate[key];
44
+ }
45
+ this.setState(tempState);
46
+ }
47
+ /**
48
+ * Init all events
49
+ * @param from
50
+ * @param any
51
+ */
52
+ _initEvents() {
53
+ // Get the state when the console is ready
54
+ this._console.onReady(() => {
55
+ this.updateFromServer();
56
+ });
57
+ // update the state when receive a change from console
58
+ this._console.onStateChange((from, state) => {
59
+ this._onReceiveState(from, state);
60
+ });
61
+ // Send a change state request when detect a state change
62
+ this._globalState.subscribe((newState) => {
63
+ if (this._access) {
64
+ this._console.onReady(() => {
65
+ console.log("change state new state", newState);
66
+ let req = new Message();
67
+ req.setRequest("changeState");
68
+ req.addParam("state", newState);
69
+ this._console.sendMessage(req);
70
+ });
71
+ }
72
+ });
73
+ }
74
+ /**
75
+ * callback when a new state
76
+ */
77
+ _onReceiveState(from, receivedState) {
78
+ this._access = false;
79
+ this._globalState.set(receivedState);
80
+ this._access = true;
81
+ }
82
+ }
@@ -0,0 +1 @@
1
+ export declare function valueToEnum<T extends Record<string, any>>(enumObj: T, value: string | number): T[keyof T] | undefined;
@@ -0,0 +1,5 @@
1
+ export function valueToEnum(enumObj, value) {
2
+ const entries = Object.entries(enumObj);
3
+ const found = entries.find(([_, enumValue]) => enumValue === value);
4
+ return found ? enumObj[found[0]] : undefined;
5
+ }
@@ -0,0 +1,2 @@
1
+ import { KoppeliaServerApi } from "./koppeliaServerApi.js";
2
+ export { KoppeliaServerApi };
@@ -0,0 +1,2 @@
1
+ import { KoppeliaServerApi } from "./koppeliaServerApi.js";
2
+ export { KoppeliaServerApi }; // Server side libraries
@@ -0,0 +1,7 @@
1
+ export declare class KoppeliaServerApi {
2
+ path: string;
3
+ constructor(path: string);
4
+ run(): void;
5
+ getContentType(file: string): string;
6
+ serveApi(): void;
7
+ }