34 lines
1.4 KiB
JavaScript
34 lines
1.4 KiB
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
(function (global) {
|
||
|
|
const Snapshot = global.TarinaiSnapshot;
|
||
|
|
if (!Snapshot) throw new Error("TarinaiSnapshot is not available for restore_coordinator.js");
|
||
|
|
|
||
|
|
function renderWorldAfterRestore(worldRef = global.world) {
|
||
|
|
if (!worldRef) return;
|
||
|
|
if (typeof renderLog === "function") renderLog(worldRef.logs || []);
|
||
|
|
if (typeof resetArchiveRenderState === "function") resetArchiveRenderState();
|
||
|
|
if (typeof renderArchive === "function") renderArchive();
|
||
|
|
if (typeof renderSelected === "function") renderSelected();
|
||
|
|
if (typeof renderStats === "function") renderStats();
|
||
|
|
if (typeof render === "function") render();
|
||
|
|
if (typeof syncTopButtons === "function") syncTopButtons();
|
||
|
|
}
|
||
|
|
|
||
|
|
function syncRestoreDependents(worldRef = global.world, context = {}) {
|
||
|
|
worldRef?.emit?.("ui:restore-sync", { source: context.source || "restore" });
|
||
|
|
renderWorldAfterRestore(worldRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
function restoreSnapshot(snapshot, worldRef = global.world, options = {}) {
|
||
|
|
const result = Snapshot.restoreSnapshot(snapshot, worldRef);
|
||
|
|
if (options.syncUi !== false) syncRestoreDependents(worldRef, { source: options.source || "snapshot", snapshotVersion: result?.snapshotVersion || Snapshot.version });
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
global.TarinaiRestoreCoordinator = {
|
||
|
|
restoreSnapshot,
|
||
|
|
syncRestoreDependents,
|
||
|
|
renderWorldAfterRestore,
|
||
|
|
};
|
||
|
|
})(typeof window !== "undefined" ? window : globalThis);
|