lingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
58 lines • 2.3 kB
JavaScript
import { uuidMap } from "../collections/idCollections";
import { flushMultipleSelectionTargets } from "../states/useMultipleSelectionTargets";
import deserialize from "./serializer/deserialize";
const undoStack = [];
const redoStack = [];
export const pushUndoStack = (commandRecord) => {
undoStack.push(commandRecord);
redoStack.length = 0;
};
export const undo = () => flushMultipleSelectionTargets(() => {
const commandRecord = undoStack.pop();
if (!commandRecord)
return;
for (const [uuid, command] of Object.entries(commandRecord)) {
const manager = uuidMap.get(uuid);
if (command.command === "update")
Object.assign(manager, command.commandPrev);
else if (command.command === "delete")
deserialize([command]);
else if (command.command === "create")
manager.dispose();
else if (command.command === "group") {
let i = 0;
for (const uuid of command.commandChildren) {
const child = uuidMap.get(uuid);
const parent = uuidMap.get(command.commandParents[i++]);
parent.attach(child);
}
manager.dispose();
}
else if (command.command === "move")
uuidMap.get(command.commandFrom).attach(manager);
}
redoStack.push(commandRecord);
}, true);
export const redo = () => flushMultipleSelectionTargets(() => {
const commandRecord = redoStack.pop();
if (!commandRecord)
return;
for (const [uuid, command] of Object.entries(commandRecord)) {
const manager = uuidMap.get(uuid);
if (command.command === "update")
Object.assign(manager, command.commandNext);
else if (command.command === "delete")
manager.dispose();
else if (command.command === "create")
deserialize([command]);
else if (command.command === "group") {
const group = deserialize([command])[0];
for (const uuid of command.commandChildren)
group.attach(uuidMap.get(uuid));
}
else if (command.command === "move")
uuidMap.get(command.commandTo).attach(manager);
}
undoStack.push(commandRecord);
}, true);
//# sourceMappingURL=undoStack.js.map