diff --git a/script.js b/script.js index 8344f6d..89c66b2 100644 --- a/script.js +++ b/script.js @@ -148,7 +148,7 @@ window.onload = () => { break; } } - for (let f = currentFrame; f <= 399; f++) { + for (let f = currentFrame; f <= totalFrames; f++) { if (keyframes[f] !== undefined) { nextFrame = f; break; @@ -628,7 +628,7 @@ window.onload = () => { if (selectedDial !== null) { for (let frame in dialKeyframes[selectedDial]) { - const x = (frame / 400) * width; + const x = (frame / totalFrames) * width; ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, height); @@ -639,7 +639,7 @@ window.onload = () => { } else { for (let ch = 0; ch < 5; ch++) { for (let frame in dialKeyframes[ch]) { - const x = (frame / 400) * width; + const x = (frame / totalFrames) * width; ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, height); @@ -650,7 +650,7 @@ window.onload = () => { } } - const currentX = (currentFrame / 400) * width; + const currentX = (currentFrame / totalFrames) * width; ctx.beginPath(); ctx.moveTo(currentX, 0); ctx.lineTo(currentX, height); @@ -673,22 +673,23 @@ window.onload = () => { }); canvas.addEventListener('mousedown', (e) => { - const x = e.offsetX; - const frame = Math.round((x / canvas.width) * totalFrames); + const x = e.offsetX; + const dialIndices = selectedDial !== null ? [selectedDial] : [0, 1, 2, 3, 4]; - const dialIndices = selectedDial !== null ? [selectedDial] : [0, 1, 2, 3, 4]; + for (let ch of dialIndices) { + for (let f in dialKeyframes[ch]) { + const frameNum = parseInt(f); + const fx = (frameNum / totalFrames) * canvas.width; - for (let ch of dialIndices) { - for (let f in dialKeyframes[ch]) { - const fx = (f / totalFrames) * canvas.width; - if (Math.abs(fx - x) < 5) { - draggingKeyframe = { dialIndex: ch, originalFrame: parseInt(f) }; - isDragging = true; - return; - } + if (Math.abs(fx - x) < 15) { + draggingKeyframe = { dialIndex: ch, originalFrame: frameNum }; + isDragging = true; + return; } } - }); + } +}); + canvas.addEventListener('mousemove', (e) => { if (!isDragging || !draggingKeyframe) return; @@ -711,6 +712,7 @@ window.onload = () => { canvas.addEventListener('mouseup', () => { isDragging = false; draggingKeyframe = null; + syncMotorsWithTimeline(); }); canvas.addEventListener('dblclick', (e) => {