fix copy&paste
This commit is contained in:
parent
7b11de4b38
commit
10fc546e61
51
src/main.js
51
src/main.js
|
|
@ -401,8 +401,8 @@ let actions = {
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
// your code here
|
// your code here
|
||||||
let object = pointerList[action.object]
|
let object = pointerList[action.object]
|
||||||
let newObj = object.copy()
|
let newObj = object.copy(action.uuid)
|
||||||
newObj.idx = action.uuid
|
// newObj.idx = action.uuid
|
||||||
context.activeObject.addObject(newObj)
|
context.activeObject.addObject(newObj)
|
||||||
updateUI()
|
updateUI()
|
||||||
},
|
},
|
||||||
|
|
@ -617,13 +617,16 @@ let actions = {
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let object = pointerList[action.object]
|
let object = pointerList[action.object]
|
||||||
let layer = pointerList[action.layer]
|
let layer = pointerList[action.layer]
|
||||||
|
console.log(pointerList)
|
||||||
|
console.log(action.object)
|
||||||
|
console.log(object)
|
||||||
let latestFrame = object.getFrame(Math.max(action.frameNum-1, 0))
|
let latestFrame = object.getFrame(Math.max(action.frameNum-1, 0))
|
||||||
let newKeyframe = new Frame("keyframe", action.uuid)
|
let newKeyframe = new Frame("keyframe", action.uuid)
|
||||||
for (let key in latestFrame.keys) {
|
for (let key in latestFrame.keys) {
|
||||||
newKeyframe.keys[key] = structuredClone(latestFrame.keys[key])
|
newKeyframe.keys[key] = structuredClone(latestFrame.keys[key])
|
||||||
}
|
}
|
||||||
for (let shape of latestFrame.shapes) {
|
for (let shape of latestFrame.shapes) {
|
||||||
newKeyframe.shapes.push(shape.copy())
|
newKeyframe.shapes.push(shape.copy(action.uuid))
|
||||||
}
|
}
|
||||||
if (action.frameNum >= layer.frames.length) {
|
if (action.frameNum >= layer.frames.length) {
|
||||||
for (const [index, idx] of Object.entries(action.addedFrames)) {
|
for (const [index, idx] of Object.entries(action.addedFrames)) {
|
||||||
|
|
@ -976,6 +979,7 @@ function selectVertex(context, mouse) {
|
||||||
let closestDist = mouseTolerance;
|
let closestDist = mouseTolerance;
|
||||||
let closestVertex = undefined
|
let closestVertex = undefined
|
||||||
let closestShape = undefined
|
let closestShape = undefined
|
||||||
|
console.log(context.activeObject.currentFrame.shapes)
|
||||||
for (let shape of context.activeObject.currentFrame.shapes) {
|
for (let shape of context.activeObject.currentFrame.shapes) {
|
||||||
if (mouse.x > shape.boundingBox.x.min - mouseTolerance &&
|
if (mouse.x > shape.boundingBox.x.min - mouseTolerance &&
|
||||||
mouse.x < shape.boundingBox.x.max + mouseTolerance &&
|
mouse.x < shape.boundingBox.x.max + mouseTolerance &&
|
||||||
|
|
@ -1121,12 +1125,12 @@ class Frame {
|
||||||
saveState() {
|
saveState() {
|
||||||
startProps[this.idx] = structuredClone(this.keys)
|
startProps[this.idx] = structuredClone(this.keys)
|
||||||
}
|
}
|
||||||
copy() {
|
copy(idx) {
|
||||||
let newFrame = new Frame(this.frameType)
|
let newFrame = new Frame(this.frameType, idx.slice(0,8)+this.idx.slice(8))
|
||||||
newFrame.keys = structuredClone(this.keys)
|
newFrame.keys = structuredClone(this.keys)
|
||||||
newFrame.shapes = []
|
newFrame.shapes = []
|
||||||
for (let shape of this.shapes) {
|
for (let shape of this.shapes) {
|
||||||
newFrame.shapes.push(shape.copy())
|
newFrame.shapes.push(shape.copy(idx))
|
||||||
}
|
}
|
||||||
return newFrame
|
return newFrame
|
||||||
}
|
}
|
||||||
|
|
@ -1236,17 +1240,17 @@ class Layer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy() {
|
copy(idx) {
|
||||||
let newLayer = new Layer()
|
let newLayer = new Layer(idx.slice(0,8)+this.idx.slice(8))
|
||||||
let idxMapping = {}
|
let idxMapping = {}
|
||||||
for (let child of this.children) {
|
for (let child of this.children) {
|
||||||
let newChild = child.copy()
|
let newChild = child.copy(idx)
|
||||||
idxMapping[child.idx] = newChild.idx
|
idxMapping[child.idx] = newChild.idx
|
||||||
newLayer.children.push(newChild)
|
newLayer.children.push(newChild)
|
||||||
}
|
}
|
||||||
newLayer.frames = []
|
newLayer.frames = []
|
||||||
for (let frame of this.frames) {
|
for (let frame of this.frames) {
|
||||||
let newFrame = frame.copy()
|
let newFrame = frame.copy(idx)
|
||||||
newFrame.keys = {}
|
newFrame.keys = {}
|
||||||
for (let key in frame.keys) {
|
for (let key in frame.keys) {
|
||||||
newFrame.keys[idxMapping[key]] = structuredClone(frame.keys[key])
|
newFrame.keys[idxMapping[key]] = structuredClone(frame.keys[key])
|
||||||
|
|
@ -1270,11 +1274,12 @@ class AudioLayer {
|
||||||
this.idx = uuid
|
this.idx = uuid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy() {
|
copy(idx) {
|
||||||
let newAudioLayer = new AudioLayer()
|
let newAudioLayer = new AudioLayer(idx.slice(0,8)+this.idx.slice(8))
|
||||||
for (let sound of this.sounds) {
|
for (let soundIdx in this.sounds) {
|
||||||
|
let sound = this.sounds[soundIdx]
|
||||||
let newPlayer = new Tone.Player(sound.buffer()).toDestination()
|
let newPlayer = new Tone.Player(sound.buffer()).toDestination()
|
||||||
let idx = uuidv4()
|
let idx = this.idx.slice(0,8)+soundIdx.slice(8)
|
||||||
let soundObj = {
|
let soundObj = {
|
||||||
player: newPlayer,
|
player: newPlayer,
|
||||||
start: sound.start
|
start: sound.start
|
||||||
|
|
@ -1430,8 +1435,8 @@ class Shape extends BaseShape {
|
||||||
clear() {
|
clear() {
|
||||||
this.curves = []
|
this.curves = []
|
||||||
}
|
}
|
||||||
copy() {
|
copy(idx) {
|
||||||
let newShape = new Shape(this.startx, this.starty, {}, undefined, this.shapeId)
|
let newShape = new Shape(this.startx, this.starty, {}, idx.slice(0,8)+this.idx.slice(8), this.shapeId)
|
||||||
newShape.startx = this.startx;
|
newShape.startx = this.startx;
|
||||||
newShape.starty = this.starty;
|
newShape.starty = this.starty;
|
||||||
for (let curve of this.curves) {
|
for (let curve of this.curves) {
|
||||||
|
|
@ -1925,8 +1930,10 @@ class GraphicsObject {
|
||||||
scale_y: this.scale_y
|
scale_y: this.scale_y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy() {
|
copy(idx) {
|
||||||
let newGO = new GraphicsObject()
|
let newGO = new GraphicsObject(idx.slice(0,8)+this.idx.slice(8))
|
||||||
|
console.log(pointerList)
|
||||||
|
console.log(newGO.idx)
|
||||||
newGO.x = this.x;
|
newGO.x = this.x;
|
||||||
newGO.y = this.y;
|
newGO.y = this.y;
|
||||||
newGO.rotation = this.rotation;
|
newGO.rotation = this.rotation;
|
||||||
|
|
@ -1936,10 +1943,10 @@ class GraphicsObject {
|
||||||
|
|
||||||
newGO.layers = []
|
newGO.layers = []
|
||||||
for (let layer of this.layers) {
|
for (let layer of this.layers) {
|
||||||
newGO.layers.push(layer.copy())
|
newGO.layers.push(layer.copy(idx))
|
||||||
}
|
}
|
||||||
for (let audioLayer of this.audioLayers) {
|
for (let audioLayer of this.audioLayers) {
|
||||||
newGO.audioLayers.push(audioLayer.copy())
|
newGO.audioLayers.push(audioLayer.copy(idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
return newGO;
|
return newGO;
|
||||||
|
|
@ -2567,10 +2574,11 @@ function stage() {
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
case "draw":
|
case "draw":
|
||||||
context.mouseDown = true
|
context.mouseDown = true
|
||||||
context.activeShape = new Shape(mouse.x, mouse.y, context, true, true)
|
context.activeShape = new Shape(mouse.x, mouse.y, context, uuidv4())
|
||||||
context.lastMouse = mouse
|
context.lastMouse = mouse
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "select":
|
||||||
|
if (context.activeObject.currentFrame.frameType != "keyframe") break;
|
||||||
let selection = selectVertex(context, mouse)
|
let selection = selectVertex(context, mouse)
|
||||||
if (selection) {
|
if (selection) {
|
||||||
context.dragging = true
|
context.dragging = true
|
||||||
|
|
@ -2785,6 +2793,7 @@ function stage() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "select":
|
||||||
|
if (context.activeObject.currentFrame.frameType!="keyframe") break;
|
||||||
if (context.dragging) {
|
if (context.dragging) {
|
||||||
if (context.activeVertex) {
|
if (context.activeVertex) {
|
||||||
let vert = context.activeVertex
|
let vert = context.activeVertex
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue