dewdrop-sdk 0.5.4 → 0.5.6

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": "dewdrop-sdk",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "Build a three.js game for Dewdrop: the Vite plugin, model calls, multiplayer, saves and voice.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -5,8 +5,9 @@
5
5
  // runs, `clients`, in that backend, over its port back, and `saves` into
6
6
  // the browser's own storage, which the plugin's script empties as each
7
7
  // page loads; `session` says when a session ends ahead of time, which here
8
- // none does, and lets a game end its player's session, which here ends
9
- // nothing; and `voice` reads the microphone through the browser's own
8
+ // none does, lets a game end its player's session, which here ends
9
+ // nothing, and lets a game allow portrait views, which here the browser's
10
+ // window already gives; and `voice` reads the microphone through the browser's own
10
11
  // audio worklet, into the chunks a game gets on Dewdrop.
11
12
  export { llm } from './llm.js';
12
13
  export { backend } from './backend.js';
package/src/session.js CHANGED
@@ -12,20 +12,38 @@
12
12
  // `session.exit()`, which on Dewdrop takes the player back to Dewdrop's
13
13
  // home page while the room's other players play on, the game hearing
14
14
  // `'exit'` as it goes; a backend has no player to send anywhere, so there it
15
- // throws NotSupportedError. `npm run dev` ends no session, so here `ending`
16
- // stays null and the event never fires, a game trying its handler by
17
- // calling it, and `exit()` ends nothing: the console says so, once.
15
+ // throws NotSupportedError. A game that lays itself out for either shape
16
+ // calls `session.allowPortrait()`, after which Dewdrop turns its view
17
+ // portrait whenever its player's page asks — a phone held upright — and the
18
+ // game hears each turn as a `resize`, its window taking the view's new
19
+ // shape; until then a session stays landscape, and a backend, which has no
20
+ // view, throws NotSupportedError. `npm run dev` ends no session, so here
21
+ // `ending` stays null and the event never fires, a game trying its handler
22
+ // by calling it, and `exit()` ends nothing: the console says so, once. The
23
+ // game here is the browser's own window, which already takes any shape and
24
+ // fires its own `resize`, so `allowPortrait()` changes nothing and says
25
+ // what it does on Dewdrop, once. `session.dev` is true in the game's dev
26
+ // version and false once it is published, in a backend too; `npm run dev`
27
+ // is development, so here it is true.
18
28
  import { defineHandlers, side } from './net.js';
19
29
 
20
30
  let told = false;
31
+ let toldPortrait = false;
21
32
  class Session extends EventTarget {
22
33
  get ending() { return null; }
34
+ get dev() { return true; }
23
35
  exit() {
24
36
  if (side.backend) throw new DOMException('session.exit is unavailable in a backend', 'NotSupportedError');
25
37
  if (told) return;
26
38
  told = true;
27
39
  console.info('[dewdrop] session.exit(): on Dewdrop this ends the session and takes the player back to Dewdrop’s home page; npm run dev keeps the game running');
28
40
  }
41
+ allowPortrait() {
42
+ if (side.backend) throw new DOMException('session.allowPortrait is unavailable in a backend', 'NotSupportedError');
43
+ if (toldPortrait) return;
44
+ toldPortrait = true;
45
+ console.info('[dewdrop] session.allowPortrait(): on Dewdrop the view turns portrait whenever the player’s page is taller than wide, each turn a resize; npm run dev’s window already takes any shape');
46
+ }
29
47
  }
30
48
  defineHandlers(Session.prototype, ['ending']);
31
49