Add manual toolbox module ordering
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s

This commit is contained in:
Shinuwa 2026-08-09 20:51:51 +02:00
parent 7140012a98
commit e043d31fa8
10 changed files with 321 additions and 128 deletions

View file

@ -6,6 +6,7 @@ import {
globalModuleKey,
labelFromFileName,
normalizeToolbox,
remapModuleOrderIds,
uid
} from "./storage/toolboxStorage.js";
import { compressImage } from "../../utils/imageCompression.js";
@ -123,14 +124,16 @@ export function useToolboxActions({ store, notify, setConfirmModal, setCreateMod
moduleIdMap.set(module.id, nextId);
return { ...module, id: nextId };
});
if (!store.setToolboxes([imported, ...store.toolboxes])) return null;
imported.moduleOrder = remapModuleOrderIds(imported.moduleOrder, moduleIdMap);
const normalizedImport = normalizeToolbox(imported);
if (!store.setToolboxes([normalizedImport, ...store.toolboxes])) return null;
Object.entries(payload.modules || {}).forEach(([oldId, data]) => {
const nextId = moduleIdMap.get(oldId);
const module = imported.modules.find((item) => item.id === nextId);
if (nextId) store.updateModuleData(imported.id, nextId, data, module?.type);
const module = normalizedImport.modules.find((item) => item.id === nextId);
if (nextId) store.updateModuleData(normalizedImport.id, nextId, data, module?.type);
});
if (gameId) linkToolboxToGame(gameId, imported.id);
return imported;
if (gameId) linkToolboxToGame(gameId, normalizedImport.id);
return normalizedImport;
}
async function importAllToolboxesPayload(file) {
@ -143,12 +146,15 @@ export function useToolboxActions({ store, notify, setConfirmModal, setCreateMod
const importedToolboxes = payload.toolboxes.map((toolbox) => {
const nextToolboxId = uid("tbx");
toolboxIdMap.set(toolbox.id, nextToolboxId);
const localModuleIdMap = new Map();
const modules = (toolbox.modules || []).map((module) => {
const nextModuleId = uid("mod");
moduleIdMap.set(globalModuleKey(toolbox.id, module.id), nextModuleId);
localModuleIdMap.set(module.id, nextModuleId);
return { ...module, id: nextModuleId };
});
return normalizeToolbox({ ...toolbox, id: nextToolboxId, name: `${toolbox.name || "Toolbox"} (import)`, modules, updatedAt: new Date().toISOString() });
const moduleOrder = remapModuleOrderIds(toolbox.moduleOrder, localModuleIdMap);
return normalizeToolbox({ ...toolbox, id: nextToolboxId, name: `${toolbox.name || "Toolbox"} (import)`, modules, moduleOrder, updatedAt: new Date().toISOString() });
});
const nextLinks = { ...store.links };
Object.entries(payload.links || {}).forEach(([gameId, oldToolboxId]) => {