Fix severe bug where all shapes would be put on the first frame when loading a saved file
This commit is contained in:
parent
78d67f82c8
commit
516dbffd12
56
src/main.js
56
src/main.js
|
|
@ -337,7 +337,8 @@ let actions = {
|
||||||
fillStyle: c.fillStyle,
|
fillStyle: c.fillStyle,
|
||||||
sendToBack: c.sendToBack
|
sendToBack: c.sendToBack
|
||||||
},
|
},
|
||||||
uuid: uuidv4()
|
uuid: uuidv4(),
|
||||||
|
frame: parent.currentFrame.idx
|
||||||
}
|
}
|
||||||
undoStack.push({name: "addShape", action: action})
|
undoStack.push({name: "addShape", action: action})
|
||||||
actions.addShape.execute(action)
|
actions.addShape.execute(action)
|
||||||
|
|
@ -345,6 +346,7 @@ let actions = {
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let object = pointerList[action.parent]
|
let object = pointerList[action.parent]
|
||||||
|
let frame = action.frame ? pointerList[action.frame] : object.currentFrame
|
||||||
let curvesList = action.curves
|
let curvesList = action.curves
|
||||||
let cxt = {
|
let cxt = {
|
||||||
...context,
|
...context,
|
||||||
|
|
@ -361,13 +363,14 @@ let actions = {
|
||||||
}
|
}
|
||||||
let shapes = shape.update()
|
let shapes = shape.update()
|
||||||
for (let newShape of shapes) {
|
for (let newShape of shapes) {
|
||||||
object.addShape(newShape, cxt.sendToBack)
|
frame.addShape(newShape, cxt.sendToBack, frame)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rollback: (action) => {
|
rollback: (action) => {
|
||||||
let object = pointerList[action.parent]
|
let object = pointerList[action.parent]
|
||||||
|
let frame = action.frame ? pointerList[action.frame] : object.currentFrame
|
||||||
let shape = pointerList[action.uuid]
|
let shape = pointerList[action.uuid]
|
||||||
object.removeShape(shape)
|
frame.removeShape(shape)
|
||||||
delete pointerList[action.uuid]
|
delete pointerList[action.uuid]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -484,7 +487,7 @@ let actions = {
|
||||||
imageShape.update()
|
imageShape.update()
|
||||||
imageShape.fillImage = img
|
imageShape.fillImage = img
|
||||||
imageShape.filled = true
|
imageShape.filled = true
|
||||||
imageObject.addShape(imageShape)
|
imageObject.currentFrame.addShape(imageShape)
|
||||||
let parent = pointerList[action.parent]
|
let parent = pointerList[action.parent]
|
||||||
parent.addObject(
|
parent.addObject(
|
||||||
imageObject,
|
imageObject,
|
||||||
|
|
@ -499,7 +502,7 @@ let actions = {
|
||||||
let shape = pointerList[action.shapeUuid]
|
let shape = pointerList[action.shapeUuid]
|
||||||
let object = pointerList[action.objectUuid]
|
let object = pointerList[action.objectUuid]
|
||||||
let parent = pointerList[action.parent]
|
let parent = pointerList[action.parent]
|
||||||
object.removeShape(shape)
|
object.getFrame(0).removeShape(shape)
|
||||||
delete pointerList[action.shapeUuid]
|
delete pointerList[action.shapeUuid]
|
||||||
parent.removeChild(object)
|
parent.removeChild(object)
|
||||||
delete pointerList[action.objectUuid]
|
delete pointerList[action.objectUuid]
|
||||||
|
|
@ -933,7 +936,8 @@ let actions = {
|
||||||
shapes: serializableShapes,
|
shapes: serializableShapes,
|
||||||
objects: serializableObjects,
|
objects: serializableObjects,
|
||||||
groupUuid: uuidv4(),
|
groupUuid: uuidv4(),
|
||||||
parent: context.activeObject.idx
|
parent: context.activeObject.idx,
|
||||||
|
frame: context.activeObject.currentFrame.idx
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'group', action: action})
|
undoStack.push({name: 'group', action: action})
|
||||||
actions.group.execute(action)
|
actions.group.execute(action)
|
||||||
|
|
@ -943,10 +947,11 @@ let actions = {
|
||||||
// your code here
|
// your code here
|
||||||
let group = new GraphicsObject(action.groupUuid)
|
let group = new GraphicsObject(action.groupUuid)
|
||||||
let parent = pointerList[action.parent]
|
let parent = pointerList[action.parent]
|
||||||
|
let frame = action.frame ? pointerList[action.frame] : parent.currentFrame
|
||||||
for (let shapeIdx of action.shapes) {
|
for (let shapeIdx of action.shapes) {
|
||||||
let shape = pointerList[shapeIdx]
|
let shape = pointerList[shapeIdx]
|
||||||
group.addShape(shape)
|
group.currentFrame.addShape(shape)
|
||||||
parent.removeShape(shape)
|
frame.removeShape(shape)
|
||||||
}
|
}
|
||||||
for (let objectIdx of action.objects) {
|
for (let objectIdx of action.objects) {
|
||||||
let object = pointerList[objectIdx]
|
let object = pointerList[objectIdx]
|
||||||
|
|
@ -963,10 +968,11 @@ let actions = {
|
||||||
rollback: (action) => {
|
rollback: (action) => {
|
||||||
let group = pointerList[action.groupUuid]
|
let group = pointerList[action.groupUuid]
|
||||||
let parent = pointerList[action.parent]
|
let parent = pointerList[action.parent]
|
||||||
|
let frame = action.frame ? pointerList[action.frame] : parent.currentFrame
|
||||||
for (let shapeIdx of action.shapes) {
|
for (let shapeIdx of action.shapes) {
|
||||||
let shape = pointerList[shapeIdx]
|
let shape = pointerList[shapeIdx]
|
||||||
parent.addShape(shape)
|
frame.addShape(shape)
|
||||||
group.removeShape(shape)
|
group.getFrame(0).removeShape(shape)
|
||||||
}
|
}
|
||||||
for (let objectIdx of action.objects) {
|
for (let objectIdx of action.objects) {
|
||||||
let object = pointerList[objectIdx]
|
let object = pointerList[objectIdx]
|
||||||
|
|
@ -1338,6 +1344,19 @@ class Frame {
|
||||||
}
|
}
|
||||||
return newFrame
|
return newFrame
|
||||||
}
|
}
|
||||||
|
addShape(shape, sendToBack) {
|
||||||
|
if (sendToBack) {
|
||||||
|
this.shapes.unshift(shape)
|
||||||
|
} else {
|
||||||
|
this.shapes.push(shape)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
removeShape(shape) {
|
||||||
|
let shapeIndex = this.shapes.indexOf(shape)
|
||||||
|
if (shapeIndex >= 0) {
|
||||||
|
this.shapes.splice(shapeIndex, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Layer {
|
class Layer {
|
||||||
|
|
@ -2176,13 +2195,6 @@ class GraphicsObject {
|
||||||
mouse.y -= this.y
|
mouse.y -= this.y
|
||||||
return mouse
|
return mouse
|
||||||
}
|
}
|
||||||
addShape(shape, sendToBack=false) {
|
|
||||||
if (sendToBack) {
|
|
||||||
this.currentFrame.shapes.unshift(shape)
|
|
||||||
} else {
|
|
||||||
this.currentFrame.shapes.push(shape)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addObject(object, x=0, y=0) {
|
addObject(object, x=0, y=0) {
|
||||||
this.children.push(object)
|
this.children.push(object)
|
||||||
object.parent = this
|
object.parent = this
|
||||||
|
|
@ -2196,16 +2208,6 @@ class GraphicsObject {
|
||||||
goToFrame: 1,
|
goToFrame: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeShape(shape) {
|
|
||||||
for (let layer of this.layers) {
|
|
||||||
for (let frame of layer.frames) {
|
|
||||||
let shapeIndex = frame.shapes.indexOf(shape)
|
|
||||||
if (shapeIndex >= 0) {
|
|
||||||
frame.shapes.splice(shapeIndex, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removeChild(childObject) {
|
removeChild(childObject) {
|
||||||
let idx = childObject.idx
|
let idx = childObject.idx
|
||||||
for (let layer of this.layers) {
|
for (let layer of this.layers) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue