diff --git a/src/store/project.ts b/src/store/project.ts index 6018115..713be78 100644 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -203,7 +203,7 @@ export const useProjectStore = defineStore("project", () => { } } - function createLayer(name = "New layer") { + function createLayer(name = "New layer", targetIndex?: number) { const layer: Layer = { id: generateId(), name, @@ -213,7 +213,11 @@ export const useProjectStore = defineStore("project", () => { }; layer.matrix.setEmptyMatrixId(_emptyMatrixId.value); layer.matrix.setSeparator(_matrixSeparator.value); - _layers.unshift(layer); + if (typeof targetIndex == "number") { + _layers.splice(targetIndex, 0, layer); + } else { + _layers.unshift(layer); + } if (_layers.length === 1) { setSelectedLayer(layer); diff --git a/src/utils/save.ts b/src/utils/save.ts index 01b9d45..849b5da 100644 --- a/src/utils/save.ts +++ b/src/utils/save.ts @@ -16,6 +16,7 @@ export namespace ProjectSaver { isVisible: boolean; isLocked: boolean; matrixString: string; + index: number; }[]; materials: { name: string; @@ -84,7 +85,7 @@ export namespace ProjectSaver { // add layers for (const rawLayer of json.project.layers) { - const layer = projectStore.createLayer(rawLayer.name); + const layer = projectStore.createLayer(rawLayer.name, rawLayer.index); layer.isLocked = rawLayer.isLocked; layer.isVisible = rawLayer.isVisible; layer.matrix.fromString(rawLayer.matrixString); @@ -150,14 +151,13 @@ export namespace ProjectSaver { return { project: { - layers: projectStore.layers.map((v) => { - return { - name: v.name, - isLocked: v.isLocked, - isVisible: v.isVisible, - matrixString: v.matrix.toString(), - }; - }), + layers: projectStore.layers.map((layer, index) => ({ + name: layer.name, + isLocked: layer.isLocked, + isVisible: layer.isVisible, + matrixString: layer.matrix.toString(), + index, + })), materials: projectStore.materials.map((v) => { return { name: v.getName(),