Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
de18731
Ensure logic loading works with Windows line endings and end-of-file …
tanjo3 Aug 25, 2026
87d865b
Keep track of which version's logic actually loaded
tanjo3 Aug 28, 2026
8d51a68
Show a warning banner when the tracker had to use backup logic files
tanjo3 Aug 31, 2026
59cebc7
Handle a failed settings-string decode with a clear error instead of …
tanjo3 Aug 31, 2026
979d84a
Report broken location rules instead of lumping them in with unknown …
tanjo3 Sep 1, 2026
ac79d7d
Refuse to start check tracking without a settings string
tanjo3 Sep 1, 2026
3db00c4
Don't crash when a settings response has no starting items
tanjo3 Sep 1, 2026
d0f076d
Give up on stalled logic downloads after 30 seconds
tanjo3 Sep 1, 2026
b08041f
Be clear when logic can't be read, and address a few edge cases
tanjo3 Sep 2, 2026
e288075
Keep the logic warning from covering up the tracker
tanjo3 Sep 2, 2026
ecfb60e
Explain what a missing boulder table means
tanjo3 Sep 2, 2026
059acdc
Warn when some checks can't be shown
tanjo3 Sep 2, 2026
87babff
Center the warning banner's close button
tanjo3 Sep 6, 2026
b72d9fc
Count hidden checks correctly
tanjo3 Sep 6, 2026
8c35fce
Fail fast without a settings string
tanjo3 Sep 6, 2026
048019f
Don't mistake a closed window for a timeout
tanjo3 Sep 6, 2026
110ea9c
Fix comment
tanjo3 Sep 6, 2026
8723f28
Load the right logic for upstream dev versions
tanjo3 Sep 8, 2026
27c2d91
Accept the generator version the way seed pages write it
tanjo3 Sep 9, 2026
7626d34
Offer popular dev branches in the version dropdown
tanjo3 Sep 9, 2026
5ae83f3
Clarify where to find the generator version
tanjo3 Sep 9, 2026
d866ba2
Use friendly names for presets
tanjo3 Sep 9, 2026
5c5b351
Load the logic from the exact build specified
tanjo3 Sep 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/components/LogicSourceWarning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useState } from "react";

import Alert from "react-bootstrap/Alert";

/**
* Warns when the logic in use may not match the generator version the player asked for.
*
* It stays silent in normal cases and only appears when availability might be wrong.
* @param {object} props - Component props.
* @param {object|null} props.meta - The `logicMeta` reported by useLogicInitialization.
* @returns {object|null} A dismissible warning element, or null when the logic is trustworthy.
*/
const LogicSourceWarning = ({ meta }) => {
const [dismissed, setDismissed] = useState(false);

if (!meta || dismissed) { return null; }

const hasWarnings = meta.warnings?.length > 0;
if (!meta.usedFallback && !hasWarnings) { return null; }

const headline = meta.usedFallback
? `Logic for version ${meta.requestedVersion} could not be loaded. Using the built-in ${meta.resolvedVersion} logic instead.`
: "The logic in use may not match your seed.";

return (
<Alert
variant="warning"
dismissible
onClose={() => setDismissed(true)}
className="logic-source-warning py-2 small mb-0"
>
<strong>{headline}</strong> The checks shown as available may be incorrect for your seed.{" "}
<details className="d-inline-block">
<summary className="d-inline text-decoration-underline" style={{ cursor: "pointer" }}>Details</summary>
<ul className="mb-0 mt-1 ps-3">
{meta.usedFallback && meta.reason && <li>{meta.reason}</li>}
{hasWarnings && meta.warnings.map(warning => <li key={warning}>{warning}</li>)}
</ul>
</details>
</Alert>
);
};

export default LogicSourceWarning;
13 changes: 9 additions & 4 deletions src/context/trackerContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Locations from "../utils/locations";
import LogicHelper from "../utils/logic-helper";
import { readJSON, writeString } from "../utils/safe-storage";
import SettingsHelper from "../utils/settings-helper";
import VersionConfig from "../versions/version-config";

const GENERATOR_VERSION = process.env.REACT_APP_GENERATOR_VERSION;

Expand Down Expand Up @@ -117,16 +118,16 @@ function setSettingsStringCache(string) {
}

/**
* Retrieves the cached generator version from localStorage.
* @returns {string} The cached version, or the default from env.
* Retrieves the cached generator version from localStorage, in the form the generator reports.
* @returns {string} The normalized cached version, or the default from env.
*/
function getGeneratorVersionCache() {
let version = localStorage.getItem("generator_version");
if (!version) {
// Coming from .env and using it as default
version = GENERATOR_VERSION;
}
return version;
return VersionConfig.normalizeVersion(version);
}

/**
Expand Down Expand Up @@ -442,7 +443,11 @@ function reducer(state, action) {
}
case "ITEMS_UPDATE_FROM_LOGIC": {
const settings = payload;
const items = [...settings.starting_equipment, ...settings.starting_inventory, ...settings.starting_songs];
const items = [
...(settings.starting_equipment ?? []),
...(settings.starting_inventory ?? []),
...(settings.starting_songs ?? []),
];

const starting_inventory = items.map(item => {
return ITEMS_JSON[item];
Expand Down
24 changes: 19 additions & 5 deletions src/data/setting-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
"9.1.0",
"8.3.0"
],
"supportedDevBranches": [
{
"label": "Dev",
"value": "dev_"
},
{
"label": "Dev-Rob",
"value": "devrreal_"
},
{
"label": "Dev-Fenhl",
"value": "devFenhl_"
}
],
"presets": [
{
"label": "Mentor 2026",
Expand All @@ -29,28 +43,28 @@
{
"label": "SAWS Beginner",
"value": "saws_beginner",
"generatorVersion": "devFenhl_9.1.10-6",
"generatorVersion": "Dev-Fenhl v9.1.10-6",
"settingsString": "EACWQSKAWCBDDSSLENNAUBXJ22A6NW8FAAASAASAASLRDA2V59DA3RQDAAAAEAEDJCASAADASASCANA2BAJAEBAFAYAADAPA2BSHAABJEAUANCALALBSFAZAADSNAWB2GARCALSJBJFSXAZCJMAZBWH28A6DWRA9B6J2DBSEEUSQC6KASBTJWEBVEAWJSCFL2JTDFSWJUCLLNKBGF4WSVCRLETBFGY2ADDPN2TTHGA5JNDUPNYB4G26JVDQQ63TJHE72WDWRW8B5HQ9JFE5SSDUQJ6B3UENUWKCSKCGT2E9VASUALGJKBFGW2UUMLSKTMFSXEYU6MJSKBGT2NCDLNLTTFGZ2ADD8N4VTRG93AJVAPJ5KPHY76YD6QJA4CJNAXBEHS8ACEJTAKCWKSJBLFJYA7CENSAGL2JCDPNEUTLGU3JHDBPWWTWG44JNDBZW6UWM4QK6FXZE9U8MCSKBGK2WBVJNLTKGGKJXBXJWLTLGL7JFEXUWUULMLTKXF22AMDNQS7BGJ2CBVENVSTCYL2NB5FN2SFDGP2YBDHN7X3ZY94ANMSPCYP2YH5APMWPUYP4GL5LPVXPZYB5YS5EQ52PRZ7LHN7UXMZQL6PTHG842VDRR6BUZJ8E35ERW6XUHM8Q3DGR36KVZP823MHR867VHP9Y7DZR7835ZR9A8M2RC9P6HU9L8V3RH9B7ZDBBAJAESB2AP2DAUA3KRUXA2ALUK7NBAAAAA22BCCA2EJ69W7ASATBUGAQAQASAGDBUTNJ",
"description": "The official settings for SAWS Beginner."
},
{
"label": "Bingo",
"value": "bingo",
"generatorVersion": "devFenhl_9.1.10-6",
"generatorVersion": "Dev-Fenhl v9.1.10-6",
"settingsString": "EACSQSKAWCBDDSW4BNNACEXJ22AWAJAEAAASAAAAAWCDCA2DA2CAAEANYKJASCAAULB6W2VC6SAAAB2KANAFJKGXVFAAAAAAASB4ZGEUA6BAJ2AKT3BLCSHSH3BCACWJGUBA",
"description": "The official settings for Bingo."
},
{
"label": "Ice%",
"value": "ice_percent",
"generatorVersion": "devFenhl_9.1.10-6",
"generatorVersion": "Dev-Fenhl v9.1.10-6",
"settingsString": "EACJAAAAWCBDDSW4ANNACAXJ22AWAJPJSAAAAEAAAAAX2SAA8AASK7CAAEANUJJAACACCCXC2KTHFAASAGADWBRAJCEH7KYCADJBLUK7NBAAAAAAAES8WBTAAHCACEGJLNQA6FAQUDEAEJSNEDC",
"description": "The official settings for Ice%."
},
{
"label": "Slugs Triforce Hunt",
"value": "slugs_triforce_hunt",
"generatorVersion": "devFenhl_9.1.10-6",
"generatorVersion": "Dev-Fenhl v9.1.10-6",
"settingsString": "EAC2VSQAWCBDDSSLENNACUXJ22A6AWAEAAASAAEAAECDCA2VCAGXMAAUASKCBBALASJA2KTHFAASAGADWBRAJSD8EJQ4VNFAGSCWEV43CAAAAAST5HCJ9YSAGSHDABA8AAEHJAJTA3JGJ",
"description": "The official settings for Slugs Triforce Hunt."
},
Expand All @@ -71,7 +85,7 @@
{
"label": "Escape From Kak",
"value": "escape_from_kak",
"generatorVersion": "devTFBlitz_9.1.9-115",
"generatorVersion": "Dev-TFBlitz v9.1.9-115",
"settingsString": "BSAZASAALTDDSLFQNACAAASWCHGADSFCAAABAAAAS3EASHFANLZS9DBA3GBBALAABLASCSLBNW2UCNLWKBHF8W2VPBZBASAJADSB4SHAEC4VAXMFSC6AHKXUYAAAJYAA3UMAFAACAR4S25A8LAENSW26AFBJ9A3BEAWJSNEDC",
"description": "The settings for Escape from Kak."
}
Expand Down
173 changes: 153 additions & 20 deletions src/hooks/useLogicInitialization.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";

import { getGeneratorVersionCache, getSettingsStringCache, useItems } from "../context/trackerContext";
import { setTooltipWarmingEnabled, warmRequirementsCache } from "../utils/expression-converter";
Expand All @@ -7,46 +7,171 @@ import LogicHelper from "../utils/logic-helper";
import LogicLoader from "../utils/logic-loader";
import SettingsHelper from "../utils/settings-helper";

const SETTINGS_DECODE_TIMEOUT_MS = 10000;
const LOGIC_FILES_TIMEOUT_MS = 30000;

// SettingsHelper builds Sets from the first group, and the items reducer spreads the starting-item lists,
// so a non-list value in any of these would throw far away from the response that caused it.
const LIST_SETTINGS = [
"mq_dungeons_specific",
"dungeon_shortcuts",
"allowed_tricks",
"advanced_allowed_tricks",
"adult_trade_start",
"shuffle_child_trade",
"disabled_locations",
"starting_equipment",
"starting_inventory",
"starting_songs",
];

const CHECK_STRING_HINT = "Check the settings string and generator version, then try again.";

/**
* Check that a decoded-settings response looks like settings before it reaches the logic.
* Unknown keys remain allowed on purpose: forks add settings this tracker has never seen.
* @param {unknown} settings - The `settings` field of the API response.
* @returns {object} The validated settings object.
* @throws {Error} When the response is not a usable settings object.
*/
const validateDecodedSettings = settings => {
if (typeof settings !== "object" || settings === null || Array.isArray(settings)) {
throw new Error(`The settings service returned an unexpected response. ${CHECK_STRING_HINT}`);
}

const badLists = LIST_SETTINGS.filter(key => key in settings && !Array.isArray(settings[key]));
if (badLists.length) {
throw new Error(`The decoded settings look corrupted (${badLists.join(", ")} should be lists). ${CHECK_STRING_HINT}`);
}

if ("bridge" in settings && typeof settings.bridge !== "string") {
throw new Error(`The decoded settings look corrupted (bridge should be text). ${CHECK_STRING_HINT}`);
}

return settings;
};

/**
* Decode a settings string through the companion API, failing loudly on anything unusable.
*
* Every failure throws instead of returning undefined.
* This prevents a session from running on silently applied default settings.
* @param {string} generatorVersion - Generator version the string was made with.
* @param {string} settingsString - The settings string to decode.
* @param {AbortSignal} signal - Abort signal for timeout/unmount cancellation.
* @returns {Promise<object>} The decoded settings.
* @throws {Error} When the service is unreachable, errors, or returns a malformed body.
*/
const fetchDecodedSettings = async (generatorVersion, settingsString, signal) => {
const url =
`${process.env.REACT_APP_API_URL}/settings/string?` +
new URLSearchParams({
version: generatorVersion,
settingsString: settingsString,
});

let response;
try {
response = await fetch(url, { signal });
} catch (err) {
if (err?.name === "AbortError") {
throw new Error("The settings service did not respond in time. Check your connection and try again.");
}
throw new Error("Could not reach the settings service. Check your connection and try again.");
}

if (!response.ok) {
throw new Error(`Could not decode the settings string (the service responded with status ${response.status}). ${CHECK_STRING_HINT}`);
}

let body;
try {
body = await response.json();
} catch (err) {
if (err?.name === "AbortError") {
throw new Error("The settings service did not respond in time. Check your connection and try again.");
}
throw new Error("The settings service returned an unreadable response. Try again in a moment.");
}

return validateDecodedSettings(body?.settings);
};

const useLogicInitialization = (options = {}) => {
const { skip = false, warmTooltips = false } = options;
const [isLoading, setIsLoading] = useState(!skip);
const [error, setError] = useState(null);
const [isInitialized, setIsInitialized] = useState(false);
// Where the logic files came from (requested vs. resolved version, fallback reason, warnings)
const [logicMeta, setLogicMeta] = useState(null);
const { updateItemsFromLogic } = useItems();

// Bumped by every (re)initialization and unmount.
// This prevents an abandoned run's late responses from overwriting the state of a newer one.
const generationRef = useRef(0);
const abortRef = useRef(null);

const initializeLogic = useCallback(async () => {
if (skip) { return; }

generationRef.current += 1;
const generation = generationRef.current;
const isStale = () => generationRef.current !== generation;

abortRef.current?.abort("cancelled");
const withDeadline = async (ms, run) => {
const controller = new AbortController();
abortRef.current = controller;
const timer = setTimeout(() => controller.abort("timeout"), ms);
try {
return await run(controller.signal);
} finally {
clearTimeout(timer);
}
};

try {
setIsLoading(true);
setError(null);
setIsInitialized(false);
setLogicMeta(null);

const generatorVersion = getGeneratorVersionCache();
const settingsString = getSettingsStringCache();

if (!settingsString) {
throw new Error(
"No settings string was provided. Launch the tracker from the main page with a settings string or preset.",
);
}

// Load logic files for the specific generator version
const bundle = await LogicLoader.loadLogicFiles(generatorVersion, settingsString);
const { files: bundle, meta } = await withDeadline(LOGIC_FILES_TIMEOUT_MS, signal =>
LogicLoader.loadLogicFiles(generatorVersion, settingsString, { signal }),
);
if (isStale()) { return; }
const { logicHelpersFile, locationTable, boulderTable, dungeonFiles, dungeonMQFiles, bossesFile, overworldFile } =
bundle;

// Initialize SettingsHelper with version-specific defaults
SettingsHelper.initialize(bundle);

Locations.initialize(dungeonFiles, dungeonMQFiles, bossesFile, overworldFile, locationTable);

let settings;
if (!settingsString) {
settings = bundle.settingsDefaults;
} else {
const response = await fetch(
`${process.env.REACT_APP_API_URL}/settings/string?` +
new URLSearchParams({
version: generatorVersion,
settingsString: settingsString,
}),
).then(res => res.json());
settings = response.settings;
}
// Locations with unparseable rules are left out of the tracker
const hiddenChecks = Locations.hiddenCheckNames.size;
const warnings = hiddenChecks
? [
...meta.warnings,
`${hiddenChecks} check${hiddenChecks === 1 ? "" : "s"} could not be understood and will not be shown. ` +
"See the browser console for details.",
]
: meta.warnings;
setLogicMeta({ ...meta, warnings });

const settings = await withDeadline(SETTINGS_DECODE_TIMEOUT_MS, signal =>
fetchDecodedSettings(generatorVersion, settingsString, signal),
);
if (isStale()) { return; }

// Apply defaults and old-name transformations first so LogicHelper sees normalized settings
SettingsHelper.setSettings(settings);
Expand All @@ -61,19 +186,27 @@ const useLogicInitialization = (options = {}) => {

// Pre-build tooltip region caches, but only for scenes that show tooltips.
setTooltipWarmingEnabled(warmTooltips);
setTimeout(warmRequirementsCache, 0);
setTimeout(() => {
if (!isStale()) { warmRequirementsCache(); }
}, 0);
} catch (err) {
setError(err);
if (!isStale()) { setError(err); }
} finally {
setIsLoading(false);
if (!isStale()) { setIsLoading(false); }
}
}, [skip, warmTooltips, updateItemsFromLogic]);

useEffect(() => {
initializeLogic();

return () => {
// Stop an in-flight run from touching state (or the network) after unmount.
generationRef.current += 1;
abortRef.current?.abort("cancelled");
};
}, [initializeLogic]);

return { isLoading, error, isInitialized, retry: initializeLogic };
return { isLoading, error, isInitialized, logicMeta, retry: initializeLogic };
};

export default useLogicInitialization;
15 changes: 15 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,18 @@ body {
padding: 0 0.25rem;
margin-bottom: 0.25rem;
}

.logic-source-warning {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1050;
border-radius: 0;
}

.logic-source-warning .btn-close {
top: 50%;
transform: translateY(-50%);
padding: 0.5rem 1rem;
}
Loading