@textadventures/quest-viva-wasmplayer 6.1.2 → 6.2.0-beta.2

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 (38) hide show
  1. package/_framework/Common.wasm +0 -0
  2. package/_framework/Engine.wasm +0 -0
  3. package/_framework/ExtendedNumerics.BigDecimal.wasm +0 -0
  4. package/_framework/Legacy.wasm +0 -0
  5. package/_framework/Microsoft.Extensions.Logging.Abstractions.wasm +0 -0
  6. package/_framework/NCalc.Core.wasm +0 -0
  7. package/_framework/NCalc.Domain.wasm +0 -0
  8. package/_framework/NCalc.Parser.wasm +0 -0
  9. package/_framework/Parlot.wasm +0 -0
  10. package/_framework/PlayerCore.wasm +0 -0
  11. package/_framework/System.Collections.Immutable.wasm +0 -0
  12. package/_framework/System.Collections.wasm +0 -0
  13. package/_framework/System.Linq.wasm +0 -0
  14. package/_framework/System.Net.Http.wasm +0 -0
  15. package/_framework/System.Private.CoreLib.wasm +0 -0
  16. package/_framework/System.Private.Xml.Linq.wasm +0 -0
  17. package/_framework/System.Private.Xml.wasm +0 -0
  18. package/_framework/System.Runtime.Numerics.wasm +0 -0
  19. package/_framework/System.Text.Json.wasm +0 -0
  20. package/_framework/System.Text.RegularExpressions.wasm +0 -0
  21. package/_framework/WasmPlayer.wasm +0 -0
  22. package/_framework/dotnet.js +40 -46
  23. package/_framework/dotnet.native.wasm +0 -0
  24. package/chrome.css +1 -1
  25. package/export-manifest.json +1 -1
  26. package/game-saver.js +5 -1
  27. package/gamepad.js +668 -0
  28. package/index.html +53 -11
  29. package/legacy/adapter.js +1 -0
  30. package/legacy/grid.js +4 -0
  31. package/legacy/playercore.js +8 -1
  32. package/legacy/questui.js +5 -1
  33. package/package.json +1 -1
  34. package/v2/map.js +1 -1
  35. package/v2/v2.css +1 -1
  36. package/v2/v2.js +1 -1
  37. package/wasm-player.js +226 -21
  38. package/_framework/System.Linq.Expressions.wasm +0 -0
package/wasm-player.js CHANGED
@@ -110,6 +110,24 @@ function playBlockedMedia() {
110
110
 
111
111
  const pendingResources = new Map();
112
112
  let editorChannel = null;
113
+
114
+ // The "Show in editor" link the Editor's play-test puts after a script error
115
+ // (WasmPlayerBridge.ScriptErrorLocationHtml): the Editor selects the element
116
+ // and shows the attribute, as it does for a Check game problem.
117
+ document.addEventListener('click', (event) => {
118
+ const link = event.target instanceof Element ? event.target.closest('a.qv-show-in-editor') : null;
119
+ if (!link) return;
120
+ event.preventDefault();
121
+ if (!editorChannel) return;
122
+ editorChannel.postMessage({
123
+ type: 'show-in-editor',
124
+ element: link.dataset.element,
125
+ attribute: link.dataset.attribute ?? null,
126
+ });
127
+ // The play-test opened in its own tab: bring the Editor's back to the front, where the
128
+ // browser lets it.
129
+ try { window.opener?.focus(); } catch { /* no opener, or not allowed */ }
130
+ });
113
131
  let resourceRoot = null;
114
132
 
115
133
  // ── Walkthrough recording/playback status banner ────────────────────────────
@@ -367,6 +385,7 @@ function stageAdjacentFiles(files) {
367
385
  function ui_init() { }
368
386
 
369
387
  function sendEndWait() {
388
+ window.QuestGamepad?.endWait();
370
389
  // The short delay lets the browser paint endWait()'s hidden Continue link
371
390
  // before the engine resumes and (in the WASM build, which runs it on the
372
391
  // one UI thread) blocks painting for the rest of the turn.
@@ -790,6 +809,7 @@ window.WebPlayer = {
790
809
  },
791
810
 
792
811
  setCanSave(value) {
812
+ currentCanSave = value;
793
813
  const cmdSave = document.getElementById("cmdSave");
794
814
  if (cmdSave) cmdSave.style.display = value ? "initial" : "none";
795
815
  playerUi.setCanSave(value);
@@ -809,7 +829,6 @@ window.WebPlayer = {
809
829
  await playerTurn(() => Bridge.SendCommand(command, tickCount, metadataJson));
810
830
  canSendCommand = true;
811
831
  recordStep(command);
812
- refreshDebuggerAfterTurn();
813
832
  },
814
833
 
815
834
  async uiChoice(choice) { await playerTurn(() => Bridge.SetMenuResponse(choice)); recordStep(`menu:${choice}`); },
@@ -818,12 +837,16 @@ window.WebPlayer = {
818
837
  // A timer firing mid-change would run its script against a half-built UI.
819
838
  await interfaceChangesApplied;
820
839
  turnsInFlight++;
840
+ const errorsBefore = Bridge.GetRecentErrorCount();
821
841
  try {
822
842
  await Bridge.Tick(tickCount);
823
843
  } finally {
824
844
  turnsInFlight--;
825
845
  scheduleInterfaceChanges();
826
846
  notifyIfTurnOver();
847
+ // Only when a timer's script failed: this runs every second, and redrawing an open
848
+ // Debugger that often would lose what's being typed in its search or override box.
849
+ if (Bridge.GetRecentErrorCount() !== errorsBefore) refreshDebuggerAfterTurn();
827
850
  }
828
851
  },
829
852
  async uiEndWait() { await playerTurn(() => Bridge.FinishWait()); },
@@ -834,7 +857,6 @@ window.WebPlayer = {
834
857
  await playerTurn(() => Bridge.SendEvent(eventName, param));
835
858
  canSendCommand = true;
836
859
  recordStep(`event:${eventName};${param ?? ''}`);
837
- refreshDebuggerAfterTurn();
838
860
  },
839
861
 
840
862
  async uiSaveGame(html) {
@@ -842,12 +864,18 @@ window.WebPlayer = {
842
864
  return Bridge.GetSaveGameBytes();
843
865
  },
844
866
 
867
+ // The game's reason for refusing a save right now (game.cansave false), or null.
868
+ saveRefusal() {
869
+ return Bridge?.GetSaveRefusal?.() ?? null;
870
+ },
871
+
845
872
  };
846
873
 
847
874
  // One engine round trip started by the player, bracketed for QuestUI's turnStarted/turnEnded
848
875
  // events (legacy/questui.js).
849
876
  async function playerTurn(run) {
850
877
  window.notifyQuestUITurn?.(true);
878
+ window.QuestGamepad?.markTurnStart();
851
879
  turnsInFlight++;
852
880
  try {
853
881
  // A live interface change being applied finishes first (applyInterfaceChanges).
@@ -858,6 +886,9 @@ async function playerTurn(run) {
858
886
  window.notifyQuestUITurn?.(false);
859
887
  scheduleInterfaceChanges();
860
888
  notifyIfTurnOver();
889
+ // Every kind of turn (a command, a menu choice, the end of a wait or pause, an answer)
890
+ // can change what the Debugger shows, and above all add to its Errors tab.
891
+ refreshDebuggerAfterTurn();
861
892
  }
862
893
  }
863
894
 
@@ -866,6 +897,30 @@ async function playerTurn(run) {
866
897
  // change waits for both to be over.
867
898
  let turnsInFlight = 0;
868
899
  let turnPending = false;
900
+ let currentCanSave = false;
901
+
902
+ // A game controller (gamepad.js): what it needs of the host.
903
+ window.QuestGamepad?.attach({
904
+ sendCommand(text) {
905
+ if (typeof window.sendCommand === 'function') window.sendCommand(text);
906
+ },
907
+ commandWord(name) {
908
+ try {
909
+ return Bridge?.GetCommandWord(name) ?? '';
910
+ } catch {
911
+ return '';
912
+ }
913
+ },
914
+ outputElement: () => playerUi?.getOutputElement() ?? null,
915
+ // The controller menu's Saved games button, which works as the Save / Load button does: not
916
+ // mid-turn, and not at all where saving is turned off.
917
+ savedGames() {
918
+ if (!currentCanSave || !WebPlayer.onSaveClick) return 'off';
919
+ return turnPending || turnsInFlight > 0 ? 'busy' : 'ready';
920
+ },
921
+ openSavedGames: () => WebPlayer.onSaveClick?.(),
922
+ chromeString: (key, fallback) => WebPlayer.chromeStrings?.[key] ?? fallback,
923
+ });
869
924
 
870
925
  // Whoever is waiting for the turn to be over (whenTurnOver): a save a game's script asks for waits
871
926
  // until then, so it has the whole turn rather than however much had run when it was asked for.
@@ -988,7 +1043,7 @@ function setGameStylesheet(css) {
988
1043
  // ── Player UIs ──────────────────────────────────────────────────────────────
989
1044
  //
990
1045
  // Each player UI is a bundle of markup (swapped into the page for each game and restart),
991
- // stylesheets and classic scripts, loaded only once a game needs it: the legacy UI (today's, frozen) and v2 (docs/ui-v2-plan.md). The last script
1046
+ // stylesheets and classic scripts, loaded only once a game needs it: the legacy UI (today's, frozen) and v2 (docs/archive/ui-v2-plan.md). The last script
992
1047
  // registers the UI's adapter as window.QuestPlayerUis[name], which is the only way the host
993
1048
  // talks to it. Paths are relative to this page and get the ?v= cache key.
994
1049
  const playerUiBundles = {
@@ -1130,6 +1185,8 @@ function swapInPlayerUi() {
1130
1185
  const debuggerDialogEl = document.getElementById('questVivaDebugger');
1131
1186
  const restartingEl = document.getElementById('qv-restarting');
1132
1187
  const recordingEl = document.getElementById('qv-recording');
1188
+ const controllerEls = ['qv-controller-menu', 'qv-controller-help', 'qv-controller-toast']
1189
+ .map(id => document.getElementById(id)).filter(Boolean);
1133
1190
  startScreenEl?.remove();
1134
1191
  savesDialogEl?.remove();
1135
1192
  debuggerDialogEl?.remove();
@@ -1143,6 +1200,7 @@ function swapInPlayerUi() {
1143
1200
  if (debuggerDialogEl) document.body.appendChild(debuggerDialogEl);
1144
1201
  if (restartingEl) document.body.appendChild(restartingEl);
1145
1202
  if (recordingEl) document.body.appendChild(recordingEl);
1203
+ for (const el of controllerEls) document.body.appendChild(el);
1146
1204
  // This is a genuinely fresh chrome (see above) — addExternalScript's
1147
1205
  // dedupe-by-URL must not carry over, or the game's external
1148
1206
  // scripts silently no-op against it on the very next Initialise() call
@@ -1231,6 +1289,7 @@ function preloadRuntime() {
1231
1289
  async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null, isPreview = false, recordWalkthrough = null, runWalkthrough = null, adjacentFiles = null, allowDebug = false) {
1232
1290
  currentIsPreview = isPreview;
1233
1291
  currentAllowDebug = allowDebug;
1292
+ window.QuestGamepad?.reset();
1234
1293
  prefetchPlayerUi(playerUiOverride() ?? (isPreview ? 'v2' : 'legacy'));
1235
1294
  const builder = await loadRuntimeBuilder();
1236
1295
  const runtime = await builder.create();
@@ -1244,14 +1303,20 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1244
1303
  bindMenu: (linkId, verbs, text, elementId) => playerUi.bindMenu(linkId, verbs, text, elementId),
1245
1304
  showMenu: (caption, optionsJson, allowCancel) => playerUi.showMenu(caption, JSON.parse(optionsJson), allowCancel),
1246
1305
  showQuestion: (caption) => playerUi.showQuestion(caption),
1247
- beginWait: () => playerUi.beginWait(),
1306
+ beginWait: () => {
1307
+ window.QuestGamepad?.beginWait();
1308
+ playerUi.beginWait();
1309
+ },
1248
1310
  setTurnPending: (pending) => {
1249
1311
  turnPending = pending;
1250
1312
  playerUi.setTurnPending(pending);
1251
1313
  if (!pending) scheduleInterfaceChanges();
1252
1314
  },
1253
1315
  beginPause: (ms) => whenClockRuns(() => playerUi.beginPause(ms)),
1254
- dismissPrompt: () => playerUi.dismissPrompt(),
1316
+ dismissPrompt: () => {
1317
+ window.QuestGamepad?.endWait();
1318
+ playerUi.dismissPrompt();
1319
+ },
1255
1320
  updateLocation: (loc) => playerUi.updateLocation(loc),
1256
1321
  setGameName: (name) => {
1257
1322
  currentGameName = name;
@@ -1264,7 +1329,10 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1264
1329
  setBackground: (colour) => playerUi.setBackground(colour),
1265
1330
  setForeground: (colour) => playerUi.setForeground(colour),
1266
1331
  updateList: (listName, itemsJson) => playerUi.updateList(listName, JSON.parse(itemsJson)),
1267
- updateCompass: (data) => playerUi.updateCompass(data),
1332
+ updateCompass: (data) => {
1333
+ window.QuestGamepad?.updateCompass(data);
1334
+ playerUi.updateCompass(data);
1335
+ },
1268
1336
  updateObjectLinks: (verbsJson) => playerUi.updateObjectLinks(JSON.parse(verbsJson)),
1269
1337
  gameFinished: () => playerUi.gameFinished(),
1270
1338
  requestNextTimerTick: (seconds) => whenClockRuns(() => playerUi.requestNextTimerTick(seconds)),
@@ -1285,7 +1353,11 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1285
1353
  try { globalEval(call); } catch (e) { console.error(e); }
1286
1354
  },
1287
1355
  jsYield: () => new Promise(resolve => setTimeout(resolve, 0)),
1288
- setCompassDirections: (dirsJson) => playerUi.setCompassDirections(JSON.parse(dirsJson)),
1356
+ setCompassDirections: (dirsJson) => {
1357
+ const directions = JSON.parse(dirsJson);
1358
+ window.QuestGamepad?.setCompassDirections(directions);
1359
+ playerUi.setCompassDirections(directions);
1360
+ },
1289
1361
  setInterfaceString: (name, text) => playerUi.setInterfaceString(name, text),
1290
1362
  setPanelContents: (html) => playerUi.setPanelContents(html),
1291
1363
  consoleError: (msg) => console.error('[Quest]', msg),
@@ -1306,6 +1378,7 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1306
1378
  const seed = Number.parseInt(testParams.get('seed') ?? '', 10);
1307
1379
  if (Number.isInteger(seed)) Bridge.SetRandomSeed(seed);
1308
1380
  if (testParams.has('transcript')) Bridge.StartTranscriptCapture();
1381
+ if (isPreview) Bridge.SetEditorPlayTest();
1309
1382
  manualClock = testParams.get('clock') === 'manual';
1310
1383
  window.QuestVivaTest = {
1311
1384
  takeTranscript: () => JSON.parse(Bridge.TakeTranscriptJson()),
@@ -1376,11 +1449,11 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1376
1449
  // BroadcastChannel (to hand off the picked file's bytes and answer
1377
1450
  // resource requests) but is a real play session and should offer saving.
1378
1451
  WebPlayer.setCanSave(!isPreview);
1379
- // Shown in editor-preview sessions, and also in a source=local play
1380
- // session for a raw .aslx file specifically (allowDebug — see the
1381
- // source=local boot branch below, which is the only caller that ever
1382
- // passes it true) — never for any other normal play session, even
1383
- // though the loaded game itself might have DebugEnabled true.
1452
+ // Shown in editor-preview sessions, and also in a play session for a raw
1453
+ // .aslx file specifically (allowDebug — passed by the source=local,
1454
+ // source=qv and ?url= boot branches below) — never for any other normal
1455
+ // play session, even though the loaded game itself might have
1456
+ // DebugEnabled true.
1384
1457
  WebPlayer.setCanDebug((isPreview || allowDebug) && Bridge.IsDebugEnabled());
1385
1458
 
1386
1459
  // The game's start runs behind the start screen, so a sound it plays can wait for a click
@@ -1582,6 +1655,8 @@ async function restartGameCore(saveBytes) {
1582
1655
  WebPlayer.setCanSave(!currentIsPreview);
1583
1656
  WebPlayer.setCanDebug((currentIsPreview || currentAllowDebug) && Bridge.IsDebugEnabled());
1584
1657
  await Bridge.Begin();
1658
+ // An open Debugger would otherwise show the old session until the next turn.
1659
+ refreshDebuggerAfterTurn();
1585
1660
  } finally {
1586
1661
  restartingEl?.classList.add('hidden');
1587
1662
  }
@@ -1933,10 +2008,27 @@ let renamingSave = null;
1933
2008
  let currentSaves = [];
1934
2009
 
1935
2010
  async function refreshSavesList(mode = 'manage') {
2011
+ updateSaveRefusal();
1936
2012
  currentSaves = await listSavesOrReportBlocked(WebPlayer.gameId);
1937
2013
  renderSavesList(currentSaves, mode);
1938
2014
  }
1939
2015
 
2016
+ // A game can refuse saves for a while (game.cansave false), for example while the player is in a
2017
+ // dungeon. The dialog then hides what would make a new save and says why, but loading stays (#3026).
2018
+ // Returns whether saving is refused.
2019
+ function updateSaveRefusal() {
2020
+ const dlg = document.getElementById('qv-saves');
2021
+ const refusal = WebPlayer.saveRefusal();
2022
+ const notice = document.getElementById('qv-saves-refused');
2023
+ if (refusal) {
2024
+ dlg.dataset.saveRefused = '';
2025
+ if (notice) notice.textContent = refusal;
2026
+ } else {
2027
+ delete dlg.dataset.saveRefused;
2028
+ }
2029
+ return !!refusal;
2030
+ }
2031
+
1940
2032
  // Lists the game's saves, or, when the browser won't open IndexedDB at all (a Firefox private
1941
2033
  // window, all site data blocked, a privacy add-on), says in the dialog that saving here isn't
1942
2034
  // available and hides the Save form, instead of the dialog failing to open. Save to file and Load
@@ -1979,6 +2071,7 @@ function downloadSaveBytes(bytes) {
1979
2071
  }
1980
2072
 
1981
2073
  async function downloadSaveToFile() {
2074
+ if (updateSaveRefusal()) return;
1982
2075
  const bytes = await WebPlayer.uiSaveGame(GameSaver.outputHtmlForSave());
1983
2076
  downloadSaveBytes(bytes);
1984
2077
  playerUi.clearUnsavedProgress();
@@ -2089,7 +2182,7 @@ function ensureSavesDialogWired() {
2089
2182
  (cs().OverwriteSaveConfirm ?? 'Overwrite "[name]"?').replace('[name]', saveTitle(slotIndex)),
2090
2183
  cs().OverwriteSave ?? 'Overwrite');
2091
2184
  if (!ok) { opener?.focus(); return; }
2092
- await GameSaver.overwrite(slotIndex);
2185
+ if (!await GameSaver.overwrite(slotIndex)) { await refreshSavesList(); return; }
2093
2186
  await refreshSavesList();
2094
2187
  document.querySelector(`#qv-saves-list [data-slot="${slotIndex}"]`)?.focus();
2095
2188
  } else if (action === 'rename') {
@@ -2136,10 +2229,12 @@ function ensureSavesDialogWired() {
2136
2229
  e.preventDefault();
2137
2230
  const input = document.getElementById('qv-saves-name-input');
2138
2231
  const button = document.getElementById('qv-saves-save-new');
2232
+ let saved = null;
2139
2233
  await withBusyButton(button, cs().SavingBusy ?? 'Saving…', async () => {
2140
- await GameSaver.save(input.value.trim() || undefined);
2234
+ saved = await GameSaver.save(input.value.trim() || undefined);
2141
2235
  });
2142
- input.value = '';
2236
+ // Not saved: the game started refusing saves while the dialog was open.
2237
+ if (saved) input.value = '';
2143
2238
  await refreshSavesList();
2144
2239
  });
2145
2240
 
@@ -2218,6 +2313,7 @@ async function openSavesDialog(mode, gameId = WebPlayer.gameId) {
2218
2313
  saveMenu.hidePopover();
2219
2314
  }
2220
2315
  dlg.dataset.mode = mode;
2316
+ updateSaveRefusal();
2221
2317
  dlg.setAttribute('aria-labelledby', mode === 'boot' ? 'qv-saves-heading-boot' : 'qv-saves-heading-manage');
2222
2318
  currentSaves = await listSavesOrReportBlocked(gameId);
2223
2319
  renderSavesList(currentSaves, mode);
@@ -2512,12 +2608,57 @@ function wireDebuggerColumnResize(startEvent) {
2512
2608
  // renderDebuggerOverridePanel).
2513
2609
  const DEBUGGER_OVERRIDE_HINT = 'Edit and Apply to change this value for the rest of the session';
2514
2610
 
2611
+ // The Errors tab lists the script errors printed this session (#2335), from
2612
+ // WasmPlayerBridge.GetRecentErrorsJson: { Total, Errors } with Errors oldest
2613
+ // first, each a RuntimeError (Message, Element, Attribute, Object, Filename,
2614
+ // Statement; only Message for an error outside a script, such as one from
2615
+ // handling a command). It has no object list, so it takes the whole width.
2616
+ const DEBUGGER_ERRORS_TAB = 'Errors';
2617
+
2515
2618
  function renderDebuggerTabs(types) {
2516
2619
  const tabs = document.getElementById('qv-debugger-tabs');
2517
- const allTabs = ['Walkthrough', ...types];
2518
- tabs.innerHTML = allTabs.map(tab =>
2519
- `<button type="button" class="btn btn-sm ${tab === debuggerActiveTab ? 'preset-filled-primary-700-300' : 'preset-tonal-surface'}" data-tab="${_esc(tab)}">${_esc(tab)}</button>`
2520
- ).join('');
2620
+ const allTabs = ['Walkthrough', DEBUGGER_ERRORS_TAB, ...types];
2621
+ const errorCount = Bridge.GetRecentErrorCount();
2622
+ tabs.innerHTML = allTabs.map(tab => {
2623
+ const label = tab === DEBUGGER_ERRORS_TAB && errorCount ? `${tab} (${errorCount})` : tab;
2624
+ return `<button type="button" class="btn btn-sm ${tab === debuggerActiveTab ? 'preset-filled-primary-700-300' : 'preset-tonal-surface'}" data-tab="${_esc(tab)}">${_esc(label)}</button>`;
2625
+ }).join('');
2626
+ }
2627
+
2628
+ // Newest first. In the Editor's play-test (editorChannel is set), each error
2629
+ // with a known element gets the same "Show in editor" link the play-test
2630
+ // prints after the error itself; the document click handler near the top of
2631
+ // this file sends it to the Editor.
2632
+ function renderDebuggerErrorsDetail() {
2633
+ const detail = document.getElementById('qv-debugger-detail');
2634
+ const { Total: total, Errors: errors } = JSON.parse(Bridge.GetRecentErrorsJson());
2635
+ if (!errors.length) {
2636
+ detail.innerHTML = '<p class="text-surface-700-300">No script errors so far.</p>';
2637
+ return;
2638
+ }
2639
+
2640
+ const rows = errors.slice().reverse().map(error => {
2641
+ let where = '';
2642
+ if (error.Element) {
2643
+ where = `In <b>${_esc(error.Attribute ? `${error.Element} › ${error.Attribute}` : error.Element)}</b>`;
2644
+ if (error.Object) where += ` (for ${_esc(error.Object)})`;
2645
+ if (error.Filename) where += ` in ${_esc(error.Filename)}`;
2646
+ if (editorChannel) {
2647
+ where += ` · <a href="#" class="qv-show-in-editor" data-element="${_esc(error.Element)}"`
2648
+ + (error.Attribute ? ` data-attribute="${_esc(error.Attribute)}"` : '')
2649
+ + '>Show in editor</a>';
2650
+ }
2651
+ }
2652
+ return '<li class="qv-debugger-error">'
2653
+ + `<div class="qv-debugger-error-message">${_esc(error.Message)}</div>`
2654
+ + (where ? `<div class="qv-debugger-error-where">${where}</div>` : '')
2655
+ + (error.Statement ? `<div class="qv-debugger-error-statement">at: <code>${_esc(error.Statement)}</code></div>` : '')
2656
+ + '</li>';
2657
+ }).join('');
2658
+ const note = total > errors.length
2659
+ ? `<p class="text-xs text-surface-700-300 mb-2">Showing the last ${errors.length} of ${total} errors.</p>`
2660
+ : '';
2661
+ detail.innerHTML = `<div class="qv-debugger-scroll">${note}<ol class="qv-debugger-errors">${rows}</ol></div>`;
2521
2662
  }
2522
2663
 
2523
2664
  // Returns the rendered items — refreshDebuggerAfterTurn uses this to notice
@@ -2528,6 +2669,13 @@ function renderDebuggerList() {
2528
2669
  const sortLabel = document.querySelector('#qv-debugger-list-sort .qv-debugger-sort-label');
2529
2670
  if (sortLabel) sortLabel.textContent = 'Name' + (debuggerListSortAscending ? ' ▲' : ' ▼');
2530
2671
 
2672
+ const errorsView = debuggerActiveTab === DEBUGGER_ERRORS_TAB;
2673
+ document.getElementById('qv-debugger-panes').classList.toggle('qv-debugger-errors-view', errorsView);
2674
+ if (errorsView) {
2675
+ list.innerHTML = '';
2676
+ return [];
2677
+ }
2678
+
2531
2679
  const items = debuggerActiveTab === 'Walkthrough'
2532
2680
  ? JSON.parse(Bridge.GetWalkthroughNamesJson())
2533
2681
  : JSON.parse(Bridge.GetDebugObjectsJson(debuggerActiveTab));
@@ -2724,6 +2872,11 @@ function renderDebuggerOverridePanel(attr, item) {
2724
2872
 
2725
2873
  function renderDebuggerDetail() {
2726
2874
  const detail = document.getElementById('qv-debugger-detail');
2875
+ if (debuggerActiveTab === DEBUGGER_ERRORS_TAB) {
2876
+ renderDebuggerErrorsDetail();
2877
+ return;
2878
+ }
2879
+
2727
2880
  if (!debuggerSelectedItem) {
2728
2881
  detail.innerHTML = '<p class="text-surface-700-300">Select an item to view details.</p>';
2729
2882
  return;
@@ -2736,7 +2889,8 @@ function renderDebuggerDetail() {
2736
2889
  }
2737
2890
  }
2738
2891
 
2739
- // Called after every turn (WebPlayer.sendCommand/uiSendEvent below) now that
2892
+ // Called after every turn (playerTurn, and a timer tick that reported an
2893
+ // error), and after a restart, now that
2740
2894
  // the dialog is non-modal and can be left open while playing (see
2741
2895
  // wireDebuggerButton's doc comment) — without this, it only ever reflected
2742
2896
  // whatever the game's state was at the moment an object/tab was last
@@ -3028,6 +3182,39 @@ function showFileProtocolError() {
3028
3182
  errorEl.style.display = 'block';
3029
3183
  }
3030
3184
 
3185
+ // The .NET runtime this player is built on can't start in Safari 17 or older, on Mac or iOS:
3186
+ // JavaScriptCore there fails to parse its scripts, and the load mostly hangs with nothing shown
3187
+ // (#3153). Every browser on iOS is WebKit underneath, so there the iOS version is what counts;
3188
+ // on a Mac it's Safari's own version (Chrome, Edge and Firefox bring their own engines). Returns
3189
+ // a short name for the browser, such as "Safari 17" or "iOS 16", or null when it's fine.
3190
+ function unsupportedWebKit(ua = navigator.userAgent) {
3191
+ const ios = /(?:iPhone|iPad|iPod).* OS (\d+)_/.exec(ua);
3192
+ if (ios) return Number(ios[1]) < 18 ? `iOS ${ios[1]}` : null;
3193
+ // A Mac, or an iPad asking for desktop sites, which reports Safari's version the same way.
3194
+ if (!ua.includes('Macintosh') || /Chrome|Chromium|CriOS|FxiOS|Firefox|Edg|Electron/.test(ua)) return null;
3195
+ const safari = /Version\/(\d+)[.\d]* (?:Mobile\/\S+ )?Safari\//.exec(ua);
3196
+ return safari && Number(safari[1]) < 18 ? `Safari ${safari[1]}` : null;
3197
+ }
3198
+
3199
+ function showUnsupportedBrowserError() {
3200
+ document.documentElement.classList.remove('qv-booting');
3201
+ const pickers = document.getElementById('qv-pickers');
3202
+ const msg = document.getElementById('qv-loading-msg');
3203
+ const errorEl = document.getElementById('qv-error');
3204
+ if (msg) msg.style.display = 'none';
3205
+ if (pickers) pickers.style.display = 'none';
3206
+ if (!errorEl) return;
3207
+ const isIos = /iPhone|iPad|iPod/.test(navigator.userAgent)
3208
+ || (navigator.userAgent.includes('Macintosh') && navigator.maxTouchPoints > 1);
3209
+ errorEl.innerHTML = '<strong>This browser is too old to play Quest games.</strong> '
3210
+ + (isIos
3211
+ ? 'Please update your iPhone or iPad to iOS 18 or later (in Settings, General, Software Update), '
3212
+ : 'Please update Safari to version 18 or later (macOS updates it through System Settings, '
3213
+ + 'General, Software Update), or use another browser such as Chrome, Edge or Firefox, ')
3214
+ + 'then open this page again.';
3215
+ errorEl.style.display = 'block';
3216
+ }
3217
+
3031
3218
  // The AppShell tab that was going to hand over game bytes (see the
3032
3219
  // `source=local` boot branch below) turned out not to be there to answer —
3033
3220
  // closed, navigated away, or superseded by a newer Start click in that same
@@ -3294,6 +3481,21 @@ async function fetchGameBytes(url) {
3294
3481
  return;
3295
3482
  }
3296
3483
 
3484
+ // Before anything starts downloading: the runtime won't start here anyway. For a game from
3485
+ // textadventures.co.uk, still report it as failed, so these loads show up in its data.
3486
+ const unsupported = unsupportedWebKit();
3487
+ if (unsupported) {
3488
+ const id = new URLSearchParams(window.location.search).get('id');
3489
+ if (id) {
3490
+ const apiRoot = window.QuestVivaConfig?.textAdventuresApiRoot
3491
+ ?? 'https://textadventures.co.uk/api/';
3492
+ progressUrl = `${apiRoot}gameprogress/${encodeURIComponent(id)}`;
3493
+ reportProgress('failed', `Unsupported browser: ${unsupported}`);
3494
+ }
3495
+ document.addEventListener('DOMContentLoaded', showUnsupportedBrowserError);
3496
+ return;
3497
+ }
3498
+
3297
3499
  // Single-file export (see PlayerExport in src/PlayerCore): the game bytes are
3298
3500
  // inlined as base64 by a <script> tag before this one, so there's nothing
3299
3501
  // to fetch at all — decode and hand straight to the same startGame() every
@@ -3471,7 +3673,10 @@ async function fetchGameBytes(url) {
3471
3673
  showLoading();
3472
3674
  try {
3473
3675
  const { bytes, filename } = await gamePromise;
3474
- await startGame(bytes, filename);
3676
+ // An .aslx is an author's source file, so Debug is on for it as for source=local
3677
+ // and source=qv; a published .quest, .asl or .cas gets none.
3678
+ await startGame(bytes, filename, null, null, false, null, null, null,
3679
+ /\.aslx$/i.test(filename));
3475
3680
  } catch (err) {
3476
3681
  showError(gameUrl, false, err);
3477
3682
  }