@unitn-asa/deliveroo-js-sdk 1.2.6 → 1.3.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitn-asa/deliveroo-js-sdk",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "description": "Software development kit for Deliveroo.js",
5
5
  "author": "Marco Robol <marco.robol@unitn.it>",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "aafc2442cb50b860033f5196e4a30b410b9959fd",
34
+ "gitHead": "704da8315162c2b98b00d6f4736f5e7631c5b4c5",
35
35
  "dependencies": {
36
36
  "getopts": "^2.3.0"
37
37
  }
@@ -80,7 +80,7 @@ export class DjsClientSocket extends Socket {
80
80
  }
81
81
 
82
82
  /**
83
- * @param { function( IOTile, IOInfo ) : void } callback
83
+ * @param { function( IOTile ) : void } callback
84
84
  */
85
85
  onTile ( callback ) {
86
86
  this.on( "tile", callback )
@@ -95,41 +95,33 @@ export class DjsClientSocket extends Socket {
95
95
  }
96
96
 
97
97
  /**
98
- * @param { function( IOAgent, IOInfo ) : void } callback
98
+ * @param { function( IOAgent ) : void } callback
99
99
  */
100
100
  onYou ( callback ) {
101
101
  this.on( "you", callback )
102
102
  }
103
103
 
104
104
  /**
105
- * @param { function( IOAgent, IOInfo ) : void } callback
105
+ * @param { function( IOAgent ) : void } callback
106
106
  */
107
107
  onceYou ( callback ) {
108
108
  this.once( "you", callback )
109
109
  }
110
110
 
111
111
  /**
112
- * Listen to 'agents sensing' events
113
- * @param { function( IOSensing [] ) : void } callback
112
+ * Listen to 'sensing' events
113
+ * @param { function( IOSensing ) : void } callback
114
114
  */
115
- onAgentsSensing ( callback ) {
116
- this.on( "agents sensing", callback )
115
+ onSensing ( callback ) {
116
+ this.on( "sensing", callback )
117
117
  }
118
118
 
119
119
  /**
120
- * Listen to 'parcels sensing' events
121
- * @param { function( IOSensing [] ) : void } callback
120
+ * Listen to 'info' events
121
+ * @param { function( IOInfo ) : void } callback
122
122
  */
123
- onParcelsSensing ( callback ) {
124
- this.on( "parcels sensing", callback )
125
- }
126
-
127
- /**
128
- * Listen to 'crates sensing' events
129
- * @param { function( IOSensing [] ) : void } callback
130
- */
131
- onCratesSensing ( callback ) {
132
- this.on( "crates sensing", callback )
123
+ onInfo ( callback ) {
124
+ this.on( "info", callback )
133
125
  }
134
126
 
135
127
  /**
@@ -206,11 +198,11 @@ export class DjsClientSocket extends Socket {
206
198
  /**
207
199
  * When movement completes, it resolves to true.
208
200
  * In case of failure when moving, it resolves to false
209
- * @param { 'up' | 'right' | 'left' | 'down' | { x:number, y:number } } directionOrXy It can be either: 'up', 'right', 'left', 'down', or destination Xy
201
+ * @param { 'up' | 'right' | 'left' | 'down' } direction It can be either: 'up', 'right', 'left', 'down'
210
202
  * @returns { Promise < { x:number, y:number } | false > }
211
203
  */
212
- async emitMove ( directionOrXy ) {
213
- return this.emitAndResolveOnAck( 'move', directionOrXy );
204
+ async emitMove ( direction ) {
205
+ return this.emitAndResolveOnAck( 'move', direction );
214
206
  }
215
207
 
216
208
  /**
@@ -205,7 +205,7 @@ export class DjsRestClient {
205
205
  }
206
206
  throw new Error(`Error generating token, Status code: ${response.status}`);
207
207
  })
208
- .then(data => {
208
+ .then( (/** @type {{token:string}} */ data) => {
209
209
  console.log("token ottenuto: " + data.token.slice(-30));
210
210
  resolve(data);
211
211
  })
@@ -40,10 +40,9 @@ export class DjsServer extends Server {
40
40
  /**
41
41
  * Broadcast a tile update to all connected clients
42
42
  * @param { IOTile } tile
43
- * @param { IOInfo } info
44
43
  */
45
- broadcastTile({ x, y, type }, info) {
46
- this.emit('tile', { x, y, type }, info);
44
+ broadcastTile({ x, y, type }) {
45
+ this.emit('tile', { x, y, type });
47
46
  }
48
47
 
49
48
  /**
@@ -46,7 +46,7 @@ export class DjsServerSocket extends Socket {
46
46
  * @param { function() : void } callback
47
47
  */
48
48
  onDisconnect ( callback ) {
49
- this.on( 'disconnect', callback);
49
+ super.on( 'disconnect', callback);
50
50
  }
51
51
 
52
52
  /**
@@ -67,10 +67,9 @@ export class DjsServerSocket extends Socket {
67
67
 
68
68
  /**
69
69
  * @param { IOTile } tile
70
- * @param { IOInfo } info
71
70
  */
72
- emitTile ( { x, y, type }, info ) {
73
- super.emit( 'tile', {x, y, type}, info );
71
+ emitTile ( { x, y, type } ) {
72
+ super.emit( 'tile', {x, y, type} );
74
73
  }
75
74
 
76
75
  /**
@@ -83,48 +82,37 @@ export class DjsServerSocket extends Socket {
83
82
 
84
83
  /**
85
84
  * @param { IOAgent } you
86
- * @param { IOInfo } info
87
85
  */
88
- emitYou ( {id, name, teamId, teamName, x, y, score, penalty}, info ) {
89
- super.emit( 'you', {id, name, teamId, teamName, x, y, score, penalty}, info );
86
+ emitYou ( {id, name, teamId, teamName, x, y, score, penalty} ) {
87
+ super.emit( 'you', {id, name, teamId, teamName, x, y, score, penalty} );
90
88
  }
91
89
 
92
90
  /**
93
- * @param { IOSensing [] } agents
94
- * @param { IOInfo } info
91
+ * @param { IOSensing } sensing
95
92
  */
96
- emitAgentsSensing ( agents, info ) {
97
- super.emit( 'agents sensing', agents, info );
93
+ emitSensing ( sensing ) {
94
+ super.emit( 'sensing', sensing );
98
95
  }
99
96
 
100
97
  /**
101
- * @param { IOSensing [] } parcels
102
- * @param { IOInfo } info
103
- */
104
- emitParcelSensing ( parcels, info ) {
105
- super.emit( 'parcels sensing', parcels, info );
106
- }
107
-
108
- /**
109
- * @param { IOSensing [] } crates
110
98
  * @param { IOInfo } info
111
99
  */
112
- emitCrateSensing ( crates, info ) {
113
- super.emit( 'crates sensing', crates, info );
100
+ emitInfo ( info ) {
101
+ super.emit( 'info', info );
114
102
  }
115
103
 
116
104
 
117
105
 
118
106
  /**
119
107
  * @callback onMoveCallback
120
- * @param { 'up' | 'right' | 'left' | 'down' | { x:number, y:number } } directionOrXy
108
+ * @param { 'up' | 'right' | 'left' | 'down' } direction
121
109
  * @param { function( { x:number, y:number } | false ) : void } replyAcknowledgmentCallback ( reply )
122
110
  */
123
111
  /**
124
112
  * @param { onMoveCallback } callback ( direction, acknowledgementCallback )
125
113
  */
126
114
  onMove ( callback ) {
127
- this.on( 'move', callback );
115
+ super.on( 'move', callback );
128
116
  }
129
117
 
130
118
  /**
@@ -135,7 +123,7 @@ export class DjsServerSocket extends Socket {
135
123
  * @param { onPickupCallback } callback ( acknowledgementCallback )
136
124
  */
137
125
  onPickup ( callback ) {
138
- this.on( 'pickup', callback );
126
+ super.on( 'pickup', callback );
139
127
  }
140
128
 
141
129
  /**
@@ -147,7 +135,7 @@ export class DjsServerSocket extends Socket {
147
135
  * @param { onPutdownCallback } callback ( selected, acknowledgementCallback )
148
136
  */
149
137
  onPutdown ( callback ) {
150
- this.on( 'putdown', callback );
138
+ super.on( 'putdown', callback );
151
139
  }
152
140
 
153
141
 
@@ -156,21 +144,21 @@ export class DjsServerSocket extends Socket {
156
144
  * @param { function ( string, any, function ( 'successful' ) : void ) : void } callback ( toId, msg, ack )
157
145
  */
158
146
  onSay ( callback ) {
159
- this.on( 'say', callback );
147
+ super.on( 'say', callback );
160
148
  }
161
149
 
162
150
  /**
163
151
  * @param { function ( string, any, function ( any ) : void ) : void } callback ( toId, msg, ack(reply) )
164
152
  */
165
153
  onAsk ( callback ) {
166
- this.on( 'ask', callback );
154
+ super.on( 'ask', callback );
167
155
  }
168
156
 
169
157
  /**
170
158
  * @param { function ( any, function ( any ) : void ) : void } callback ( msg, ack(reply) )
171
159
  */
172
160
  onShout ( callback ) {
173
- this.on( 'shout', callback );
161
+ super.on( 'shout', callback );
174
162
  }
175
163
 
176
164
  /**
@@ -225,7 +213,7 @@ export class DjsServerSocket extends Socket {
225
213
  * @param { function ( ...any ) : void } callback ( ...msgArgs )
226
214
  */
227
215
  onLog ( callback ) {
228
- this.on( 'log', callback );
216
+ super.on( 'log', callback );
229
217
  }
230
218
 
231
219
  /**
@@ -246,7 +234,7 @@ export class DjsServerSocket extends Socket {
246
234
  * @param { function ( 'create' | 'dispose' | 'set', {id:string, x:number, y:number, reward:number} ) : void } callback
247
235
  */
248
236
  onParcel ( callback ) {
249
- this.on( 'parcel', callback );
237
+ super.on( 'parcel', callback );
250
238
  }
251
239
 
252
240
  /**
@@ -254,7 +242,7 @@ export class DjsServerSocket extends Socket {
254
242
  * @param { function ( IOTile ) : void } callback
255
243
  */
256
244
  onTile ( callback ) {
257
- this.on( 'tile', callback );
245
+ super.on( 'tile', callback );
258
246
  }
259
247
 
260
248
  /**
@@ -262,7 +250,7 @@ export class DjsServerSocket extends Socket {
262
250
  * @param { function () : void } callback
263
251
  */
264
252
  onRestart ( callback ) {
265
- this.on( 'restart', callback );
253
+ super.on( 'restart', callback );
266
254
  }
267
255
 
268
256
 
@@ -5,8 +5,8 @@
5
5
  * @property {string} name
6
6
  * @property {string} teamId
7
7
  * @property {string} teamName
8
- * @property {number} x
9
- * @property {number} y
8
+ * @property {number=} x
9
+ * @property {number=} y
10
10
  * @property {number} score
11
11
  * @property {number} penalty
12
12
  */
@@ -1,7 +1,6 @@
1
1
 
2
2
  /**
3
3
  * @typedef { 'frame' | '1s' | '2s' | '5s' | '10s' | 'infinite' } IOClockEvent
4
- * @export
5
4
  */
6
5
 
7
6
 
@@ -46,8 +46,7 @@
46
46
  * Player configuration object
47
47
  * @property {string} agent_type Agent class
48
48
  * @property {number} movement_duration Duration of each movement in ms
49
- * @property {number} agents_observation_distance Observation distance for agents
50
- * @property {number} parcels_observation_distance Observation distance for parcels
49
+ * @property {number|'infinite'} observation_distance Observation distance
51
50
  * @property {number} capacity Capacity
52
51
  */
53
52
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @typedef IONPC
3
+ * @property {string} id
4
+ * @property {string} name
5
+ * @property {boolean} running
6
+ * @property {boolean} stopRequested
7
+ */
8
+
9
+ export { };
@@ -5,11 +5,10 @@
5
5
 
6
6
  /**
7
7
  * @typedef IOSensing
8
- * @property {number} x
9
- * @property {number} y
10
- * @property {IOAgent=} agent
11
- * @property {IOParcel=} parcel
12
- * @property {IOCrate=} crate
8
+ * @property {{x:number, y:number}[]} positions
9
+ * @property {IOAgent[]} agents
10
+ * @property {IOParcel[]} parcels
11
+ * @property {IOCrate[]} crates
13
12
  */
14
13
 
15
14
  export { };
@@ -8,7 +8,7 @@
8
8
  * Client -> Server events. Emitted by the client and listened by the server.
9
9
  * @typedef {{
10
10
  * 'disconnect': function () : void,
11
- * 'move': function ( 'up' | 'right' | 'left' | 'down' | { x:number, y:number }, function ( { x:number, y:number } | false ) : void = ) : { x:number, y:number } | false,
11
+ * 'move': function ( 'up' | 'right' | 'left' | 'down', function ( { x:number, y:number } | false ) : void = ) : { x:number, y:number } | false,
12
12
  * 'pickup': function ( function ( { id:string } [] ) : void = ) : { id:string } [],
13
13
  * 'putdown': function ( string [] =, function ( { id:string } [] ) : void = ) : { id:string } [],
14
14
  * 'say': function ( string, any, function( 'successful' ) : void ) : void,
@@ -30,14 +30,13 @@
30
30
  * 'token': function ( string ) : void,
31
31
  * 'config': function ( any ) : void,
32
32
  * 'map': function ( number, number, IOTile[] ) : void,
33
- * 'tile': function ( IOTile, IOInfo ) : void,
33
+ * 'tile': function ( IOTile ) : void,
34
34
  * 'controller': function ( 'connected' | 'disconnected', {id:string, name:string, teamId:string, teamName:string, score:number} ) : void,
35
- * 'you': function ( IOAgent, IOInfo ) : void,
36
- * 'agents sensing': function ( IOSensing[], IOInfo ) : void,
37
- * 'parcels sensing': function ( IOSensing[], IOInfo ) : void,
38
- * 'crates sensing': function ( IOSensing[], IOInfo ) : void,
35
+ * 'you': function ( IOAgent ) : void,
36
+ * 'sensing': function ( IOSensing ) : void,
37
+ * 'info': function ( IOInfo ) : void,
39
38
  * 'msg': function ( string, string, Object, function ( Object ) : void = ) : Object,
40
- * 'log': function ( 'server' | { socket:string, id:string, name:string }, IOInfo, ...any ) : void
39
+ * 'log': function ( 'server' | { socket:string, id:string, name:string }, ...any ) : void
41
40
  * }} IOServerEvents
42
41
  */
43
42
 
@@ -1,5 +1,5 @@
1
1
 
2
- /** @typedef {import("./IOClockEvent.js").IOClockEvent} IOClockEvent */
2
+ /** @import { IOClockEvent } from "./IOClockEvent.js" */
3
3
 
4
4
 
5
5