minimojs 1.0.0-alpha.36 → 1.0.0-alpha.37

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.
@@ -100,6 +100,19 @@ export interface RoomUpdate {
100
100
  /** Passes the turn: `"next"`, the next player by seat, or a player's id. */
101
101
  turn?: "next" | string;
102
102
  }
103
+ /**
104
+ * The room a player is expected in when the game starts, from
105
+ * {@link Multiplayer.pendingRoom}.
106
+ */
107
+ export interface PendingRoom {
108
+ /** The room's code, such as `KQ7XA`. */
109
+ code: string;
110
+ /**
111
+ * `true` when the player opened the room's link, an invitation; `false`
112
+ * when they were already in the room on this device, as after a reload.
113
+ */
114
+ invited: boolean;
115
+ }
103
116
  /** Options for {@link Room.showResults}. */
104
117
  export interface RoomResultsOptions {
105
118
  /** A title instead of `"Results"`. */
@@ -295,6 +308,16 @@ export declare class Room {
295
308
  * await room.end({ [winnerId]: 1 });
296
309
  * const choice = await room.showResults(); // "rematch" or "leave"
297
310
  * ```
311
+ *
312
+ * A game with its own welcome screen asks {@link Multiplayer.pendingRoom}
313
+ * first, so a player who opened a room's link, or reloaded the page in a
314
+ * room, goes straight to it instead of to the welcome screen:
315
+ *
316
+ * ```js
317
+ * const pending = await mp.pendingRoom();
318
+ * if (pending) room = await mp.lobby(); // that room's lobby, or its game in progress
319
+ * else showWelcome(); // Play online, then mp.lobby() to create or join
320
+ * ```
298
321
  */
299
322
  export declare class Multiplayer {
300
323
  /**
@@ -313,6 +336,19 @@ export declare class Multiplayer {
313
336
  create(): Promise<Room>;
314
337
  /** Joins a room by its code, without the lobby, or returns to one the player is in. */
315
338
  join(code: string): Promise<Room>;
339
+ /**
340
+ * The room this player is expected in, before any screen is shown: the room
341
+ * whose link they opened, an invitation, or the room they were in on this
342
+ * device before the page reloaded. `null` on a normal visit, outside
343
+ * Minimo Games, and when the game's creator is not on Pro.
344
+ *
345
+ * It opens nothing, joins nothing, and can be asked again: the room stays
346
+ * pending until the player is in it. {@link Multiplayer.lobby} then takes
347
+ * them straight into it. A room that has closed since, as an old link's,
348
+ * is still returned, and the lobby then says there is no room with that
349
+ * code.
350
+ */
351
+ pendingRoom(): Promise<PendingRoom | null>;
316
352
  /**
317
353
  * The player's name on Minimo Games, the one leaderboards show, or `null`
318
354
  * before they choose one.
@@ -772,6 +772,16 @@ export class Room {
772
772
  * await room.end({ [winnerId]: 1 });
773
773
  * const choice = await room.showResults(); // "rematch" or "leave"
774
774
  * ```
775
+ *
776
+ * A game with its own welcome screen asks {@link Multiplayer.pendingRoom}
777
+ * first, so a player who opened a room's link, or reloaded the page in a
778
+ * room, goes straight to it instead of to the welcome screen:
779
+ *
780
+ * ```js
781
+ * const pending = await mp.pendingRoom();
782
+ * if (pending) room = await mp.lobby(); // that room's lobby, or its game in progress
783
+ * else showWelcome(); // Play online, then mp.lobby() to create or join
784
+ * ```
775
785
  */
776
786
  export class Multiplayer {
777
787
  /**
@@ -897,6 +907,29 @@ export class Multiplayer {
897
907
  const result = await request("join", { code: String(code).trim().toUpperCase() });
898
908
  return this._adopt(result.room);
899
909
  }
910
+ /**
911
+ * The room this player is expected in, before any screen is shown: the room
912
+ * whose link they opened, an invitation, or the room they were in on this
913
+ * device before the page reloaded. `null` on a normal visit, outside
914
+ * Minimo Games, and when the game's creator is not on Pro.
915
+ *
916
+ * It opens nothing, joins nothing, and can be asked again: the room stays
917
+ * pending until the player is in it. {@link Multiplayer.lobby} then takes
918
+ * them straight into it. A room that has closed since, as an old link's,
919
+ * is still returned, and the lobby then says there is no room with that
920
+ * code.
921
+ */
922
+ async pendingRoom() {
923
+ if (this._room && !this._room.closed)
924
+ return { code: this._room.code, invited: false };
925
+ if (!(await connectHost()))
926
+ return null;
927
+ const info = await request("hello", {}, HOST_TIMEOUT_MS * 2).catch(() => null);
928
+ if (!info || !info.available || typeof info.roomCode !== "string")
929
+ return null;
930
+ const code = info.roomCode.trim().toUpperCase();
931
+ return /^[A-Z0-9]{5}$/.test(code) ? { code, invited: Boolean(info.fromLink) } : null;
932
+ }
900
933
  /**
901
934
  * The player's name on Minimo Games, the one leaderboards show, or `null`
902
935
  * before they choose one.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimojs",
3
- "version": "1.0.0-alpha.36",
3
+ "version": "1.0.0-alpha.37",
4
4
  "description": "MinimoJS v1 — ultra-minimal, flat, deterministic 2D web game engine. Image-first sprites with emoji as a zero-asset alternative, rAF loop, TypeScript-first, LLM-friendly.",
5
5
  "type": "module",
6
6
  "main": "dist/minimo.js",