Delete frame

This commit is contained in:
Skyler Lehmkuhl 2024-12-23 01:21:08 -05:00
parent 0aada309ca
commit 7cf8ff7776
1 changed files with 33 additions and 15 deletions

View File

@ -803,6 +803,7 @@ let actions = {
let layer = pointerList[action.layer] let layer = pointerList[action.layer]
layer.addOrChangeFrame(action.frameNum, "keyframe", action.uuid, action.addedFrames) layer.addOrChangeFrame(action.frameNum, "keyframe", action.uuid, action.addedFrames)
updateLayers() updateLayers()
updateUI()
}, },
rollback: (action) => { rollback: (action) => {
let layer = pointerList[action.layer] let layer = pointerList[action.layer]
@ -815,6 +816,7 @@ let actions = {
layer.frames[action.frameNum].frameType = action.formerType layer.frames[action.frameNum].frameType = action.formerType
} }
updateLayers() updateLayers()
updateUI()
} }
}, },
deleteFrame: { deleteFrame: {
@ -829,11 +831,17 @@ let actions = {
updateMenu() updateMenu()
}, },
execute: (action) => { execute: (action) => {
let frame = pointerList[action.frame]
let layer = pointerList[action.layer] let layer = pointerList[action.layer]
layer.deleteFrame(action.frame)
updateLayers()
updateUI()
}, },
rollback: (action) => { rollback: (action) => {
// your code here let layer = pointerList[action.layer]
let frame = pointerList[action.frame]
layer.addFrame(action.frameNum, frame, {})
updateLayers()
updateUI()
} }
}, },
addMotionTween: { addMotionTween: {
@ -1486,15 +1494,7 @@ class Layer {
} }
return newLayer return newLayer
} }
addOrChangeFrame(num, frameType, uuid, addedFrames) { addFrame(num, frame, addedFrames) {
let latestFrame = this.getFrame(Math.max(num-1, 0))
let newKeyframe = new Frame(frameType, uuid)
for (let key in latestFrame.keys) {
newKeyframe.keys[key] = structuredClone(latestFrame.keys[key])
}
for (let shape of latestFrame.shapes) {
newKeyframe.shapes.push(shape.copy(uuid))
}
let updateDest = undefined let updateDest = undefined
if (num >= this.frames.length) { if (num >= this.frames.length) {
for (const [index, idx] of Object.entries(addedFrames)) { for (const [index, idx] of Object.entries(addedFrames)) {
@ -1507,12 +1507,23 @@ class Layer {
updateDest = "shape" updateDest = "shape"
} }
} }
this.frames[num] = newKeyframe this.frames[num] = frame
if (updateDest) { if (updateDest) {
this.updateFrameNextAndPrev(num-1, updateDest) this.updateFrameNextAndPrev(num-1, updateDest)
this.updateFrameNextAndPrev(num+1, updateDest) this.updateFrameNextAndPrev(num+1, updateDest)
} }
} }
addOrChangeFrame(num, frameType, uuid, addedFrames) {
let latestFrame = this.getFrame(Math.max(num-1, 0))
let newKeyframe = new Frame(frameType, uuid)
for (let key in latestFrame.keys) {
newKeyframe.keys[key] = structuredClone(latestFrame.keys[key])
}
for (let shape of latestFrame.shapes) {
newKeyframe.shapes.push(shape.copy(uuid))
}
this.addFrame(num, newKeyframe, addedFrames)
}
deleteFrame(uuid, destinationType) { deleteFrame(uuid, destinationType) {
let frame = pointerList[uuid] let frame = pointerList[uuid]
let i = this.frames.indexOf(frame) let i = this.frames.indexOf(frame)
@ -1536,8 +1547,8 @@ class Layer {
if (destinationType=="none") { if (destinationType=="none") {
delete this.frames[i] delete this.frames[i]
} else { } else {
this.frames[i].frameType = frameType this.frames[i].frameType = destinationType
this.updateFrameNextAndPrev(i, frameType) this.updateFrameNextAndPrev(i, destinationType)
} }
} }
} }
@ -2783,6 +2794,13 @@ function addFrame() {
function addKeyframe() { function addKeyframe() {
actions.addKeyframe.create() actions.addKeyframe.create()
} }
function deleteFrame() {
let frame = context.activeObject.currentFrame
let layer = context.activeObject.activeLayer
if (frame) {
actions.deleteFrame.create(frame, layer)
}
}
async function about () { async function about () {
messageDialog(`Lightningbeam version ${await getVersion()}\nDeveloped by Skyler Lehmkuhl`, messageDialog(`Lightningbeam version ${await getVersion()}\nDeveloped by Skyler Lehmkuhl`,
{title: 'About', kind: "info"} {title: 'About', kind: "info"}
@ -4916,7 +4934,7 @@ async function updateMenu() {
deleteFrameMenuItem = { deleteFrameMenuItem = {
text: "Delete Frame", text: "Delete Frame",
enabled: activeFrame, enabled: activeFrame,
action: () => {} action: deleteFrame
} }
const timelineSubmenu = await Submenu.new({ const timelineSubmenu = await Submenu.new({