@textadventures/quest-viva-wasmplayer 6.0.0-beta.57 → 6.0.0-beta.59

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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,7 +1,7 @@
1
1
  export const config = /*json-start*/{
2
2
  "mainAssemblyName": "WasmPlayer.dll",
3
3
  "resources": {
4
- "hash": "sha256-1IjPEvvC42SmC0Z1qe7SujMgBpAMlPzodJ2lu8rF7iU=",
4
+ "hash": "sha256-JR2RaJFHW87NQvu3H/puPdda+cgxLVtr3snkTNVAGNQ=",
5
5
  "jsModuleNative": [
6
6
  {
7
7
  "name": "dotnet.native.js"
@@ -939,27 +939,27 @@ export const config = /*json-start*/{
939
939
  {
940
940
  "virtualPath": "Common.wasm",
941
941
  "name": "Common.wasm",
942
- "hash": "sha256-txuoGYNFIT7kV6fBAQuEJ/aOF1kzL3ACcV6KE7QS2iY="
942
+ "hash": "sha256-2weqQwAVEV2TCiE2wkZtlMeUpRRECS0qh5gomoENIjk="
943
943
  },
944
944
  {
945
945
  "virtualPath": "Engine.wasm",
946
946
  "name": "Engine.wasm",
947
- "hash": "sha256-DDSHRNfIoFiEHgInjs4k9hMhzjh+YhUQ76xwKJk6N4A="
947
+ "hash": "sha256-kP8DveYxBZmLh0UH4A1n/+mCO4Nc7asdXM8hu5DBTus="
948
948
  },
949
949
  {
950
950
  "virtualPath": "Legacy.wasm",
951
951
  "name": "Legacy.wasm",
952
- "hash": "sha256-RlhHBBWIkw8bHWwgrBJZ/3pZWlXJsML4auIVWjvme1k="
952
+ "hash": "sha256-8olPp51wGZYjz5bYSNzX7XajdoYMJwicXXgo8Gl9iqM="
953
953
  },
954
954
  {
955
955
  "virtualPath": "PlayerCore.wasm",
956
956
  "name": "PlayerCore.wasm",
957
- "hash": "sha256-9LvsVVijNT0+RhcdDx4Wp1xDXfMR4tCtK44OAWBU884="
957
+ "hash": "sha256-X3wtjTH8L8zy+MgD24EK8/Xj+y54ZGxY4PW593EYkkY="
958
958
  },
959
959
  {
960
960
  "virtualPath": "WasmPlayer.wasm",
961
961
  "name": "WasmPlayer.wasm",
962
- "hash": "sha256-gdsRHx7fDmJx1n/zi1/6Fn3+mJDoUy3mtbQV9lYG0OY="
962
+ "hash": "sha256-TAend3zTIYs+Us7ReKDqNhmZT0SaheVCHXyT3yTRvNw="
963
963
  }
964
964
  ],
965
965
  "assembly": []
package/index.html CHANGED
@@ -4,8 +4,18 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Quest Viva</title>
7
- <link rel="icon" type="image/svg+xml" href="favicon.svg" />
8
- <script type="text/javascript" src="quest-config.js"></script>
7
+ <link rel="icon" type="image/svg+xml" href="favicon.svg?v=6.0.0-beta.59" />
8
+ <!-- Lets the preload scanner start the runtime loader before the parser has
9
+ even reached wasm-player.js, which as the last script in this head only
10
+ executes once jQuery/jQuery UI/paper.js have all downloaded *and* run.
11
+ It's 37 KB, so it's unconditional rather than gated on a game actually
12
+ being on its way — the ~10.6 MB the loader then pulls is what's gated,
13
+ in wasm-player.js's boot IIFE. Stamped with ?v= like every other asset
14
+ here (scripts/inject-version.mjs), which is also what makes the
15
+ preload and wasm-player.js's own import() agree on one URL and share a
16
+ single fetch. -->
17
+ <link rel="modulepreload" href="_framework/dotnet.js?v=6.0.0-beta.59" />
18
+ <script type="text/javascript" src="quest-config.js?v=6.0.0-beta.59"></script>
9
19
  <script type="text/javascript">
10
20
  // Runs before the start screen is parsed, so when a game is specified via the
11
21
  // URL (or a defaultGameUrl is configured) we paint straight into the loading
@@ -23,28 +33,28 @@
23
33
  html.qv-booting #qv-pickers { display: none; }
24
34
  html.qv-booting #qv-loading-msg { display: flex; }
25
35
  </style>
26
- <script type="text/javascript" src="lib/jquery-2.1.1.min.js"></script>
27
- <script type="text/javascript" src="lib/jquery-ui.min.js"></script>
28
- <script type="text/javascript" src="lib/jquery.multi-open-accordion-1.5.3.js"></script>
29
- <link rel="stylesheet" type="text/css" href="lib/jquery-ui.min.css" />
30
- <link rel="stylesheet" type="text/css" href="playercore.css" />
36
+ <script type="text/javascript" src="lib/jquery-2.1.1.min.js?v=6.0.0-beta.59"></script>
37
+ <script type="text/javascript" src="lib/jquery-ui.min.js?v=6.0.0-beta.59"></script>
38
+ <script type="text/javascript" src="lib/jquery.multi-open-accordion-1.5.3.js?v=6.0.0-beta.59"></script>
39
+ <link rel="stylesheet" type="text/css" href="lib/jquery-ui.min.css?v=6.0.0-beta.59" />
40
+ <link rel="stylesheet" type="text/css" href="playercore.css?v=6.0.0-beta.59" />
31
41
  <!-- App-chrome styles (start screen, debugger, save-slot manager). Built from
32
42
  styles/chrome.css via `npm run build` — see WasmPlayer/package.json. All of
33
43
  its rules are contained to `.qv-chrome` subtrees so they can't affect the
34
44
  game UI above (playercore.css / jQuery UI). -->
35
- <link rel="stylesheet" type="text/css" href="chrome.css" />
36
- <script type="text/javascript" src="playercore.js"></script>
37
- <script type="text/javascript" src="player.js"></script>
38
- <script type="text/javascript" src="lib/paper.js"></script>
39
- <script>window.QuestVivaVersion = "6.0.0-beta.57";</script>
40
- <script type="text/javascript" src="wasm-player.js"></script>
45
+ <link rel="stylesheet" type="text/css" href="chrome.css?v=6.0.0-beta.59" />
46
+ <script type="text/javascript" src="playercore.js?v=6.0.0-beta.59"></script>
47
+ <script type="text/javascript" src="player.js?v=6.0.0-beta.59"></script>
48
+ <script type="text/javascript" src="lib/paper.js?v=6.0.0-beta.59"></script>
49
+ <script>window.QuestVivaVersion = "6.0.0-beta.59";</script>
50
+ <script type="text/javascript" src="wasm-player.js?v=6.0.0-beta.59"></script>
41
51
  </head>
42
52
  <body>
43
53
  <div id="qv-start" class="qv-chrome">
44
54
  <div class="card preset-filled-surface-100-900 w-full max-w-md p-8 space-y-6" data-theme="wintry">
45
55
  <div>
46
56
  <h1 class="h2 flex items-center gap-4">
47
- <img src="logo.svg" alt="" class="h-7" />
57
+ <img src="logo.svg?v=6.0.0-beta.59" alt="" class="h-7" />
48
58
  Quest Viva
49
59
  </h1>
50
60
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textadventures/quest-viva-wasmplayer",
3
- "version": "6.0.0-beta.57",
3
+ "version": "6.0.0-beta.59",
4
4
  "private": false,
5
5
  "description": "Quest Viva WasmPlayer runtime (browser-WASM text adventure player), published for CDN-linked single-file game exports.",
6
6
  "license": "MIT",
package/player.js CHANGED
@@ -41,6 +41,7 @@ var _menuSelection = "";
41
41
  function showMenu(title, options, allowCancel) {
42
42
  $("#dialogOptions").empty();
43
43
  var firstOption = true;
44
+ var optionCount = 0;
44
45
  $.each(options, function (key, value) {
45
46
  // Explicitly mark the first <option> selected - a <select> visually
46
47
  // shows its first option as selected by default, but jQuery's .val()
@@ -51,13 +52,23 @@ function showMenu(title, options, allowCancel) {
51
52
  $("<option/>").attr("value", key).text(value).prop("selected", firstOption)
52
53
  );
53
54
  firstOption = false;
55
+ optionCount++;
54
56
  });
55
57
 
58
+ // Show every option at once where we can - the markup's fallback size of 3
59
+ // meant a menu of more than three options was scrolled by default, with no
60
+ // hint that there was anything below the fold.
61
+ $("#dialogOptions").attr("size", Math.min(Math.max(optionCount, 3), 10));
62
+
56
63
  $("#dialogCaption").html(title);
57
64
 
58
65
  var dialogOptions = {
59
66
  modal: true,
60
67
  autoOpen: false,
68
+ // Size to the widest option rather than jQuery UI's default 300px,
69
+ // which clipped longer options. playercore.css caps how far this can
70
+ // grow so it can't overflow the window.
71
+ width: "auto",
61
72
  buttons: [{
62
73
  text: "Select",
63
74
  click: function () {
package/playercore.css CHANGED
@@ -80,12 +80,27 @@ div#gamePanes {
80
80
  }
81
81
 
82
82
  div#qv-status {
83
- height: 30px;
83
+ /* A border-box total (box-sizing below): 30px of bar plus
84
+ .ui-widget-header's 1px border top and bottom. */
85
+ height: 32px;
84
86
  position: fixed;
85
87
  top: 0px;
86
88
  z-index: 100;
87
- width: 100%;
88
- max-width: 948px;
89
+ /* Anchored to the viewport rather than left to its static position inside
90
+ #gameBorder. It's position: fixed, so a plain "width: 100%" resolved
91
+ against the viewport while the bar still started at #gameBorder's 1px
92
+ left border - and with .ui-widget-header's own 1px borders sitting
93
+ outside a content-box width, the bar overran the window by 3px and
94
+ clipped its rightmost button on a phone. left/right/margin: auto centres
95
+ it on the viewport instead, which is where #gameBorder centres too, so
96
+ the wide layout is unchanged. */
97
+ left: 0;
98
+ right: 0;
99
+ width: auto;
100
+ /* A border-box total, matching #gameBorder's content width - see
101
+ setGameWidth() in playercore.js, which caps this at runtime. */
102
+ box-sizing: border-box;
103
+ max-width: 950px;
89
104
  margin-left: auto;
90
105
  margin-right: auto;
91
106
  font-size: 14pt;
@@ -111,6 +126,25 @@ div#controlButtons {
111
126
  display: none;
112
127
  }
113
128
 
129
+ /* showMenu() opens the menu dialog with width: "auto" so that long options
130
+ aren't clipped, so it's the options themselves that decide how wide the
131
+ dialog gets. Keep that within the window, keep a long caption wrapping
132
+ instead of stretching the dialog out on its own, and let the options list
133
+ shrink rather than overflow once the cap is reached. */
134
+ .ui-dialog {
135
+ max-width: 95vw;
136
+ }
137
+
138
+ #dialogCaption {
139
+ max-width: 60ch;
140
+ }
141
+
142
+ #dialogOptions {
143
+ min-width: 100%;
144
+ max-width: 100%;
145
+ box-sizing: border-box;
146
+ }
147
+
114
148
  #msgbox {
115
149
  display: none;
116
150
  }
@@ -316,4 +350,156 @@ div.jj_menu_item_hover {
316
350
 
317
351
  #cmdShowPanes {
318
352
  display: none;
319
- }
353
+ }
354
+
355
+ /* ---------------------------------------------------------------------------
356
+ Narrow-window (phone/tablet) sizing - see issue #2181.
357
+
358
+ doLayout() in playercore.js owns the single narrow/wide threshold (the
359
+ window is narrower than the game width, so the panes have collapsed behind
360
+ the hamburger button) and publishes it as body.qv-narrow. Keying these rules
361
+ off that class rather than a media query of their own keeps one source of
362
+ truth: setGameWidth() can move the threshold at runtime, which a media query
363
+ couldn't follow.
364
+
365
+ The sizes here target WCAG 2.2's 44x44 CSS px pointer target (2.5.5 Target
366
+ Size (Enhanced)) and lift chrome text to 16px, matching the 12pt default
367
+ body text rather than sitting well below it.
368
+ --------------------------------------------------------------------------- */
369
+
370
+ .qv-narrow {
371
+ --qv-sidebar-width: min(320px, 85vw);
372
+ }
373
+
374
+ /* The status bar is a fixed 32px when wide, which can't hold a 44px button.
375
+ updateStatusVisibility() measures whatever height this ends up being rather
376
+ than assuming, so #gamePanel/#gridPanel/#gamePanes stay directly below it. */
377
+ .qv-narrow div#qv-status {
378
+ height: auto;
379
+ min-height: 50px;
380
+ }
381
+
382
+ .qv-narrow div#controlButtons {
383
+ padding-top: 2px;
384
+ }
385
+
386
+ .qv-narrow div#controlButtons .ui-button {
387
+ font-size: 16px !important;
388
+ min-height: 44px;
389
+ min-width: 44px;
390
+ /* jQuery UI puts the padding on the inner .ui-button-text span, so the
391
+ label sits at the top of a min-height-stretched button unless the button
392
+ itself centres it. */
393
+ display: inline-flex;
394
+ align-items: center;
395
+ justify-content: center;
396
+ }
397
+
398
+ .qv-narrow div#location {
399
+ padding-top: 12px;
400
+ }
401
+
402
+ /* Side pane: 12px text in 15px rows, inside a 220px overlay.
403
+
404
+ The overlay is anchored between the status bar (updateStatusVisibility()
405
+ sets its top from the bar's measured height, so it can't end up underneath
406
+ it) and the bottom of the window. "height: 100%" would instead run the
407
+ overlay's bottom edge off the screen by however far down its top starts,
408
+ putting the end of a long pane out of reach. */
409
+ .qv-narrow #sidebar {
410
+ width: var(--qv-sidebar-width);
411
+ box-sizing: border-box;
412
+ height: auto;
413
+ bottom: 0;
414
+ }
415
+
416
+ /* In the wide layout #gamePanes is a fixed, floated column positioned against
417
+ the viewport. Inside the narrow overlay it should simply be the overlay's
418
+ content: laying it out in flow is what lets #sidebar's own overflow-y scroll
419
+ it, which a fixed (out-of-flow) child left it unable to do - so a pane taller
420
+ than the screen had nothing to scroll and its lower half was unreachable.
421
+ float: none because a float would shrink-wrap instead of filling the width,
422
+ and min-height: 0 because a 100% of the overlay plus its padding is always
423
+ fractionally too tall, leaving the overlay permanently scrollable by a few
424
+ pixels. */
425
+ .qv-narrow div#gamePanes {
426
+ position: static;
427
+ float: none;
428
+ width: auto;
429
+ min-height: 0;
430
+ }
431
+
432
+ .qv-narrow #gamePanes .ui-widget {
433
+ font-size: 16px;
434
+ }
435
+
436
+ .qv-narrow .ui-accordion-header {
437
+ font-size: 16px;
438
+ }
439
+
440
+ .qv-narrow button.accordion-header-text {
441
+ min-height: 44px;
442
+ }
443
+
444
+ .qv-narrow .elementList li {
445
+ display: flex;
446
+ align-items: center;
447
+ min-height: 44px;
448
+ padding: 0 6px;
449
+ box-sizing: border-box;
450
+ }
451
+
452
+ /* Six 44px rows rather than the ten 15px ones the 200px cap used to hold. */
453
+ .qv-narrow .elementListWrapper {
454
+ max-height: 264px;
455
+ }
456
+
457
+ /* The multi-open accordion's expand/collapse arrow is a bare .ui-icon, not the
458
+ .ui-accordion-header-icon that jQuery UI's own centring rule targets, so it
459
+ keeps its static position at the top-left of the header's padding box - which
460
+ left it stranded against the top of a header now 44px tall. Centre it on the
461
+ header and scale the 16px sprite up to match the rest of the touch chrome
462
+ (transform rather than background-size, so the sprite's per-icon background
463
+ position doesn't have to be recomputed). */
464
+ .qv-narrow .ui-accordion-header > .ui-icon {
465
+ top: 50%;
466
+ margin-top: -8px;
467
+ transform: scale(1.5);
468
+ }
469
+
470
+ /* The compass lives in the same pane, and its buttons are 35px. */
471
+ .qv-narrow .compassbutton {
472
+ height: 44px;
473
+ width: 44px;
474
+ }
475
+
476
+ /* playercore.js pins the direction icon at an inline left: 0.8em, which centres
477
+ it in a 35px button but not a 44px one - hand centring back to jQuery UI's
478
+ own rule for it. */
479
+ .qv-narrow .compassbutton span.ui-icon {
480
+ left: 50% !important;
481
+ margin-left: -8px;
482
+ }
483
+
484
+ .qv-narrow #compassTable .ui-button {
485
+ font-size: 14px !important;
486
+ }
487
+
488
+ .qv-narrow .verbButtons .ui-button {
489
+ font-size: 14px !important;
490
+ min-height: 44px;
491
+ display: inline-flex;
492
+ align-items: center;
493
+ justify-content: center;
494
+ }
495
+
496
+ /* Hyperlink pop-up menu. The font size itself is the game's to choose (see
497
+ SetMenuFontSize in playercore.js, which applies a floor here rather than
498
+ overriding it outright), so only the row height is set from CSS. */
499
+ .qv-narrow div.jj_menu_item span {
500
+ display: flex;
501
+ align-items: center;
502
+ min-height: 44px;
503
+ padding: 4px 10px;
504
+ box-sizing: border-box;
505
+ }
package/playercore.js CHANGED
@@ -232,6 +232,13 @@ function initPlayerUI() {
232
232
  const doLayout = () => {
233
233
  let isWide = isWindowWide();
234
234
 
235
+ // Published as a class so playercore.css can hang its larger touch
236
+ // targets off the same threshold this function already owns, instead
237
+ // of duplicating it as a media query - which setGameWidth() would then
238
+ // have no way to move. See issue #2181.
239
+ document.body.classList.toggle("qv-narrow", !isWide);
240
+ refreshMenuFontSize();
241
+
235
242
  if (isWide && arePanesVisible) {
236
243
  sidebar.style.display = "block";
237
244
  sidebar.style.background = "initial";
@@ -263,14 +270,18 @@ function initPlayerUI() {
263
270
  if (window.paper && paper.view) paper.view.viewSize.width = Math.min(window.innerWidth, gameWidth);
264
271
  }
265
272
 
266
- const newPanelImageMaxHeight = `${(window.innerHeight - 30) * 0.5}px`;
267
- updatePanelImageMaxHeight(newPanelImageMaxHeight);
268
-
269
273
  // cmdShowPanes.style.display was just set above - recompute #qv-status's own
270
274
  // visibility now in case resizing past the narrow-window threshold is what
271
275
  // just made (or unmade) the hamburger button #qv-status's only visible child.
272
276
  updateStatusVisibility();
273
277
 
278
+ // Budget the sticky picture frame against however tall the status bar
279
+ // actually ended up - it used to subtract a hard-coded 30, which is
280
+ // neither its narrow-layout height nor right at all when it isn't
281
+ // showing. updateStatusVisibility() has just settled both, hence the
282
+ // ordering here.
283
+ updatePanelImageMaxHeight(`${(window.innerHeight - statusBarHeight()) * 0.5}px`);
284
+
274
285
  wasWide = isWide;
275
286
  }
276
287
 
@@ -280,8 +291,12 @@ function initPlayerUI() {
280
291
  const gameBorder = document.getElementById("gameBorder");
281
292
  gameBorder.style.maxWidth = width + "px";
282
293
 
294
+ // playercore.css gives #qv-status box-sizing: border-box, so this cap is
295
+ // the bar's whole width including its 1px borders - matching #gameBorder's
296
+ // content box, which is what "width" is there (it's content-box, with its
297
+ // own 1px borders outside that).
283
298
  const status = document.getElementById("qv-status");
284
- status.style.maxWidth = (width - 2) + "px";
299
+ status.style.maxWidth = width + "px";
285
300
 
286
301
  gameWidth = width;
287
302
  doLayout();
@@ -393,6 +408,13 @@ function setGameName(text) {
393
408
  var _waitMode = false;
394
409
  var _pauseMode = false;
395
410
 
411
+ // True between endPause() and pauseEnded(), i.e. while the command bar is
412
+ // hidden only because a finished pause hasn't been able to restore it yet.
413
+ // Anything that snapshots the command bar's current visibility to restore it
414
+ // later (playSound's synchronous branch) has to count that as visible, or the
415
+ // pause's pending restore is swallowed and the command bar never comes back.
416
+ var _pauseRestorePending = false;
417
+
396
418
  // Mirrors the engine's WorldModel._pendingCallbackCount > 0: true whenever
397
419
  // anything is suspended inside a TaskCompletionSource continuation (wait(),
398
420
  // get input(), ask, show menu, pause) that a save/reload can't reconstruct -
@@ -422,15 +444,35 @@ function beginPause(ms) {
422
444
  }
423
445
 
424
446
  function endPause() {
447
+ if (!_pauseMode) return;
425
448
  _pauseMode = false;
426
- $("#txtCommandDiv").show();
449
+ // The command bar deliberately stays hidden until pauseEnded() - showing it
450
+ // here made it flash into view for the length of the round trip whenever the
451
+ // resumed script went straight into another pause (same bug as endWait()).
452
+ _pauseRestorePending = true;
427
453
 
428
454
  // TODO: This is WebPlayer-specific, so shouldn't be in this shared file
429
455
  window.setTimeout(async function () {
430
- await WebPlayer.uiEndPause();
456
+ try {
457
+ await WebPlayer.uiEndPause();
458
+ } finally {
459
+ pauseEnded();
460
+ }
431
461
  }, 100);
432
462
  }
433
463
 
464
+ // Called once the engine has resumed the paused turn and run on to its next
465
+ // stopping point, so anything that turn did to the command bar has already
466
+ // happened: another pause (beginPause), the end of the game (disableInterface)
467
+ // or a synchronous sound (playSound), each of which owns the command bar until
468
+ // it restores it itself.
469
+ function pauseEnded() {
470
+ _pauseRestorePending = false;
471
+ if (_pauseMode || _gameFinished || _waitingForSoundToFinish) return;
472
+ $("#txtCommandDiv").show();
473
+ focusCommandInput();
474
+ }
475
+
434
476
  function commandKey(e) {
435
477
  if (_waitMode) return false;
436
478
  switch (keyPressCode(e)) {
@@ -556,16 +598,40 @@ function updateStatusVisibility() {
556
598
  || isElementVisible("#cmdDebug") || isElementVisible("#cmdShowPanes");
557
599
  if (anyVisible) {
558
600
  $("#qv-status").show();
559
- $("#divOutput").css("margin-top", "20px");
560
- $("#gamePanes").css("top", "24px");
561
- $("#gridPanel").css("top", "32px");
562
- $("#gamePanel").css("top", "32px");
601
+ // #qv-status is no longer a fixed height - on a narrow window it grows
602
+ // to fit 44px touch targets (see playercore.css's .qv-narrow rules), so
603
+ // measure its real bottom edge rather than repeating the height as a
604
+ // constant here. Its 32px on the desktop layout is what the old 24/32
605
+ // constants were describing: the panels sat flush with the bar's bottom
606
+ // edge, and #gamePanes deliberately tucked 8px up under it.
607
+ var statusHeight = statusBarHeight();
608
+ // #qv-status is position: fixed, so it takes up no space in flow and
609
+ // this margin is the whole of what holds the game text clear of it.
610
+ // The 20px it used to be was picked against the 32px desktop bar,
611
+ // leaving 18px of daylight - which a 50px narrow-layout bar closed to
612
+ // nothing, running the text right up under it. Tracking the bar keeps
613
+ // that daylight constant. It's expressed as an offset from the bar's
614
+ // own height rather than computed from #gameContent's padding, so a
615
+ // game setting its own custompaddingtop keeps exactly the spacing it
616
+ // has today.
617
+ $("#divOutput").css("margin-top", (statusHeight - 12) + "px");
618
+ $("#gamePanes").css("top", (statusHeight - 8) + "px");
619
+ $("#gridPanel").css("top", statusHeight + "px");
620
+ $("#gamePanel").css("top", statusHeight + "px");
621
+ // The narrow layout's pane overlay, which is opaque and would otherwise
622
+ // sit over the bottom of the bar it drops down from. (In the wide
623
+ // layout it's a transparent container and this is the 32px it already
624
+ // had.) #gamePanes is laid out inside it there rather than positioned,
625
+ // so this is what actually places the panes on a narrow window - its
626
+ // own "top" above is only read by the wide layout.
627
+ $("#sidebar").css("top", statusHeight + "px");
563
628
  } else {
564
629
  $("#qv-status").hide();
565
630
  $("#divOutput").css("margin-top", "0px");
566
631
  $("#gamePanes").css("top", "0px");
567
632
  $("#gridPanel").css("top", "0px");
568
633
  $("#gamePanel").css("top", "0px");
634
+ $("#sidebar").css("top", "0px");
569
635
  }
570
636
  }
571
637
 
@@ -573,6 +639,20 @@ function isElementVisible(element) {
573
639
  return $(element).css("display") != "none";
574
640
  }
575
641
 
642
+ // doLayout() publishes its narrow/wide threshold as a class on <body> - see
643
+ // playercore.css's .qv-narrow rules.
644
+ function isNarrowLayout() {
645
+ return document.body.classList.contains("qv-narrow");
646
+ }
647
+
648
+ // #qv-status's on-screen height, or 0 when it isn't showing at all. 32px on the
649
+ // desktop layout, but it grows to hold 44px touch targets on a narrow one, so
650
+ // nothing downstream should be assuming a number for it.
651
+ function statusBarHeight() {
652
+ var $status = $("#qv-status");
653
+ return ($status.length && isElementVisible($status)) ? $status.outerHeight() : 0;
654
+ }
655
+
576
656
  var _animateScroll = true;
577
657
 
578
658
  // The page's own scrollable content sits behind #qv-status (fixed) and
@@ -693,7 +773,12 @@ function scrollToTurnStart(turnStart, allowBackward) {
693
773
  // jumped straight to the document's bottom, undoing every calculation above.
694
774
  // {preventScroll: true} keeps the input usable (typing still works
695
775
  // immediately) without fighting the scroll position we just computed.
776
+ //
777
+ // Also guards against focusing the input while it's genuinely hidden (mid
778
+ // wait()/pause()) — needed by waitEnded()/pauseEnded(), which share this
779
+ // same function to restore focus once the command bar comes back.
696
780
  function focusCommandInput() {
781
+ if (!isElementVisible("#txtCommandDiv") || !isElementVisible("#txtCommand")) return;
697
782
  document.getElementById("txtCommand")?.focus({preventScroll: true});
698
783
  }
699
784
 
@@ -941,14 +1026,26 @@ function beginWait() {
941
1026
 
942
1027
  function endWait() {
943
1028
  if (!_waitMode) return;
1029
+ // Leave wait mode and hide the Continue link straight away: that's the
1030
+ // click's immediate feedback, and it also stops a second click/keypress
1031
+ // firing a second FinishWait while the engine is resuming. The command
1032
+ // input deliberately stays hidden until waitEnded() - see below.
1033
+ _waitMode = false;
1034
+ $("#endWaitLink").hide();
944
1035
  sendEndWait();
945
1036
  }
946
1037
 
1038
+ // Called by the platform's sendEndWait() once the engine has resumed the
1039
+ // suspended turn and run on to its next stopping point. If that turn started
1040
+ // another wait(), beginWait() has already re-hidden the command input and
1041
+ // re-shown the Continue link, so leave both alone: restoring the input
1042
+ // unconditionally (as this used to, synchronously at click time) is what made
1043
+ // it flash into view for the length of the round trip between chained waits.
947
1044
  function waitEnded() {
948
- _waitMode = false;
949
- $("#endWaitLink").hide();
1045
+ if (_waitMode) return;
950
1046
  $("#txtCommand").show();
951
1047
  $("#txtCommandPrompt").show();
1048
+ focusCommandInput();
952
1049
  }
953
1050
 
954
1051
  function gameFinished() {
@@ -1299,39 +1396,63 @@ function AddVimeo(id) {
1299
1396
  }
1300
1397
 
1301
1398
  function SetMenuBackground(color) {
1302
- var css = getCSSRule("div.jj_menu_item");
1399
+ var css = addCSSRule("div.jj_menu_item");
1303
1400
  css.style.backgroundColor = color;
1304
1401
  }
1305
1402
 
1306
1403
  function SetMenuForeground(color) {
1307
- var css = getCSSRule("div.jj_menu_item");
1404
+ var css = addCSSRule("div.jj_menu_item");
1308
1405
  css.style.color = color;
1309
1406
  }
1310
1407
 
1311
1408
  function SetMenuHoverBackground(color) {
1312
- var css = getCSSRule("div.jj_menu_item_hover");
1409
+ var css = addCSSRule("div.jj_menu_item_hover");
1313
1410
  css.style.backgroundColor = color;
1314
1411
  }
1315
1412
 
1316
1413
  function SetMenuHoverForeground(color) {
1317
- var css = getCSSRule("div.jj_menu_item_hover");
1414
+ var css = addCSSRule("div.jj_menu_item_hover");
1318
1415
  css.style.color = color;
1319
1416
  }
1320
1417
 
1321
1418
  function SetMenuFontName(font) {
1322
- var css = getCSSRule("div.jjmenu");
1419
+ var css = addCSSRule("div.jjmenu");
1323
1420
  css.style.fontFamily = font;
1324
1421
  }
1325
1422
 
1423
+ // game.menufontsize defaults to 9pt (12px), and - like every other Core
1424
+ // library value - is inlined into each game at publish time, so an already
1425
+ // published game calls SetMenuFontSize("9pt") on startup no matter what this
1426
+ // stylesheet's own default says. Rather than ignoring the game outright, treat
1427
+ // its value as a request with a floor under it on a narrow window: an author
1428
+ // who asked for something larger (theme_retro asks for 14pt) still gets
1429
+ // exactly what they asked for. max() does the comparison in CSS, so "9pt"
1430
+ // doesn't have to be converted to px here; in a browser without support the
1431
+ // assignment is simply dropped and the stylesheet's own div.jjmenu size
1432
+ // stands, exactly as it did before. See issue #2181.
1433
+ function menuFontSizeWithFloor(size) {
1434
+ return isNarrowLayout() ? "max(" + size + ", 16px)" : size;
1435
+ }
1436
+
1437
+ // The size the game last asked for, before any narrow-window floor, so the
1438
+ // floor can be re-evaluated when the window crosses the threshold.
1439
+ var _requestedMenuFontSize = null;
1440
+
1326
1441
  function SetMenuFontSize(size) {
1327
1442
  if (_allowMenuFontSizeChange) {
1328
- var css = getCSSRule("div.jjmenu");
1329
- css.style.fontSize = size;
1443
+ var css = addCSSRule("div.jjmenu");
1444
+ css.style.fontSize = menuFontSizeWithFloor(size);
1445
+ _requestedMenuFontSize = size;
1330
1446
  }
1331
1447
  }
1332
1448
 
1449
+ function refreshMenuFontSize() {
1450
+ if (_requestedMenuFontSize == null) return;
1451
+ addCSSRule("div.jjmenu").style.fontSize = menuFontSizeWithFloor(_requestedMenuFontSize);
1452
+ }
1453
+
1333
1454
  function TurnOffHyperlinksUnderline() {
1334
- var css = getCSSRule("a.cmdlink");
1455
+ var css = addCSSRule("a.cmdlink");
1335
1456
  css.style.textDecoration = "none";
1336
1457
  }
1337
1458
 
package/wasm-player.js CHANGED
@@ -27,6 +27,28 @@ console.log(
27
27
  // relative resolution entirely, so it works either way.
28
28
  const wasmPlayerScriptUrl = document.currentScript?.src;
29
29
 
30
+ // Cache key for this build's own static assets, matching the `?v=` that
31
+ // scripts/inject-version.mjs stamps onto every asset URL in the markup —
32
+ // window.QuestVivaVersion is spliced in by that same script. This covers the
33
+ // assets fetched from JS instead (playercore.htm, grid.js, and everything
34
+ // under _framework/), so a deploy changes every URL and play.questviva.com can
35
+ // serve them `immutable` rather than revalidating ~210 files on each load.
36
+ //
37
+ // For _framework/ specifically the version is also what makes `immutable`
38
+ // *safe*. None of those filenames are content-hashed and AOT output isn't
39
+ // byte-reproducible, so a browser holding dotnet.boot.js (the manifest of
40
+ // per-file SHA-256 hashes) from one deploy alongside a binary from the next
41
+ // gets an SRI mismatch and the resource is blocked. Stamping manifest and
42
+ // binaries with the same version means they can never come from different
43
+ // deploys — which is what the blanket `Cache-Control: no-cache` on
44
+ // _framework/* used to buy, at the cost of ~190 revalidations per page load.
45
+ //
46
+ // Empty when the version is unknown (which also leaves the runtime's own
47
+ // no-cache fetching alone, below) — nothing then depends on cache keys.
48
+ const assetVersion = window.QuestVivaVersion || '';
49
+ const assetVersionQuery = assetVersion ? `?v=${encodeURIComponent(assetVersion)}` : '';
50
+ const versioned = (url) => (assetVersionQuery && !url.includes('?') ? url + assetVersionQuery : url);
51
+
30
52
  var _audio = null;
31
53
 
32
54
  const pendingResources = new Map();
@@ -224,10 +246,20 @@ function stageAdjacentFiles(files) {
224
246
  function ui_init() { }
225
247
 
226
248
  function sendEndWait() {
249
+ // The short delay lets the browser paint endWait()'s hidden Continue link
250
+ // before the engine resumes and (in the WASM build, which runs it on the
251
+ // one UI thread) blocks painting for the rest of the turn.
227
252
  window.setTimeout(async function () {
228
- await WebPlayer.uiEndWait();
253
+ try {
254
+ await WebPlayer.uiEndWait();
255
+ } finally {
256
+ // uiEndWait only resolves once the resumed turn has reached its
257
+ // next stopping point and flushed its UI calls, so by now
258
+ // beginWait() has already run for a chained wait() - which is
259
+ // exactly what waitEnded() checks before restoring the input.
260
+ waitEnded();
261
+ }
229
262
  }, 100);
230
- waitEnded();
231
263
  }
232
264
 
233
265
  function afterSendCommand() { }
@@ -237,7 +269,10 @@ function playSound(url, synchronous, looped) {
237
269
  _audio = new Audio(url);
238
270
  if (looped) _audio.loop = true;
239
271
  if (synchronous) {
240
- var showCmdDiv = isElementVisible("#txtCommandDiv");
272
+ // Counts a pause whose restore is still pending as visible - see
273
+ // _pauseRestorePending, otherwise finishSync() below leaves the command
274
+ // bar hidden for good.
275
+ var showCmdDiv = isElementVisible("#txtCommandDiv") || _pauseRestorePending;
241
276
  _waitingForSoundToFinish = true;
242
277
  $("#txtCommandDiv").hide();
243
278
  _audio.addEventListener('ended', function () { finishSync(showCmdDiv); });
@@ -426,7 +461,7 @@ async function setupPaperJs() {
426
461
  canvas.style.display = 'none';
427
462
  document.body.appendChild(canvas);
428
463
  paper.setup(canvas);
429
- const code = await fetch('grid.js').then(r => r.text());
464
+ const code = await fetch(versioned('grid.js')).then(r => r.text());
430
465
  paper.PaperScript.evaluate(code, paper);
431
466
  }
432
467
 
@@ -479,19 +514,75 @@ let currentIsPreview = false;
479
514
  // must NOT also disable Save or add the Restart button the way isPreview does.
480
515
  let currentAllowDebug = false;
481
516
 
517
+ // ── .NET runtime bootstrap ───────────────────────────────────────────────────
518
+ //
519
+ // The runtime is ~10.6 MB spread over ~190 files, and which game is being
520
+ // played has no bearing on any of it. It used to be imported and instantiated
521
+ // inside initWasmPlayer() — i.e. only once the game bytes were already in
522
+ // hand, which for a ?id= link means after a textadventures API round trip and
523
+ // then the game download, neither of which it depends on. Splitting the
524
+ // download away from create() lets the boot IIFE start it up front instead, in
525
+ // parallel with those two fetches. See issue #2186.
526
+ let runtimeBuilderPromise = null;
527
+
528
+ // Resolves to the configured — but not yet instantiated — host builder.
529
+ function loadRuntimeBuilder() {
530
+ if (runtimeBuilderPromise) return runtimeBuilderPromise;
531
+ // A relative specifier fails here when this script is loaded cross-origin
532
+ // (the CDN-linked single-file export) — see wasmPlayerScriptUrl's comment.
533
+ // The version query is load-bearing beyond its own cache key too: the
534
+ // loader reads it back off its own import.meta.url and propagates it to
535
+ // the JS modules it imports and to dotnet.boot.js (`modulesUniqueQuery`),
536
+ // so those need no further handling in withResourceLoader below.
537
+ const dotnetJsUrl = versioned(wasmPlayerScriptUrl
538
+ ? new URL('_framework/dotnet.js', wasmPlayerScriptUrl).href
539
+ : './_framework/dotnet.js');
540
+ runtimeBuilderPromise = import(dotnetJsUrl).then(({ dotnet }) => dotnet
541
+ // The loader otherwise passes `cache: "no-cache"` on every asset fetch,
542
+ // which forces a conditional request regardless of how long the CDN
543
+ // said the response was fresh for — so without this, `immutable` on
544
+ // _framework/* buys nothing at all. Only safe to turn off because the
545
+ // URLs are version-stamped (see assetVersionQuery); left alone when
546
+ // there's no version to stamp with.
547
+ .withConfig({ disableNoCacheFetch: !!assetVersionQuery })
548
+ // Stamps the remaining assets — the assemblies, dotnet.native.wasm and
549
+ // the ICU data. Returning null means "use the default URL", which is
550
+ // what the JS modules and the manifest want: modulesUniqueQuery has
551
+ // already appended the same query to those, and doing it here as well
552
+ // would produce a doubled `?v=...?v=...`.
553
+ .withResourceLoader((type, name, defaultUri) =>
554
+ !assetVersionQuery || type === 'manifest' || type === 'dotnetjs'
555
+ ? null
556
+ : versioned(defaultUri)));
557
+ return runtimeBuilderPromise;
558
+ }
559
+
560
+ // Pulls every runtime asset into the browser cache without instantiating
561
+ // anything, so the create() in initWasmPlayer has nothing left to fetch.
562
+ // Fire-and-forget by design: it's started before we know the game will even
563
+ // load, and its result is not what anyone waits on. The runtime's own
564
+ // bookkeeping makes create() reuse this exact work rather than repeat it
565
+ // (mono_download_assets is one-shot), and a failure here resurfaces from
566
+ // create() where startGame already turns it into a visible error — so the
567
+ // catch here only exists to keep it from becoming an unhandled rejection.
568
+ //
569
+ // The trade is that a game that turns out not to exist (a bad ?id=) now
570
+ // downloads some of a runtime it won't use. That costs a failed load some
571
+ // bandwidth; not doing it costs every successful load ~1.7s.
572
+ function preloadRuntime() {
573
+ loadRuntimeBuilder().then(builder => builder.download()).catch(() => {});
574
+ }
575
+
482
576
  async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null, isPreview = false, recordWalkthrough = null, runWalkthrough = null, adjacentFiles = null, allowDebug = false) {
483
577
  currentIsPreview = isPreview;
484
578
  currentAllowDebug = allowDebug;
485
- const dotnetJsUrl = wasmPlayerScriptUrl
486
- ? new URL('_framework/dotnet.js', wasmPlayerScriptUrl).href
487
- : './_framework/dotnet.js';
488
- const [htmResponse, { dotnet }] = await Promise.all([
489
- fetch('playercore.htm'),
490
- import(dotnetJsUrl),
579
+ const [htmResponse, builder] = await Promise.all([
580
+ fetch(versioned('playercore.htm')),
581
+ loadRuntimeBuilder(),
491
582
  ]);
492
583
  originalPlayerHtml = await htmResponse.text();
493
584
 
494
- const runtime = await dotnet.create();
585
+ const runtime = await builder.create();
495
586
  const { setModuleImports, getAssemblyExports, getConfig } = runtime;
496
587
 
497
588
  setModuleImports("wasm-player", {
@@ -2060,6 +2151,7 @@ async function fetchGameBytes(url) {
2060
2151
  // other boot source converges on. Checked first since, unlike the sources
2061
2152
  // below, an embedded export never carries any of their query params.
2062
2153
  if (window.QuestVivaEmbeddedGame) {
2154
+ preloadRuntime();
2063
2155
  const bytes = Uint8Array.from(atob(window.QuestVivaEmbeddedGame), c => c.charCodeAt(0));
2064
2156
  const filename = window.QuestVivaEmbeddedGameFilename || 'game.quest';
2065
2157
  document.addEventListener('DOMContentLoaded', async () => {
@@ -2072,6 +2164,7 @@ async function fetchGameBytes(url) {
2072
2164
  const params = new URLSearchParams(window.location.search);
2073
2165
 
2074
2166
  if (params.get('source') === 'editor') {
2167
+ preloadRuntime();
2075
2168
  const bc = new BroadcastChannel('quest-preview');
2076
2169
  bc.postMessage({ type: 'ready' });
2077
2170
  bc.onmessage = async ({ data }) => {
@@ -2097,6 +2190,7 @@ async function fetchGameBytes(url) {
2097
2190
  // distinct channel name keeps this from cross-talking with a real
2098
2191
  // editor-preview tab open at the same time.
2099
2192
  if (params.get('source') === 'local') {
2193
+ preloadRuntime();
2100
2194
  const bc = new BroadcastChannel('quest-play-local');
2101
2195
  bc.postMessage({ type: 'ready' });
2102
2196
  // Covers the case where nothing ever answers — see
@@ -2135,7 +2229,10 @@ async function fetchGameBytes(url) {
2135
2229
  const gameUrl = params.get('url') || window.QuestVivaConfig?.defaultGameUrl;
2136
2230
 
2137
2231
  if (id) {
2138
- // Start API fetch immediately; wire DOM once it's ready.
2232
+ // Start API fetch immediately; wire DOM once it's ready. The runtime
2233
+ // download runs alongside it rather than behind it — the API response
2234
+ // and the game file it points at are what used to gate it.
2235
+ preloadRuntime();
2139
2236
  let resolvedSourceUrl = null;
2140
2237
  const gamePromise = (async () => {
2141
2238
  const apiRoot = window.QuestVivaConfig?.textAdventuresApiRoot
@@ -2167,6 +2264,7 @@ async function fetchGameBytes(url) {
2167
2264
 
2168
2265
  if (gameUrl) {
2169
2266
  // Start fetch immediately; wire DOM once it's ready.
2267
+ preloadRuntime();
2170
2268
  const gamePromise = fetchGameBytes(gameUrl);
2171
2269
 
2172
2270
  document.addEventListener('DOMContentLoaded', async () => {