@hadoku/rooms-protocol 0.45.54 → 0.45.55
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 +33 -0
- package/dist/avatars.d.ts.map +1 -0
- package/dist/avatars.js +46 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -7
- package/package.json +2 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fleet's character pool, and the one rule for handing a character out.
|
|
3
|
+
*
|
|
4
|
+
* Every hadoku room app draws the same cast (watchparty's chat, cardtable's
|
|
5
|
+
* board, bomberman's arena), so the list of ids is room protocol, not any one
|
|
6
|
+
* app's content. Ids are generic archetypes, never a character's name: the art
|
|
7
|
+
* is fan art of third-party characters, and the names stay out of every repo.
|
|
8
|
+
* Portraits live on watchparty's media as `square_<id>.png`; colours, grouping
|
|
9
|
+
* and art revisions are each app's presentation and stay with the app.
|
|
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.
|
|
13
|
+
*/
|
|
14
|
+
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
|
+
export type AvatarId = (typeof AVATAR_POOL)[number];
|
|
16
|
+
/** Narrow an arbitrary string (it arrives off the wire) to a pool id. */
|
|
17
|
+
export declare function isAvatarId(id: string | null | undefined): id is AvatarId;
|
|
18
|
+
/**
|
|
19
|
+
* 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
|
+
* pool is exhausted, and the member goes without).
|
|
22
|
+
*
|
|
23
|
+
* Pure and storage-agnostic on purpose: `worn` is whatever the caller's room
|
|
24
|
+
* keeps — a socket room's claim set, or a list of member records' `avatarId`s
|
|
25
|
+
* (absent entries are ignored). What to do when `preferred` is worn (refuse,
|
|
26
|
+
* move its holder, let two people share it) is the app's policy, decided
|
|
27
|
+
* around this call, not in it.
|
|
28
|
+
*
|
|
29
|
+
* `pool` defaults to the fleet's pool; pass another only for a room with its
|
|
30
|
+
* own cast.
|
|
31
|
+
*/
|
|
32
|
+
export declare function pickAvatar(worn: Iterable<string | null | undefined>, preferred?: string | null, pool?: readonly string[]): string | undefined;
|
|
33
|
+
//# sourceMappingURL=avatars.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/avatars.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fleet's character pool, and the one rule for handing a character out.
|
|
3
|
+
*
|
|
4
|
+
* Every hadoku room app draws the same cast (watchparty's chat, cardtable's
|
|
5
|
+
* board, bomberman's arena), so the list of ids is room protocol, not any one
|
|
6
|
+
* app's content. Ids are generic archetypes, never a character's name: the art
|
|
7
|
+
* is fan art of third-party characters, and the names stay out of every repo.
|
|
8
|
+
* Portraits live on watchparty's media as `square_<id>.png`; colours, grouping
|
|
9
|
+
* and art revisions are each app's presentation and stay with the app.
|
|
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.
|
|
13
|
+
*/
|
|
14
|
+
export const AVATAR_POOL = [
|
|
15
|
+
'sage', 'herald', 'cleric', 'knight', 'mage', 'brawler', 'wanderer', 'rogue',
|
|
16
|
+
'gunner', 'chief', 'walker', 'operative',
|
|
17
|
+
'idol', 'recluse', 'phantom', 'harlequin', 'doll', 'imp',
|
|
18
|
+
'apprentice', 'prodigy', 'dreamer', 'sunny', 'mentor',
|
|
19
|
+
];
|
|
20
|
+
/** Narrow an arbitrary string (it arrives off the wire) to a pool id. */
|
|
21
|
+
export function isAvatarId(id) {
|
|
22
|
+
return !!id && AVATAR_POOL.includes(id);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 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
|
+
* pool is exhausted, and the member goes without).
|
|
28
|
+
*
|
|
29
|
+
* Pure and storage-agnostic on purpose: `worn` is whatever the caller's room
|
|
30
|
+
* keeps — a socket room's claim set, or a list of member records' `avatarId`s
|
|
31
|
+
* (absent entries are ignored). What to do when `preferred` is worn (refuse,
|
|
32
|
+
* move its holder, let two people share it) is the app's policy, decided
|
|
33
|
+
* around this call, not in it.
|
|
34
|
+
*
|
|
35
|
+
* `pool` defaults to the fleet's pool; pass another only for a room with its
|
|
36
|
+
* own cast.
|
|
37
|
+
*/
|
|
38
|
+
export function pickAvatar(worn, preferred, pool = AVATAR_POOL) {
|
|
39
|
+
const taken = new Set();
|
|
40
|
+
for (const id of worn)
|
|
41
|
+
if (id)
|
|
42
|
+
taken.add(id);
|
|
43
|
+
if (preferred && pool.includes(preferred) && !taken.has(preferred))
|
|
44
|
+
return preferred;
|
|
45
|
+
return pool.find((id) => !taken.has(id));
|
|
46
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
* @wolffm/rooms-protocol — the wire contract for rooms.
|
|
3
3
|
*
|
|
4
4
|
* Deliberately dependency-free (not even zod yet) and free of any hosting
|
|
5
|
-
* app's vocabulary: no playhead, media, fragment, playlist
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Extracted from watchparty's `@watchparty/shared`, which keeps re-exporting
|
|
10
|
-
* these so the ~40 existing import sites did not all have to move in the same
|
|
11
|
-
* commit as the package boundary.
|
|
5
|
+
* app's vocabulary: no playhead, media, fragment, playlist or tierlist. The
|
|
6
|
+
* character pool (`avatars.ts`) is here because every room app draws the same
|
|
7
|
+
* cast. Both `rooms-server` and a client bind to this, so anything that lands
|
|
8
|
+
* here becomes a promise to every consumer.
|
|
12
9
|
*/
|
|
13
10
|
export * from './participantId.js';
|
|
14
11
|
export * from './seats.js';
|
|
15
12
|
export * from './resync.js';
|
|
16
13
|
export * from './game-bundle.js';
|
|
14
|
+
export * from './avatars.js';
|
|
17
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* @wolffm/rooms-protocol — the wire contract for rooms.
|
|
3
3
|
*
|
|
4
4
|
* Deliberately dependency-free (not even zod yet) and free of any hosting
|
|
5
|
-
* app's vocabulary: no playhead, media, fragment, playlist
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Extracted from watchparty's `@watchparty/shared`, which keeps re-exporting
|
|
10
|
-
* these so the ~40 existing import sites did not all have to move in the same
|
|
11
|
-
* commit as the package boundary.
|
|
5
|
+
* app's vocabulary: no playhead, media, fragment, playlist or tierlist. The
|
|
6
|
+
* character pool (`avatars.ts`) is here because every room app draws the same
|
|
7
|
+
* cast. Both `rooms-server` and a client bind to this, so anything that lands
|
|
8
|
+
* here becomes a promise to every consumer.
|
|
12
9
|
*/
|
|
13
10
|
export * from './participantId.js';
|
|
14
11
|
export * from './seats.js';
|
|
15
12
|
export * from './resync.js';
|
|
16
13
|
export * from './game-bundle.js';
|
|
14
|
+
export * from './avatars.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/rooms-protocol",
|
|
3
|
-
"version": "0.45.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.45.55",
|
|
4
|
+
"gitHead": "4030a40dc8710a9ec7c1cb9d42d3afb185f329f9",
|
|
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.",
|