Skip to content

Commit

Permalink
fix: save layer's position
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehue committed Mar 29, 2024
1 parent 39664e6 commit 2e01a3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/utils/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export namespace ProjectSaver {
isVisible: boolean;
isLocked: boolean;
matrixString: string;
index: number;
}[];
materials: {
name: string;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 2e01a3d

Please sign in to comment.