@hadoku/rooms-protocol 0.45.81 → 0.45.82

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/dist/avatars.d.ts CHANGED
@@ -8,8 +8,9 @@
8
8
  * Portraits live on watchparty's media as `square_<id>.png`; colours, grouping
9
9
  * and art revisions are each app's presentation and stay with the app.
10
10
  *
11
- * ORDER IS THE CONTRACT. Auto-assignment hands out the first free id, so the
12
- * order decides who is given what; append a new character, never insert one.
11
+ * Append a new character, never insert one: apps draw the cast in this order
12
+ * (watchparty's picker, its colour table) and their tables are checked
13
+ * against it.
13
14
  */
14
15
  export declare const AVATAR_POOL: readonly ["sage", "herald", "cleric", "knight", "mage", "brawler", "wanderer", "rogue", "gunner", "chief", "walker", "operative", "idol", "recluse", "phantom", "harlequin", "doll", "imp", "apprentice", "prodigy", "dreamer", "sunny", "mentor"];
15
16
  export type AvatarId = (typeof AVATAR_POOL)[number];
@@ -17,7 +18,8 @@ export type AvatarId = (typeof AVATAR_POOL)[number];
17
18
  export declare function isAvatarId(id: string | null | undefined): id is AvatarId;
18
19
  /**
19
20
  * The character a member gets: `preferred` when it is in the pool and nobody
20
- * wears it, otherwise the first pool id nobody wears, otherwise undefined (the
21
+ * wears it, otherwise a pool id nobody wears chosen at random (so a newcomer
22
+ * is not always handed the same first character), otherwise undefined (the
21
23
  * pool is exhausted, and the member goes without).
22
24
  *
23
25
  * Pure and storage-agnostic on purpose: `worn` is whatever the caller's room
@@ -27,7 +29,7 @@ export declare function isAvatarId(id: string | null | undefined): id is AvatarI
27
29
  * around this call, not in it.
28
30
  *
29
31
  * `pool` defaults to the fleet's pool; pass another only for a room with its
30
- * own cast.
32
+ * own cast. `rand` (a `Math.random`-shaped source) is there for tests.
31
33
  */
32
- export declare function pickAvatar(worn: Iterable<string | null | undefined>, preferred?: string | null, pool?: readonly string[]): string | undefined;
34
+ export declare function pickAvatar(worn: Iterable<string | null | undefined>, preferred?: string | null, pool?: readonly string[], rand?: () => number): string | undefined;
33
35
  //# sourceMappingURL=avatars.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatars.d.ts","sourceRoot":"","sources":["../src/avatars.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,oPAKd,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpD,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,EAAE,IAAI,QAAQ,CAExE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EACzC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,IAAI,GAAE,SAAS,MAAM,EAAgB,GACpC,MAAM,GAAG,SAAS,CAKpB"}
1
+ {"version":3,"file":"avatars.d.ts","sourceRoot":"","sources":["../src/avatars.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,oPAKd,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpD,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,EAAE,IAAI,QAAQ,CAExE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EACzC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,IAAI,GAAE,SAAS,MAAM,EAAgB,EACrC,IAAI,GAAE,MAAM,MAAoB,GAC/B,MAAM,GAAG,SAAS,CAMpB"}
package/dist/avatars.js CHANGED
@@ -8,8 +8,9 @@
8
8
  * Portraits live on watchparty's media as `square_<id>.png`; colours, grouping
9
9
  * and art revisions are each app's presentation and stay with the app.
10
10
  *
11
- * ORDER IS THE CONTRACT. Auto-assignment hands out the first free id, so the
12
- * order decides who is given what; append a new character, never insert one.
11
+ * Append a new character, never insert one: apps draw the cast in this order
12
+ * (watchparty's picker, its colour table) and their tables are checked
13
+ * against it.
13
14
  */
14
15
  export const AVATAR_POOL = [
15
16
  'sage', 'herald', 'cleric', 'knight', 'mage', 'brawler', 'wanderer', 'rogue',
@@ -23,7 +24,8 @@ export function isAvatarId(id) {
23
24
  }
24
25
  /**
25
26
  * The character a member gets: `preferred` when it is in the pool and nobody
26
- * wears it, otherwise the first pool id nobody wears, otherwise undefined (the
27
+ * wears it, otherwise a pool id nobody wears chosen at random (so a newcomer
28
+ * is not always handed the same first character), otherwise undefined (the
27
29
  * pool is exhausted, and the member goes without).
28
30
  *
29
31
  * Pure and storage-agnostic on purpose: `worn` is whatever the caller's room
@@ -33,14 +35,15 @@ export function isAvatarId(id) {
33
35
  * around this call, not in it.
34
36
  *
35
37
  * `pool` defaults to the fleet's pool; pass another only for a room with its
36
- * own cast.
38
+ * own cast. `rand` (a `Math.random`-shaped source) is there for tests.
37
39
  */
38
- export function pickAvatar(worn, preferred, pool = AVATAR_POOL) {
40
+ export function pickAvatar(worn, preferred, pool = AVATAR_POOL, rand = Math.random) {
39
41
  const taken = new Set();
40
42
  for (const id of worn)
41
43
  if (id)
42
44
  taken.add(id);
43
45
  if (preferred && pool.includes(preferred) && !taken.has(preferred))
44
46
  return preferred;
45
- return pool.find((id) => !taken.has(id));
47
+ const free = pool.filter((id) => !taken.has(id));
48
+ return free.length ? free[Math.floor(rand() * free.length)] : undefined;
46
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/rooms-protocol",
3
- "version": "0.45.81",
4
- "gitHead": "85d1bea7dbe3ab737020c997890af7e08ad9a851",
3
+ "version": "0.45.82",
4
+ "gitHead": "ad62fed8a76ba0b92936749a02df45d4a281b881",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "Room, identity and seating protocol — the wire contract shared by rooms-server and rooms-client.",