@textadventures/quest-viva-wasmplayer 6.1.0-beta.1 → 6.1.0-beta.3

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.
Files changed (84) hide show
  1. package/_framework/Common.wasm +0 -0
  2. package/_framework/Engine.wasm +0 -0
  3. package/_framework/Legacy.wasm +0 -0
  4. package/_framework/PlayerCore.wasm +0 -0
  5. package/_framework/System.Text.Json.wasm +0 -0
  6. package/_framework/WasmPlayer.wasm +0 -0
  7. package/_framework/dotnet.js +9 -9
  8. package/chrome.css +1 -1
  9. package/export-manifest.json +1 -1
  10. package/fonts/courier-prime/LICENSE.txt +93 -0
  11. package/fonts/courier-prime/latin-400-italic.woff2 +0 -0
  12. package/fonts/courier-prime/latin-400-normal.woff2 +0 -0
  13. package/fonts/courier-prime/latin-700-italic.woff2 +0 -0
  14. package/fonts/courier-prime/latin-700-normal.woff2 +0 -0
  15. package/fonts/courier-prime/latin-ext-400-italic.woff2 +0 -0
  16. package/fonts/courier-prime/latin-ext-400-normal.woff2 +0 -0
  17. package/fonts/courier-prime/latin-ext-700-italic.woff2 +0 -0
  18. package/fonts/courier-prime/latin-ext-700-normal.woff2 +0 -0
  19. package/fonts/fonts.css +500 -0
  20. package/fonts/literata/LICENSE.txt +93 -0
  21. package/fonts/literata/cyrillic-400-italic.woff2 +0 -0
  22. package/fonts/literata/cyrillic-400-normal.woff2 +0 -0
  23. package/fonts/literata/cyrillic-700-italic.woff2 +0 -0
  24. package/fonts/literata/cyrillic-700-normal.woff2 +0 -0
  25. package/fonts/literata/cyrillic-ext-400-italic.woff2 +0 -0
  26. package/fonts/literata/cyrillic-ext-400-normal.woff2 +0 -0
  27. package/fonts/literata/cyrillic-ext-700-italic.woff2 +0 -0
  28. package/fonts/literata/cyrillic-ext-700-normal.woff2 +0 -0
  29. package/fonts/literata/greek-400-italic.woff2 +0 -0
  30. package/fonts/literata/greek-400-normal.woff2 +0 -0
  31. package/fonts/literata/greek-700-italic.woff2 +0 -0
  32. package/fonts/literata/greek-700-normal.woff2 +0 -0
  33. package/fonts/literata/greek-ext-400-italic.woff2 +0 -0
  34. package/fonts/literata/greek-ext-400-normal.woff2 +0 -0
  35. package/fonts/literata/greek-ext-700-italic.woff2 +0 -0
  36. package/fonts/literata/greek-ext-700-normal.woff2 +0 -0
  37. package/fonts/literata/latin-400-italic.woff2 +0 -0
  38. package/fonts/literata/latin-400-normal.woff2 +0 -0
  39. package/fonts/literata/latin-700-italic.woff2 +0 -0
  40. package/fonts/literata/latin-700-normal.woff2 +0 -0
  41. package/fonts/literata/latin-ext-400-italic.woff2 +0 -0
  42. package/fonts/literata/latin-ext-400-normal.woff2 +0 -0
  43. package/fonts/literata/latin-ext-700-italic.woff2 +0 -0
  44. package/fonts/literata/latin-ext-700-normal.woff2 +0 -0
  45. package/fonts/literata/vietnamese-400-italic.woff2 +0 -0
  46. package/fonts/literata/vietnamese-400-normal.woff2 +0 -0
  47. package/fonts/literata/vietnamese-700-italic.woff2 +0 -0
  48. package/fonts/literata/vietnamese-700-normal.woff2 +0 -0
  49. package/fonts/nunito/LICENSE.txt +93 -0
  50. package/fonts/nunito/cyrillic-400-italic.woff2 +0 -0
  51. package/fonts/nunito/cyrillic-400-normal.woff2 +0 -0
  52. package/fonts/nunito/cyrillic-700-italic.woff2 +0 -0
  53. package/fonts/nunito/cyrillic-700-normal.woff2 +0 -0
  54. package/fonts/nunito/cyrillic-ext-400-italic.woff2 +0 -0
  55. package/fonts/nunito/cyrillic-ext-400-normal.woff2 +0 -0
  56. package/fonts/nunito/cyrillic-ext-700-italic.woff2 +0 -0
  57. package/fonts/nunito/cyrillic-ext-700-normal.woff2 +0 -0
  58. package/fonts/nunito/latin-400-italic.woff2 +0 -0
  59. package/fonts/nunito/latin-400-normal.woff2 +0 -0
  60. package/fonts/nunito/latin-700-italic.woff2 +0 -0
  61. package/fonts/nunito/latin-700-normal.woff2 +0 -0
  62. package/fonts/nunito/latin-ext-400-italic.woff2 +0 -0
  63. package/fonts/nunito/latin-ext-400-normal.woff2 +0 -0
  64. package/fonts/nunito/latin-ext-700-italic.woff2 +0 -0
  65. package/fonts/nunito/latin-ext-700-normal.woff2 +0 -0
  66. package/fonts/nunito/vietnamese-400-italic.woff2 +0 -0
  67. package/fonts/nunito/vietnamese-400-normal.woff2 +0 -0
  68. package/fonts/nunito/vietnamese-700-italic.woff2 +0 -0
  69. package/fonts/nunito/vietnamese-700-normal.woff2 +0 -0
  70. package/fonts/special-elite/LICENSE.txt +201 -0
  71. package/fonts/special-elite/latin-400-normal.woff2 +0 -0
  72. package/fonts/special-elite/latin-ext-400-normal.woff2 +0 -0
  73. package/fonts/vt323/LICENSE.txt +93 -0
  74. package/fonts/vt323/latin-400-normal.woff2 +0 -0
  75. package/fonts/vt323/latin-ext-400-normal.woff2 +0 -0
  76. package/fonts/vt323/vietnamese-400-normal.woff2 +0 -0
  77. package/index.html +14 -10
  78. package/legacy/playercore.js +12 -1
  79. package/legacy/questui.js +52 -0
  80. package/package.json +1 -1
  81. package/v2/player.htm +5 -1
  82. package/v2/v2.css +1 -1
  83. package/v2/v2.js +1 -1
  84. package/wasm-player.js +143 -15
package/wasm-player.js CHANGED
@@ -679,11 +679,31 @@ function transcriptText(html) {
679
679
  let currentGameName = '';
680
680
  let currentPlayerUiName = null; // 'legacy' or 'v2', once preparePlayerUi has picked it
681
681
 
682
+ // Whether any transcript is already stored, from this game or another: the
683
+ // viewer lists them all. Electron's store answers asynchronously
684
+ // (player-preload.ts), so its answer is fetched as the player UI starts
685
+ // (wireTranscriptsButton) and kept here.
686
+ let electronTranscriptsStored = false;
687
+ function anyTranscriptStored() {
688
+ if (navigator.userAgent.includes('Electron/')) return electronTranscriptsStored;
689
+ try {
690
+ for (let i = 0; i < localStorage.length; i++) {
691
+ if (localStorage.key(i)?.startsWith('questtranscript-')) return true;
692
+ }
693
+ } catch {
694
+ // Storage blocked (a private window, or site data turned off)
695
+ }
696
+ return false;
697
+ }
698
+
682
699
  const transcript = {
683
700
  recording: false,
684
701
  // "kill": the game has turned transcripts off for good, until "revive".
685
702
  killed: false,
686
703
  name: '',
704
+ // Whether anything has been written since the page loaded. Electron's
705
+ // store hasn't been asked again since, so this stands in for it.
706
+ recorded: false,
687
707
 
688
708
  // Each Initialise: 610 Core's InitInterface turns it back on if the game
689
709
  // (or the save being restored) has it on.
@@ -696,24 +716,63 @@ const transcript = {
696
716
  if (this.killed) return;
697
717
  this.name = name || this.name || currentGameName || 'Transcript';
698
718
  this.recording = true;
719
+ updateTranscriptsButton();
699
720
  },
700
721
  disable() { this.recording = false; },
701
722
  kill() {
702
723
  this.killed = true;
703
724
  this.recording = false;
725
+ updateTranscriptsButton();
726
+ },
727
+ revive() {
728
+ this.killed = false;
729
+ updateTranscriptsButton();
704
730
  },
705
- revive() { this.killed = false; },
706
731
  setName(name) { this.name = name || ''; },
707
732
  write(html) {
708
733
  if (!this.recording || this.killed) return;
709
734
  if (!appendToTranscript(this.name || currentGameName || 'Transcript', transcriptText(html))) {
710
735
  console.error('There is no localStorage. Disabling transcript functionality.');
711
736
  this.kill();
737
+ return;
738
+ }
739
+ if (!this.recorded) {
740
+ this.recorded = true;
741
+ updateTranscriptsButton();
712
742
  }
713
743
  },
744
+ // Whether there's a transcript to view: this game is recording one, or
745
+ // one has been kept, unless the game has turned the feature off
746
+ // ("notranscript", which reaches the player as kill).
747
+ hasTranscript() {
748
+ return !this.killed && (this.recording || this.recorded || anyTranscriptStored());
749
+ },
714
750
  viewerUrl: 'TranscriptViewer/index.html',
715
751
  };
716
752
 
753
+ // v2's toolbar button for the transcript viewer, the button version of
754
+ // "view transcript" (issue #2882), shown once there's a transcript to view.
755
+ // Legacy has no such button, so this does nothing there.
756
+ function updateTranscriptsButton() {
757
+ const button = document.getElementById('cmdTranscripts');
758
+ if (button) button.style.display = transcript.hasTranscript() ? 'initial' : 'none';
759
+ }
760
+
761
+ // Called after every WebPlayer.initUI(), like wireDebuggerButton, since the
762
+ // player UI's markup is replaced on every boot and restart.
763
+ function wireTranscriptsButton() {
764
+ const button = document.getElementById('cmdTranscripts');
765
+ if (!button) return;
766
+ // Opened as "view transcript"'s link is, so Electron gives it its viewer
767
+ // window (attachTranscriptWindowHandling).
768
+ button.addEventListener('click', () => window.open(transcript.viewerUrl, '_blank', 'noopener'));
769
+ updateTranscriptsButton();
770
+ window.electronTranscripts?.any?.().then((any) => {
771
+ electronTranscriptsStored = any;
772
+ updateTranscriptsButton();
773
+ }, () => {});
774
+ }
775
+
717
776
  // The WebPlayer object — the host API that the shared playercore.js and
718
777
  // player.js call into. The name predates WasmPlayer and is kept as-is.
719
778
  window.WebPlayer = {
@@ -1082,6 +1141,9 @@ function swapInPlayerUi() {
1082
1141
  // so the Debug button's visibility stays correct after "Start from the
1083
1142
  // beginning"/Load in an editor-preview session.
1084
1143
  let currentIsPreview = false;
1144
+ // True when the game came from files the player picked (the start screen's file picker, or the
1145
+ // Play tab's): see showGameLoadError's hint about choosing a game's library files too.
1146
+ let gameFromPickedFiles = false;
1085
1147
 
1086
1148
  // Same idea as currentIsPreview, but for the source=local .aslx case (see
1087
1149
  // setCanDebug's call sites below) — kept separate from isPreview because it
@@ -1265,7 +1327,7 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1265
1327
  // A live app (Play tab / editor preview) handed this game over via bc —
1266
1328
  // it owns the file-picking UI, so don't re-offer the start-screen
1267
1329
  // pickers; just show the error, editor-style.
1268
- showGameLoadError(errors, !bc);
1330
+ showGameLoadError(errors, !bc, gameFromPickedFiles);
1269
1331
  reportProgress('failed', errors.join(' ') || 'Unknown error');
1270
1332
  return false;
1271
1333
  }
@@ -1284,6 +1346,7 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1284
1346
  await WebPlayer.initUI();
1285
1347
  wireDebuggerButton();
1286
1348
  wireDebuggerRestartButton(isPreview);
1349
+ wireTranscriptsButton();
1287
1350
  wireRecordingStopButton();
1288
1351
  // Editor-preview sessions (isPreview) don't offer saving at all — by
1289
1352
  // design: a save captures the whole game state, so reloading one while
@@ -1378,6 +1441,7 @@ async function applyInterfaceChangesCore(attributes) {
1378
1441
  playerUi.setGameName(currentGameName);
1379
1442
  wireDebuggerButton();
1380
1443
  wireDebuggerRestartButton(currentIsPreview);
1444
+ wireTranscriptsButton();
1381
1445
  WebPlayer.setCanSave(!currentIsPreview);
1382
1446
  WebPlayer.setCanDebug((currentIsPreview || currentAllowDebug) && Bridge.IsDebugEnabled());
1383
1447
  await Bridge.ReapplyInterface(html);
@@ -1486,6 +1550,7 @@ async function restartGameCore(saveBytes) {
1486
1550
  await WebPlayer.initUI();
1487
1551
  wireDebuggerButton();
1488
1552
  wireDebuggerRestartButton(currentIsPreview);
1553
+ wireTranscriptsButton();
1489
1554
  // Used to be an unconditional true — harmless while restartGame was only
1490
1555
  // ever reachable from the Saves dialog, which editor-preview sessions
1491
1556
  // never had access to in the first place (Save itself is hidden there).
@@ -1628,7 +1693,7 @@ function renderSavesList(saves, mode) {
1628
1693
  }
1629
1694
 
1630
1695
  if (!saves.length) {
1631
- list.innerHTML = mode === 'manage'
1696
+ list.innerHTML = mode === 'manage' && !document.getElementById('qv-saves').hasAttribute('data-storage-blocked')
1632
1697
  ? `<li class="qv-saves-empty text-sm text-surface-700-300">${_esc(cs.NoSavedGamesYet ?? 'No saved games yet.')}</li>`
1633
1698
  : '';
1634
1699
  return;
@@ -1846,10 +1911,29 @@ let renamingSave = null;
1846
1911
  let currentSaves = [];
1847
1912
 
1848
1913
  async function refreshSavesList(mode = 'manage') {
1849
- currentSaves = await GameSaver.listSaves(WebPlayer.gameId);
1914
+ currentSaves = await listSavesOrReportBlocked(WebPlayer.gameId);
1850
1915
  renderSavesList(currentSaves, mode);
1851
1916
  }
1852
1917
 
1918
+ // Lists the game's saves, or, when the browser won't open IndexedDB at all (a Firefox private
1919
+ // window, all site data blocked, a privacy add-on), says in the dialog that saving here isn't
1920
+ // available and hides the Save form, instead of the dialog failing to open. Save to file and Load
1921
+ // from file don't use the browser's storage, so they stay.
1922
+ async function listSavesOrReportBlocked(gameId) {
1923
+ const dlg = document.getElementById('qv-saves');
1924
+ try {
1925
+ const saves = await GameSaver.listSaves(gameId);
1926
+ delete dlg.dataset.storageBlocked;
1927
+ return saves;
1928
+ } catch (err) {
1929
+ console.warn('Saved games are unavailable:', err);
1930
+ dlg.dataset.storageBlocked = '';
1931
+ showSavesError(WebPlayer.chromeStrings?.SavingNotAvailable
1932
+ ?? "Saving here isn't available, because this browser is blocking storage (for example in a private window). You can still save to a file and load from one.");
1933
+ return [];
1934
+ }
1935
+ }
1936
+
1853
1937
  function saveTitle(slotIndex) {
1854
1938
  const save = currentSaves.find(s => s.slotIndex === slotIndex);
1855
1939
  return save ? describeSave(save).title : (WebPlayer.chromeStrings?.UnnamedSave ?? 'this save');
@@ -2113,7 +2197,7 @@ async function openSavesDialog(mode, gameId = WebPlayer.gameId) {
2113
2197
  }
2114
2198
  dlg.dataset.mode = mode;
2115
2199
  dlg.setAttribute('aria-labelledby', mode === 'boot' ? 'qv-saves-heading-boot' : 'qv-saves-heading-manage');
2116
- currentSaves = await GameSaver.listSaves(gameId);
2200
+ currentSaves = await listSavesOrReportBlocked(gameId);
2117
2201
  renderSavesList(currentSaves, mode);
2118
2202
 
2119
2203
  if (mode === 'boot') {
@@ -3033,7 +3117,7 @@ function showError(downloadUrl, isLocalFile, error) {
3033
3117
  // header+bullets format the Editor uses for a load-time error (see
3034
3118
  // EditorController.cs's "Failed to load game due to the following errors:"),
3035
3119
  // with a blank line between the header and the error message.
3036
- function showGameLoadError(errors, showPickers = true) {
3120
+ function showGameLoadError(errors, showPickers = true, fromPickedFiles = false) {
3037
3121
  document.documentElement.classList.remove('qv-booting');
3038
3122
  const pickers = document.getElementById('qv-pickers');
3039
3123
  const msg = document.getElementById('qv-loading-msg');
@@ -3042,15 +3126,25 @@ function showGameLoadError(errors, showPickers = true) {
3042
3126
  if (pickers) pickers.style.display = showPickers ? 'block' : 'none';
3043
3127
  if (!errorEl) return;
3044
3128
  const list = errors.length ? errors : ['Unknown error'];
3129
+ // A game picked from disk only brings the files the player chose, so a library it includes
3130
+ // from its own folder is missing unless it was chosen too. Say how to fix that.
3131
+ const missingLibraries = fromPickedFiles
3132
+ ? list.map(e => /Library file not found: (.+)$/.exec(e)?.[1]).filter(Boolean)
3133
+ : [];
3134
+ const libraryHint = missingLibraries.length
3135
+ ? `This game uses ${missingLibraries.join(', ')}. Open the game again, and choose `
3136
+ + `${missingLibraries.length === 1 ? 'that file' : 'those files'} too, along with the game file.`
3137
+ : null;
3045
3138
  errorEl.style.whiteSpace = showPickers ? '' : 'pre-wrap';
3046
3139
  if (showPickers) {
3047
3140
  errorEl.innerHTML = '<strong>This game couldn\'t be started.</strong> '
3048
3141
  + 'The game file loaded, but Quest Viva reported a problem with its contents:<br/>'
3049
3142
  + list.map(_esc).join('<br/>')
3050
- + '<br/>You can try a different file below.';
3143
+ + (libraryHint ? '<br/>' + _esc(libraryHint) : '<br/>You can try a different file below.');
3051
3144
  } else {
3052
3145
  errorEl.innerHTML = _esc('Failed to load game due to the following errors:\n\n'
3053
- + list.map(e => '* ' + e).join('\n'));
3146
+ + list.map(e => '* ' + e).join('\n')
3147
+ + (libraryHint ? '\n\n' + libraryHint : ''));
3054
3148
  }
3055
3149
  errorEl.style.display = 'block';
3056
3150
  wireStartScreen();
@@ -3069,6 +3163,31 @@ function setLocationParam(name, value) {
3069
3163
  history.replaceState(null, '', newUrl);
3070
3164
  }
3071
3165
 
3166
+ // An .aslx game can <include ref="..."/> a library from its own folder, and a picked file brings
3167
+ // no folder with it, so the player can choose the game together with its libraries. Of the
3168
+ // files chosen, the game is the .quest/.asl/.cas, or else the .aslx whose root element is <asl>
3169
+ // (a library's is <library>); every other .aslx is passed on as an adjacent file for
3170
+ // WorldModel.GetLibraryStream to find. Returns null when no game is among them.
3171
+ async function splitPickedGameFiles(files) {
3172
+ const read = await Promise.all(files.map(async f => ({ name: f.name, bytes: new Uint8Array(await f.arrayBuffer()) })));
3173
+ const isAslx = f => /\.aslx$/i.test(f.name);
3174
+ const game = read.find(f => /\.(quest|asl|cas)$/i.test(f.name))
3175
+ ?? read.find(f => isAslx(f) && aslxRootElement(f.bytes) === 'asl')
3176
+ ?? (read.length === 1 ? read[0] : null);
3177
+ if (!game) return null;
3178
+ const adjacentFiles = {};
3179
+ for (const f of read) {
3180
+ if (f !== game && isAslx(f)) adjacentFiles[f.name] = f.bytes;
3181
+ }
3182
+ return { bytes: game.bytes, filename: game.name, adjacentFiles };
3183
+ }
3184
+
3185
+ // The name of an XML file's root element, skipping any XML declaration and comments (TextDecoder drops a BOM).
3186
+ function aslxRootElement(bytes) {
3187
+ const text = new TextDecoder().decode(bytes.subarray(0, 4096));
3188
+ return /^\s*(?:<\?[\s\S]*?\?>\s*|<!--[\s\S]*?-->\s*)*<([A-Za-z_][\w.-]*)/.exec(text)?.[1] ?? null;
3189
+ }
3190
+
3072
3191
  let _startScreenWired = false;
3073
3192
  function wireStartScreen() {
3074
3193
  if (_startScreenWired) return;
@@ -3081,15 +3200,23 @@ function wireStartScreen() {
3081
3200
  if (!fileBtn) return;
3082
3201
 
3083
3202
  fileBtn.addEventListener('click', () => fileInput.click());
3084
- fileInput.addEventListener('change', () => {
3085
- const file = fileInput.files?.[0];
3086
- if (!file) return;
3203
+ fileInput.addEventListener('change', async () => {
3204
+ const files = [...(fileInput.files ?? [])];
3205
+ fileInput.value = '';
3206
+ if (!files.length) return;
3087
3207
  setLocationParam(null);
3088
3208
  showLoading();
3089
- const reader = new FileReader();
3090
- reader.onload = () => startGame(new Uint8Array(reader.result), file.name)
3091
- .catch(() => showError(null, true));
3092
- reader.readAsArrayBuffer(file);
3209
+ try {
3210
+ const picked = await splitPickedGameFiles(files);
3211
+ if (!picked) {
3212
+ showError(null, true);
3213
+ return;
3214
+ }
3215
+ gameFromPickedFiles = true;
3216
+ await startGame(picked.bytes, picked.filename, null, null, false, null, null, picked.adjacentFiles);
3217
+ } catch {
3218
+ showError(null, true);
3219
+ }
3093
3220
  });
3094
3221
 
3095
3222
  async function doLoadUrl() {
@@ -3217,6 +3344,7 @@ async function fetchGameBytes(url) {
3217
3344
  // play session (isPreview stays false) since a real save is
3218
3345
  // still wanted here.
3219
3346
  const allowDebug = /\.aslx$/i.test(data.filename ?? '');
3347
+ gameFromPickedFiles = !!data.picked;
3220
3348
  await startGame(data.bytes, data.filename, bc, null, false, null, null, data.adjacentFiles ?? null, allowDebug);
3221
3349
  }
3222
3350
  };