Skip to content

Commit be3c898

Browse files
author
DavidQ
committed
Fix Skin Editor game-context handoff and catalog-based skin loading after preset removal
1 parent 913963f commit be3c898

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

games/shared/gameSkinLoader.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,14 @@ function resolveSkinAssetPath(gameId) {
859859
return resolveWorkspaceGameAssetPath(gameId, "skin.main", "");
860860
}
861861

862+
function deriveWorkspaceCatalogPath(gameId) {
863+
const normalizedGameId = normalizeText(gameId);
864+
if (!normalizedGameId) {
865+
return "";
866+
}
867+
return normalizePath(`/games/${encodeURIComponent(normalizedGameId)}/assets/workspace.asset-catalog.json`);
868+
}
869+
862870
export async function loadGameSkin(options = {}) {
863871
const expectedGameId = normalizeText(options.gameId);
864872
if (!expectedGameId) {
@@ -875,7 +883,9 @@ export async function loadGameSkin(options = {}) {
875883
};
876884
}
877885

878-
await preloadWorkspaceGameAssetCatalog(expectedGameId);
886+
const explicitCatalogPath = normalizePath(options.catalogPath);
887+
const catalogPath = explicitCatalogPath || deriveWorkspaceCatalogPath(expectedGameId);
888+
await preloadWorkspaceGameAssetCatalog(expectedGameId, { catalogPath });
879889

880890
const skinPath = resolveSkinAssetPath(expectedGameId);
881891
if (!skinPath) {

tools/Skin Editor/main.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ function toDownloadName(gameId) {
267267
return `${normalized || "game"}-skin.json`;
268268
}
269269

270+
function deriveCatalogPathFromGameHref(gameHref) {
271+
const href = normalizeText(gameHref).replace(/\\/g, "/");
272+
if (!href || !href.startsWith("/games/")) {
273+
return "";
274+
}
275+
if (href.endsWith("/index.html")) {
276+
return `${href.slice(0, -"/index.html".length)}/assets/workspace.asset-catalog.json`;
277+
}
278+
if (href.endsWith("/")) {
279+
return `${href}assets/workspace.asset-catalog.json`;
280+
}
281+
return "";
282+
}
283+
270284
function downloadTextFile(filename, contents) {
271285
const blob = new Blob([contents], { type: "application/json" });
272286
const objectUrl = URL.createObjectURL(blob);
@@ -1440,7 +1454,8 @@ async function loadActiveSkinForSelectedGame() {
14401454
try {
14411455
result = await loadGameSkin({
14421456
gameId: game.id,
1443-
fallbackSchema: game.fallbackSchema
1457+
fallbackSchema: game.fallbackSchema,
1458+
catalogPath: deriveCatalogPathFromGameHref(game.gameHref)
14441459
});
14451460
} catch (error) {
14461461
setStatus(`Skin load failed: ${error instanceof Error ? error.message : "unknown error"}`);
@@ -1768,10 +1783,11 @@ function extractPresetPayload(rawPreset) {
17681783

17691784
async function loadPresetFromQuery() {
17701785
const searchParams = new URLSearchParams(window.location.search);
1786+
const requestedGameId = normalizeText(searchParams.get("gameId") || searchParams.get("game"));
17711787
const samplePresetPath = normalizeSamplePresetPath(searchParams.get("samplePresetPath"));
17721788
if (!samplePresetPath) {
17731789
return {
1774-
gameId: normalizeText(searchParams.get("gameId")),
1790+
gameId: requestedGameId,
17751791
presetLoaded: false
17761792
};
17771793
}
@@ -1785,15 +1801,15 @@ async function loadPresetFromQuery() {
17851801
const rawPreset = await response.json();
17861802
const payload = extractPresetPayload(rawPreset);
17871803
state.presetSkin = payload.skin && typeof payload.skin === "object" ? payload.skin : null;
1788-
const gameId = normalizeText(payload.gameId || searchParams.get("gameId"));
1804+
const gameId = normalizeText(payload.gameId || requestedGameId);
17891805
return {
17901806
gameId,
17911807
presetLoaded: true
17921808
};
17931809
} catch (error) {
17941810
setStatus(`Preset load failed: ${error instanceof Error ? error.message : "unknown error"}`);
17951811
return {
1796-
gameId: normalizeText(searchParams.get("gameId")),
1812+
gameId: requestedGameId,
17971813
presetLoaded: false
17981814
};
17991815
}

tools/Workspace Manager/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ function updateStandaloneHref(toolId) {
225225

226226
function writeQueryToolId(toolId, replace = false) {
227227
const url = new URL(window.location.href);
228+
const gameParam = normalizeTextParam(url.searchParams.get("game"));
229+
const gameIdParam = normalizeTextParam(url.searchParams.get("gameId"));
230+
if (!gameIdParam && gameParam) {
231+
url.searchParams.set("gameId", gameParam);
232+
}
228233
url.searchParams.delete("game");
229234
if (toolId) {
230235
url.searchParams.set("tool", toolId);

0 commit comments

Comments
 (0)