@momo2555/koppeliajs 0.0.128 → 0.0.129

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,4 +1,5 @@
1
1
  import { Console } from './console.js';
2
+ import { Resident } from './resident.js';
2
3
  /**
3
4
  * This class reprensts a device
4
5
  */
@@ -13,6 +14,8 @@ export declare class Device {
13
14
  private _name;
14
15
  private _console;
15
16
  private _attachedEvents;
17
+ private _resident?;
18
+ private isAttachedToResident;
16
19
  constructor(console: Console, address?: string);
17
20
  get color(): Color;
18
21
  get name(): string;
@@ -45,5 +48,7 @@ export declare class Device {
45
48
  fromObject(object: {
46
49
  [key: string]: any;
47
50
  }): void;
51
+ get resident(): Resident | undefined;
52
+ get isAssociatedToResident(): boolean;
48
53
  }
49
54
  export {};
@@ -1,17 +1,21 @@
1
1
  import { Console } from './console.js';
2
2
  import { Message, MessageType, PeerType } from './message.js';
3
+ import { Resident } from './resident.js';
3
4
  export class Device {
4
5
  _address;
5
6
  _color;
6
7
  _name;
7
8
  _console;
8
9
  _attachedEvents;
10
+ _resident;
11
+ isAttachedToResident;
9
12
  constructor(console, address = "") {
10
13
  this._address = address;
11
14
  this._color = { r: 0, g: 0, b: 0 };
12
15
  this._name = "";
13
16
  this._console = console;
14
17
  this._attachedEvents = [];
18
+ this.isAttachedToResident = false;
15
19
  }
16
20
  // public set color(color: Color) {
17
21
  // this._color = color;
@@ -128,5 +132,16 @@ export class Device {
128
132
  if (object.name !== undefined) {
129
133
  this._name = object.name;
130
134
  }
135
+ if (object.resident !== undefined) {
136
+ this.isAttachedToResident = true;
137
+ this._resident = new Resident();
138
+ this._resident.fromObject(object.resident);
139
+ }
140
+ }
141
+ get resident() {
142
+ return this._resident;
143
+ }
144
+ get isAssociatedToResident() {
145
+ return this.isAttachedToResident;
131
146
  }
132
147
  }
@@ -2,6 +2,7 @@ import { type Writable } from "svelte/store";
2
2
  import { type AnyState } from "./state.js";
3
3
  import { Device } from "./device.js";
4
4
  import { Play } from "./play.js";
5
+ import { Resident } from "./resident.js";
5
6
  export declare class Koppelia {
6
7
  private _console;
7
8
  private _state;
@@ -33,6 +34,7 @@ export declare class Koppelia {
33
34
  */
34
35
  goto(stageName: string): void;
35
36
  fixMediaUrl(mediaUrl: string): string;
37
+ getMediaLink(path: string): string;
36
38
  /**
37
39
  * Get the list of devices in a callback
38
40
  * @param callback
@@ -52,6 +54,7 @@ export declare class Koppelia {
52
54
  * @returns the List of plays an array of objects of type Play,
53
55
  */
54
56
  getPlays(count?: number, index?: number, orderBy?: string): Promise<Play[]>;
57
+ getResidents(): Promise<Resident[]>;
55
58
  /**
56
59
  * Get the current play that has been set
57
60
  * @returns the current play
@@ -7,6 +7,7 @@ import { Stage } from "./stage.js";
7
7
  import { Device } from "./device.js";
8
8
  import { Play } from "./play.js";
9
9
  import { PUBLIC_GAME_ID } from '$env/static/public';
10
+ import { Resident } from "./resident.js";
10
11
  export class Koppelia {
11
12
  _console;
12
13
  _state;
@@ -84,6 +85,9 @@ export class Koppelia {
84
85
  fixMediaUrl(mediaUrl) {
85
86
  return this._console.fixMediaUrl(mediaUrl);
86
87
  }
88
+ getMediaLink(path) {
89
+ return this._console.getMediaUrl(path);
90
+ }
87
91
  /**
88
92
  * Get the list of devices in a callback
89
93
  * @param callback
@@ -142,6 +146,23 @@ export class Koppelia {
142
146
  });
143
147
  });
144
148
  }
149
+ async getResidents() {
150
+ return new Promise((resolve, reject) => {
151
+ let getResidentsRequest = new Message();
152
+ getResidentsRequest.setRequest("getResidentsList");
153
+ getResidentsRequest.setDestination(PeerType.MASTER, "");
154
+ this._console.sendMessage(getResidentsRequest, (response) => {
155
+ let ResidentRawList = response.getParam("residents", {});
156
+ let residents = [];
157
+ for (let residentId in ResidentRawList) {
158
+ let resident = new Resident();
159
+ resident.fromObject(ResidentRawList[residentId]);
160
+ residents.push(resident);
161
+ }
162
+ resolve(residents);
163
+ });
164
+ });
165
+ }
145
166
  /**
146
167
  * Get the current play that has been set
147
168
  * @returns the current play
@@ -0,0 +1,12 @@
1
+ export declare class Resident {
2
+ private _name;
3
+ private _id;
4
+ private _image;
5
+ constructor();
6
+ get id(): string;
7
+ get name(): string;
8
+ get imageUrl(): string;
9
+ fromObject(object: {
10
+ [key: string]: string;
11
+ }): void;
12
+ }
@@ -0,0 +1,24 @@
1
+ import { Koppelia } from "./koppelia.js";
2
+ export class Resident {
3
+ _name = "";
4
+ _id = "";
5
+ _image = "";
6
+ constructor() {
7
+ }
8
+ get id() {
9
+ return this._id;
10
+ }
11
+ get name() {
12
+ return this._name;
13
+ }
14
+ get imageUrl() {
15
+ let koppelia = Koppelia.instance;
16
+ let path = "/media/residence/" + this._id + "/" + this._image;
17
+ return koppelia.getMediaLink(path);
18
+ }
19
+ fromObject(object) {
20
+ this._name = object["resident_name"];
21
+ this._id = object["resident_id"];
22
+ this._image = object["resident_image"];
23
+ }
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.128",
3
+ "version": "0.0.129",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",