10 Commits

Author SHA1 Message Date
f6b34449df 0.4.2
All checks were successful
Deploy to Production / deploy (push) Successful in 10s
2026-02-23 19:42:40 +00:00
21e3465be9 fix(ui): make programmatic moveQueue reactive to immediately reflect intercepted changes like FFF towards F' 2026-02-23 19:42:19 +00:00
ce4a183090 Disable copy/reset actions when move queue is empty 2026-02-23 17:28:33 +00:00
bc7ae67412 Refactor SmartCube controls and move history into separate components 2026-02-23 17:25:59 +00:00
a49ca8f98e 0.4.1
All checks were successful
Deploy to Production / deploy (push) Successful in 8s
2026-02-23 01:14:19 +00:00
afac47c634 chore: adjust panel background for modal 2026-02-23 01:14:10 +00:00
31015366be 0.4.0
All checks were successful
Deploy to Production / deploy (push) Successful in 9s
2026-02-23 01:09:36 +00:00
880d46be1c chore: tweak add-moves modal layout 2026-02-23 01:09:10 +00:00
8d5521e326 0.3.1
All checks were successful
Deploy to Production / deploy (push) Successful in 9s
2026-02-23 00:51:21 +00:00
b5e407f738 chore: refine moves queue layout gap 2026-02-23 00:51:06 +00:00
6 changed files with 648 additions and 247 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "rubic-cube", "name": "rubic-cube",
"version": "0.3.0", "version": "0.4.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rubic-cube", "name": "rubic-cube",
"version": "0.3.0", "version": "0.4.2",
"dependencies": { "dependencies": {
"lucide-vue-next": "^0.564.0", "lucide-vue-next": "^0.564.0",
"rubiks-js": "^1.0.0", "rubiks-js": "^1.0.0",

View File

@@ -1,7 +1,7 @@
{ {
"name": "rubic-cube", "name": "rubic-cube",
"private": true, "private": true,
"version": "0.3.0", "version": "0.4.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -0,0 +1,87 @@
<script setup>
const emit = defineEmits(['move', 'scramble'])
</script>
<template>
<div>
<div class="controls controls-left">
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'U')">U</button>
<button class="btn-neon move-btn" @click="emit('move', 'D')">D</button>
<button class="btn-neon move-btn" @click="emit('move', 'L')">L</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'U-prime')">U'</button>
<button class="btn-neon move-btn" @click="emit('move', 'D-prime')">D'</button>
<button class="btn-neon move-btn" @click="emit('move', 'L-prime')">L'</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'U2')">U2</button>
<button class="btn-neon move-btn" @click="emit('move', 'D2')">D2</button>
<button class="btn-neon move-btn" @click="emit('move', 'L2')">L2</button>
</div>
</div>
<div class="controls controls-right">
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'R')">R</button>
<button class="btn-neon move-btn" @click="emit('move', 'F')">F</button>
<button class="btn-neon move-btn" @click="emit('move', 'B')">B</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'R-prime')">R'</button>
<button class="btn-neon move-btn" @click="emit('move', 'F-prime')">F'</button>
<button class="btn-neon move-btn" @click="emit('move', 'B-prime')">B'</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="emit('move', 'R2')">R2</button>
<button class="btn-neon move-btn" @click="emit('move', 'F2')">F2</button>
<button class="btn-neon move-btn" @click="emit('move', 'B2')">B2</button>
</div>
</div>
<button class="btn-neon move-btn scramble-btn" @click="emit('scramble')">
Scramble
</button>
</div>
</template>
<style scoped>
.controls {
position: absolute;
top: 96px;
display: flex;
flex-direction: column;
gap: 8px;
z-index: 50;
}
.controls-left {
left: 24px;
}
.controls-right {
right: 24px;
}
.controls-row {
display: flex;
gap: 8px;
justify-content: center;
}
.move-btn {
min-width: 44px;
height: 36px;
font-size: 0.9rem;
padding: 0 10px;
}
.scramble-btn {
position: absolute;
bottom: 72px;
left: 24px;
z-index: 50;
}
</style>

View File

@@ -0,0 +1,222 @@
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
const props = defineProps({
moves: {
type: Array,
required: true
}
})
const emit = defineEmits(['reset', 'copy', 'add-moves', 'open-add-modal'])
const MIN_MOVES_COLUMN_GAP = 6
const movesHistoryEl = ref(null)
const samplePillEl = ref(null)
const movesPerRow = ref(0)
const movesColumnGap = ref(MIN_MOVES_COLUMN_GAP)
const displayMoves = computed(() => props.moves || [])
const moveRows = computed(() => {
const perRow = movesPerRow.value || displayMoves.value.length || 1
const rows = []
const all = displayMoves.value
for (let i = 0; i < all.length; i += perRow) {
rows.push(all.slice(i, i + perRow))
}
return rows
})
const hasMoves = computed(() => displayMoves.value.length > 0)
const copyQueueToClipboard = () => {
emit('copy')
}
const resetQueue = () => {
emit('reset')
}
const setSamplePill = (el) => {
if (el && !samplePillEl.value) {
samplePillEl.value = el
}
}
const recalcMovesLayout = () => {
const container = movesHistoryEl.value
const pill = samplePillEl.value
if (!container || !pill) return
const containerWidth = container.clientWidth
const pillWidth = pill.offsetWidth
if (pillWidth <= 0) return
const totalWidth = (cols) => {
if (cols <= 0) return 0
if (cols === 1) return pillWidth
return cols * pillWidth + (cols - 1) * MIN_MOVES_COLUMN_GAP
}
let cols = Math.floor((containerWidth + MIN_MOVES_COLUMN_GAP) / (pillWidth + MIN_MOVES_COLUMN_GAP))
if (cols < 1) cols = 1
while (cols > 1 && totalWidth(cols) > containerWidth) {
cols -= 1
}
let gap = 0
if (cols > 1) {
gap = (containerWidth - cols * pillWidth) / (cols - 1)
}
movesPerRow.value = cols
movesColumnGap.value = gap
}
const openAddModal = () => {
emit('open-add-modal')
}
watch(displayMoves, () => {
nextTick(recalcMovesLayout)
})
onMounted(() => {
window.addEventListener('resize', recalcMovesLayout)
nextTick(recalcMovesLayout)
})
onUnmounted(() => {
window.removeEventListener('resize', recalcMovesLayout)
})
</script>
<template>
<div class="moves-history">
<div class="moves-inner" ref="movesHistoryEl">
<div
v-for="(row, rowIndex) in moveRows"
:key="rowIndex"
class="moves-row"
:style="{ columnGap: movesColumnGap + 'px' }"
>
<span
v-for="(m, idx) in row"
:key="m.id"
class="move-pill"
:class="{
'move-pill-active': m.status === 'in_progress',
'move-pill-pending': m.status === 'pending'
}"
:ref="rowIndex === 0 && idx === 0 ? setSamplePill : null"
>
{{ m.label }}
</span>
</div>
</div>
<div class="moves-actions">
<button class="queue-action" @click="openAddModal">add</button>
<button
class="queue-action"
:class="{ 'queue-action-disabled': !hasMoves }"
:disabled="!hasMoves"
@click="copyQueueToClipboard"
>
copy
</button>
<button
class="queue-action"
:class="{ 'queue-action-disabled': !hasMoves }"
:disabled="!hasMoves"
@click="resetQueue"
>
reset
</button>
</div>
</div>
</template>
<style scoped>
.moves-history {
position: absolute;
bottom: 72px;
left: 50%;
transform: translateX(-50%);
width: 100%;
max-width: calc(100vw - 360px);
overflow-x: hidden;
padding: 12px 12px 26px 12px;
background: rgba(0, 0, 0, 0.4);
border-radius: 8px;
backdrop-filter: blur(8px);
}
.moves-inner {
display: flex;
flex-direction: column;
gap: 6px;
}
.moves-row {
display: flex;
}
.move-pill {
display: flex;
align-items: center;
justify-content: center;
width: 16px;
padding: 4px 8px;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.2);
font-size: 0.8rem;
color: #fff;
white-space: nowrap;
}
.move-pill-active {
background: #ffd500;
color: #000;
border-color: #ffd500;
}
.move-pill-pending {
opacity: 0.4;
}
.moves-actions {
position: absolute;
right: 6px;
bottom: 6px;
display: flex;
gap: 0px;
}
.queue-action {
border: none;
background: transparent;
padding: 6px 6px;
color: #fff;
font-size: 0.8rem;
cursor: pointer;
}
.queue-action-disabled {
opacity: 0.35;
cursor: default;
pointer-events: none;
}
.moves-history::after {
content: none;
}
.queue-action:focus {
outline: none;
box-shadow: none;
}
</style>

View File

@@ -3,6 +3,8 @@ import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { useCube } from '../../composables/useCube' import { useCube } from '../../composables/useCube'
import { useSettings } from '../../composables/useSettings' import { useSettings } from '../../composables/useSettings'
import { LAYER_ANIMATION_DURATION } from '../../config/animationSettings' import { LAYER_ANIMATION_DURATION } from '../../config/animationSettings'
import CubeMoveControls from './CubeMoveControls.vue'
import MoveHistoryPanel from './MoveHistoryPanel.vue'
const { cubies, initCube, rotateLayer, turn, FACES } = useCube() const { cubies, initCube, rotateLayer, turn, FACES } = useCube()
const { isCubeTranslucent } = useSettings() const { isCubeTranslucent } = useSettings()
@@ -13,6 +15,8 @@ const ry = ref(45)
const rz = ref(0) const rz = ref(0)
const SCALE = 100 const SCALE = 100
const GAP = 0 const GAP = 0
const MIN_MOVES_COLUMN_GAP = 6
const movesColumnGap = ref(MIN_MOVES_COLUMN_GAP)
// --- Interaction State --- // --- Interaction State ---
const isDragging = ref(false) const isDragging = ref(false)
@@ -31,6 +35,21 @@ const currentLayerRotation = ref(0) // Visual rotation in degrees
const isAnimating = ref(false) const isAnimating = ref(false)
const pendingLogicalUpdate = ref(false) const pendingLogicalUpdate = ref(false)
const currentMoveId = ref(null) const currentMoveId = ref(null)
const programmaticAnimation = ref(null)
const rotationDebugTarget = computed(() => {
const anim = programmaticAnimation.value
if (!anim) return null
const angle = anim.targetRotation || 0
return Math.round(angle)
})
const rotationDebugCurrent = computed(() => {
const anim = programmaticAnimation.value
if (!anim) return null
const angle = currentLayerRotation.value || 0
return Math.round(angle)
})
// --- Constants & Helpers --- // --- Constants & Helpers ---
@@ -217,11 +236,10 @@ const handleLayerDrag = (totalDx, totalDy, dx, dy) => {
} }
const onMouseUp = () => { const onMouseUp = () => {
isDragging.value = false if (isDragging.value && activeLayer.value) {
if (activeLayer.value) {
snapRotation() snapRotation()
} }
isDragging.value = false
} }
const snapRotation = () => { const snapRotation = () => {
@@ -237,8 +255,7 @@ const snapRotation = () => {
const animate = (time) => { const animate = (time) => {
const p = Math.min((time - startTime) / duration, 1) const p = Math.min((time - startTime) / duration, 1)
// Ease out const ease = easeInOutCubic(p)
const ease = 1 - Math.pow(1 - p, 3)
currentLayerRotation.value = start + (target - start) * ease currentLayerRotation.value = start + (target - start) * ease
@@ -266,14 +283,11 @@ const finishMove = (steps, directionOverride = null) => {
} }
const movesHistory = ref([]) const movesHistory = ref([])
const movesHistoryEl = ref(null)
const samplePillEl = ref(null)
const movesPerRow = ref(0)
const displayMoves = computed(() => { const displayMoves = computed(() => {
const list = movesHistory.value.slice() const list = movesHistory.value.slice()
moveQueue.forEach((q, idx) => { moveQueue.value.forEach((q, idx) => {
const stepsMod = ((q.steps % 4) + 4) % 4 const stepsMod = ((q.steps % 4) + 4) % 4
if (stepsMod === 0) return if (stepsMod === 0) return
@@ -295,15 +309,55 @@ const displayMoves = computed(() => {
return list return list
}) })
const moveRows = computed(() => { const getAxisIndexForBase = (base) => {
const perRow = movesPerRow.value || displayMoves.value.length || 1 if (base === 'U') return { axis: 'y', index: 1 }
const rows = [] if (base === 'D') return { axis: 'y', index: -1 }
const all = displayMoves.value if (base === 'L') return { axis: 'x', index: -1 }
for (let i = 0; i < all.length; i += perRow) { if (base === 'R') return { axis: 'x', index: 1 }
rows.push(all.slice(i, i + perRow)) if (base === 'F') return { axis: 'z', index: 1 }
if (base === 'B') return { axis: 'z', index: -1 }
return { axis: 'y', index: 0 }
}
const getVisualFactor = (axis, base) => {
let factor = 1
if (axis === 'z') factor *= -1
if (base === 'U' || base === 'D') factor *= -1
return factor
}
const coerceStepsToSign = (steps, sign) => {
if (steps === 0) return 0
const mod = ((steps % 4) + 4) % 4
if (sign < 0) {
if (mod === 1) return -3
if (mod === 2) return -2
return -1
}
if (mod === 1) return 1
if (mod === 2) return 2
return 3
}
const formatMoveLabel = (displayBase, steps) => {
const stepsMod = ((steps % 4) + 4) % 4
if (stepsMod === 0) return displayBase
let modifier = ''
if (stepsMod === 1) modifier = "'"
else if (stepsMod === 2) modifier = '2'
else if (stepsMod === 3) modifier = ''
return displayBase + (modifier === "'" ? "'" : modifier === '2' ? '2' : '')
}
const updateCurrentMoveLabel = (displayBase, steps) => {
if (currentMoveId.value === null) return
const idx = movesHistory.value.findIndex(m => m.id === currentMoveId.value)
if (idx === -1) return
movesHistory.value[idx] = {
...movesHistory.value[idx],
label: formatMoveLabel(displayBase, steps)
}
} }
return rows
})
const copyQueueToClipboard = async () => { const copyQueueToClipboard = async () => {
if (!displayMoves.value.length) return if (!displayMoves.value.length) return
@@ -329,31 +383,32 @@ const copyQueueToClipboard = async () => {
} }
} }
const setSamplePill = (el) => {
if (el && !samplePillEl.value) {
samplePillEl.value = el
}
}
const recalcMovesLayout = () => {
const container = movesHistoryEl.value
const pill = samplePillEl.value
if (!container || !pill) return
const containerWidth = container.clientWidth - 4
const pillWidth = pill.offsetWidth + 8
if (pillWidth <= 0) return
const rawCount = Math.floor(containerWidth / pillWidth)
const count = Math.max(1, rawCount - 1)
movesPerRow.value = count
}
const resetQueue = () => { const resetQueue = () => {
moveQueue.length = 0 moveQueue.value = []
movesHistory.value = [] movesHistory.value = []
currentMoveId.value = null currentMoveId.value = null
nextTick(recalcMovesLayout) }
const handleAddMoves = (text) => {
const tokens = text.split(/\s+/).filter(Boolean)
const moves = []
tokens.forEach((token) => {
const t = token.trim()
if (!t) return
const base = t[0]
if (!'UDLRFB'.includes(base)) return
const rest = t.slice(1)
let key = null
if (rest === '') key = base
else if (rest === '2') key = base + '2'
else if (rest === "'" || rest === '') key = base + '-prime'
if (key && MOVE_MAP[key]) {
moves.push(key)
}
})
moves.forEach((m) => applyMove(m))
} }
const getCubieStyle = (c) => { const getCubieStyle = (c) => {
@@ -399,11 +454,11 @@ const getCubieStyle = (c) => {
const getProjectionStyle = () => ({}) const getProjectionStyle = () => ({})
const moveQueue = [] const moveQueue = ref([])
const dequeueMove = () => { const dequeueMove = () => {
while (moveQueue.length) { while (moveQueue.value.length) {
const next = moveQueue.shift() const next = moveQueue.value.shift()
const stepsMod = ((next.steps % 4) + 4) % 4 const stepsMod = ((next.steps % 4) + 4) % 4
if (stepsMod === 0) continue if (stepsMod === 0) continue
@@ -428,67 +483,107 @@ const processNextMove = () => {
movesHistory.value.push({ id, label, status: 'in_progress' }) movesHistory.value.push({ id, label, status: 'in_progress' })
currentMoveId.value = id currentMoveId.value = id
animateProgrammaticMove(next.base, next.modifier) animateProgrammaticMove(next.base, next.modifier, baseLabel)
} }
const animateProgrammaticMove = (base, modifier) => { const easeInOutCubic = (t) => {
if (t < 0.5) return 4 * t * t * t
return 1 - Math.pow(-2 * t + 2, 3) / 2
}
// Derivative of standard easeInOutCubic for instantaneous velocity calculations
const easeInOutCubicDerivative = (t) => {
if (t < 0.5) return 12 * t * t
return 3 * Math.pow(-2 * t + 2, 2)
}
// Custom easing function that preserves initial velocity $v_0$
// The polynomial is $P(t) = (v_0 - 2)t^3 + (3 - 2v_0)t^2 + v_0 t$
const cubicEaseWithInitialVelocity = (t, v0) => {
return (v0 - 2) * t * t * t + (3 - 2 * v0) * t * t + v0 * t
}
// Derivative of the custom easing function
const cubicEaseWithInitialVelocityDerivative = (t, v0) => {
return 3 * (v0 - 2) * t * t + 2 * (3 - 2 * v0) * t + v0
}
const sampleProgrammaticAngle = (anim, time) => {
const p = Math.min((time - anim.startTime) / anim.duration, 1)
const ease = anim.v0 !== undefined
? cubicEaseWithInitialVelocity(p, anim.v0)
: easeInOutCubic(p)
return anim.startRotation + (anim.targetRotation - anim.startRotation) * ease
}
// Calculate the current rotation derivative (Velocity in degrees per millisecond)
const programmaticVelocity = (anim, time) => {
if (time >= anim.startTime + anim.duration) return 0
const p = Math.max(0, Math.min((time - anim.startTime) / anim.duration, 1))
const d_ease_dp = anim.v0 !== undefined
? cubicEaseWithInitialVelocityDerivative(p, anim.v0)
: easeInOutCubicDerivative(p)
const totalVisualDelta = anim.targetRotation - anim.startRotation
// dp/dt = 1 / duration
// d_angle/dt = (totalVisualDelta) * (d_ease_dp) * (dp/dt)
return (totalVisualDelta * d_ease_dp) / anim.duration
}
const stepProgrammaticAnimation = (time) => {
const anim = programmaticAnimation.value
if (!anim) return
const nextRotation = sampleProgrammaticAngle(anim, time)
currentLayerRotation.value = nextRotation
if (time - anim.startTime < anim.duration) {
requestAnimationFrame(stepProgrammaticAnimation)
} else {
let steps = Math.abs(anim.logicalSteps)
const dir = anim.logicalSteps >= 0 ? 1 : -1
pendingLogicalUpdate.value = true
for (let i = 0; i < steps; i += 1) {
rotateLayer(anim.axis, anim.index, dir)
}
programmaticAnimation.value = null
}
}
const animateProgrammaticMove = (base, modifier, displayBase) => {
if (isAnimating.value || activeLayer.value) return if (isAnimating.value || activeLayer.value) return
// Map base move to axis/index (same warstwa jak przy dragowaniu) const { axis, index } = getAxisIndexForBase(base)
let axis = 'y'
let index = 1
if (base === 'U') {
axis = 'y'; index = 1
} else if (base === 'D') {
axis = 'y'; index = -1
} else if (base === 'L') {
axis = 'x'; index = -1
} else if (base === 'R') {
axis = 'x'; index = 1
} else if (base === 'F') {
axis = 'z'; index = 1
} else if (base === 'B') {
axis = 'z'; index = -1
}
// Kierunek zgodny z RubiksJSModel.rotateLayer:
// dir === 1 -> ruch z apostrofem, dir === -1 -> ruch podstawowy (bez apostrofu)
const count = modifier === '2' ? 2 : 1 const count = modifier === '2' ? 2 : 1
const direction = modifier === "'" ? 1 : -1 const direction = modifier === "'" ? 1 : -1
const logicalSteps = direction * count
const visualFactor = getVisualFactor(axis, displayBase)
const visualDelta = logicalSteps * visualFactor * 90
activeLayer.value = { activeLayer.value = {
axis, axis,
index, index,
tangent: { x: 1, y: 0 } tangent: { x: 1, y: 0 }
} }
currentLayerRotation.value = 0
isAnimating.value = true isAnimating.value = true
const logicalSteps = direction * count currentLayerRotation.value = 0
let visualSteps = logicalSteps const startRotation = 0
if (axis === 'z') visualSteps = -visualSteps const targetRotation = visualDelta
if (base === 'U' || base === 'D') visualSteps = -visualSteps
const target = visualSteps * 90
const start = 0
const startTime = performance.now()
const duration = LAYER_ANIMATION_DURATION * count
const animate = (time) => { programmaticAnimation.value = {
const p = Math.min((time - startTime) / duration, 1) axis,
const ease = 1 - Math.pow(1 - p, 3) index,
currentLayerRotation.value = start + (target - start) * ease displayBase,
logicalSteps,
if (p < 1) { visualFactor,
requestAnimationFrame(animate) targetRotation,
} else { startRotation,
pendingLogicalUpdate.value = true startTime: performance.now(),
for (let i = 0; i < count; i += 1) { duration: LAYER_ANIMATION_DURATION * Math.max(Math.abs(visualDelta) / 90 || 1, 0.01)
rotateLayer(axis, index, direction)
}
}
} }
requestAnimationFrame(animate) requestAnimationFrame(stepProgrammaticAnimation)
} }
const MOVE_MAP = { const MOVE_MAP = {
@@ -517,6 +612,25 @@ const MOVE_MAP = {
'B2': { base: 'R', modifier: '2' } 'B2': { base: 'R', modifier: '2' }
} }
const isAddModalOpen = ref(false)
const addMovesText = ref('')
const openAddModal = () => {
addMovesText.value = ''
isAddModalOpen.value = true
}
const closeAddModal = () => {
isAddModalOpen.value = false
}
const handleKeydown = (e) => {
if (e.key === 'Escape' && isAddModalOpen.value) {
e.preventDefault()
closeAddModal()
}
}
const applyMove = (move) => { const applyMove = (move) => {
const mapping = MOVE_MAP[move] const mapping = MOVE_MAP[move]
if (!mapping) return if (!mapping) return
@@ -527,12 +641,55 @@ const applyMove = (move) => {
else if (mapping.modifier === '2') delta = -2 // logical -2 else if (mapping.modifier === '2') delta = -2 // logical -2
const displayBase = move[0] const displayBase = move[0]
const { axis, index } = getAxisIndexForBase(mapping.base)
const visualFactor = getVisualFactor(axis, displayBase)
const currentAnim = programmaticAnimation.value
const last = moveQueue[moveQueue.length - 1] if (
currentAnim &&
isAnimating.value &&
activeLayer.value &&
currentAnim.axis === axis &&
currentAnim.index === index
) {
const now = performance.now()
const currentAngle = sampleProgrammaticAngle(currentAnim, now)
const currentVelocity = programmaticVelocity(currentAnim, now) // degrees per ms
currentLayerRotation.value = currentAngle
currentAnim.logicalSteps += delta
const additionalVisualDelta = delta * currentAnim.visualFactor * 90
// Setup new target
currentAnim.startRotation = currentAngle
currentAnim.targetRotation += additionalVisualDelta
currentAnim.startTime = now
const remainingVisualDelta = currentAnim.targetRotation - currentAngle
// Recalculate duration based on how far we still have to go
currentAnim.duration = LAYER_ANIMATION_DURATION * Math.max(Math.abs(remainingVisualDelta) / 90, 0.01)
// Calculate normalized initial velocity v0
let v0 = 0
if (Math.abs(remainingVisualDelta) > 0.01) {
v0 = (currentVelocity * currentAnim.duration) / remainingVisualDelta
}
currentAnim.v0 = Math.max(-3, Math.min(3, v0))
// Format the new label instantly
const label = formatMoveLabel(displayBase, currentAnim.logicalSteps)
updateCurrentMoveLabel(displayBase, currentAnim.logicalSteps)
return
}
const last = moveQueue.value[moveQueue.value.length - 1]
if (last && last.base === mapping.base && last.displayBase === displayBase) { if (last && last.base === mapping.base && last.displayBase === displayBase) {
last.steps += delta last.steps += delta
} else { } else {
moveQueue.push({ base: mapping.base, displayBase, steps: delta }) moveQueue.value.push({ base: mapping.base, displayBase, steps: delta })
} }
processNextMove() processNextMove()
@@ -563,7 +720,6 @@ watch(cubies, () => {
} }
activeLayer.value = null activeLayer.value = null
currentLayerRotation.value = 0
isAnimating.value = false isAnimating.value = false
selectedCubie.value = null selectedCubie.value = null
selectedFace.value = null selectedFace.value = null
@@ -574,18 +730,13 @@ onMounted(() => {
initCube() initCube()
window.addEventListener('mousemove', onMouseMove) window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp) window.addEventListener('mouseup', onMouseUp)
window.addEventListener('resize', recalcMovesLayout) window.addEventListener('keydown', handleKeydown)
nextTick(recalcMovesLayout)
}) })
onUnmounted(() => { onUnmounted(() => {
window.removeEventListener('mousemove', onMouseMove) window.removeEventListener('mousemove', onMouseMove)
window.removeEventListener('mouseup', onMouseUp) window.removeEventListener('mouseup', onMouseUp)
window.removeEventListener('resize', recalcMovesLayout) window.removeEventListener('keydown', handleKeydown)
})
watch(displayMoves, () => {
nextTick(recalcMovesLayout)
}) })
</script> </script>
@@ -611,71 +762,44 @@ watch(displayMoves, () => {
</div> </div>
</div> </div>
<div class="controls controls-left"> <CubeMoveControls
<div class="controls-row"> @move="applyMove"
<button class="btn-neon move-btn" @click="applyMove('U')">U</button> @scramble="scramble"
<button class="btn-neon move-btn" @click="applyMove('D')">D</button> />
<button class="btn-neon move-btn" @click="applyMove('L')">L</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="applyMove('U-prime')">U'</button>
<button class="btn-neon move-btn" @click="applyMove('D-prime')">D'</button>
<button class="btn-neon move-btn" @click="applyMove('L-prime')">L'</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="applyMove('U2')">U2</button>
<button class="btn-neon move-btn" @click="applyMove('D2')">D2</button>
<button class="btn-neon move-btn" @click="applyMove('L2')">L2</button>
</div>
</div>
<div class="controls controls-right"> <MoveHistoryPanel
<div class="controls-row"> :moves="displayMoves"
<button class="btn-neon move-btn" @click="applyMove('R')">R</button> @reset="resetQueue"
<button class="btn-neon move-btn" @click="applyMove('F')">F</button> @copy="copyQueueToClipboard"
<button class="btn-neon move-btn" @click="applyMove('B')">B</button> @add-moves="handleAddMoves"
</div> @open-add-modal="openAddModal"
<div class="controls-row"> />
<button class="btn-neon move-btn" @click="applyMove('R-prime')">R'</button>
<button class="btn-neon move-btn" @click="applyMove('F-prime')">F'</button>
<button class="btn-neon move-btn" @click="applyMove('B-prime')">B'</button>
</div>
<div class="controls-row">
<button class="btn-neon move-btn" @click="applyMove('R2')">R2</button>
<button class="btn-neon move-btn" @click="applyMove('F2')">F2</button>
<button class="btn-neon move-btn" @click="applyMove('B2')">B2</button>
</div>
</div>
<button class="btn-neon move-btn scramble-btn" @click="scramble">
Scramble
</button>
<div class="moves-history">
<div class="moves-inner" ref="movesHistoryEl">
<div <div
v-for="(row, rowIndex) in moveRows" v-if="isAddModalOpen"
:key="rowIndex" class="moves-modal-backdrop"
class="moves-row" @click.self="closeAddModal"
:class="{ 'moves-row-justify': rowIndex < moveRows.length - 1 }"
> >
<span <div class="moves-modal">
v-for="(m, idx) in row" <textarea
:key="m.id" v-model="addMovesText"
class="move-pill" class="moves-modal-textarea"
:class="{ />
'move-pill-active': m.status === 'in_progress', <div class="moves-modal-actions">
'move-pill-pending': m.status === 'pending' <button class="btn-neon move-btn moves-modal-button" @click="closeAddModal">
}" cancel
:ref="rowIndex === 0 && idx === 0 ? setSamplePill : null" </button>
> <button class="btn-neon move-btn moves-modal-button" @click="handleAddMoves(addMovesText)">
{{ m.label }} add moves
</span> </button>
</div> </div>
</div> </div>
<div v-if="displayMoves.length" class="moves-actions"> </div>
<button class="queue-action" @click="copyQueueToClipboard">copy</button> <div class="rotation-debug">
<button class="queue-action" @click="resetQueue">reset</button> <div class="rotation-debug-target">
{{ rotationDebugTarget !== null ? rotationDebugTarget : '-' }}
</div>
<div class="rotation-debug-current">
{{ rotationDebugCurrent !== null ? rotationDebugCurrent : '-' }}
</div> </div>
</div> </div>
</div> </div>
@@ -714,116 +838,84 @@ watch(displayMoves, () => {
transform-style: preserve-3d; transform-style: preserve-3d;
} }
.controls { .rotation-debug {
position: absolute; position: fixed;
top: 96px;
display: flex;
flex-direction: column;
gap: 8px;
z-index: 50;
}
.controls-left {
left: 24px;
}
.controls-right {
right: 24px; right: 24px;
} top: 50%;
transform: translateY(-50%);
.controls-row {
display: flex;
gap: 8px;
justify-content: center;
}
.move-btn {
min-width: 44px;
height: 36px;
font-size: 0.9rem;
padding: 0 10px;
}
.scramble-btn {
position: absolute;
bottom: 72px;
left: 24px;
z-index: 50;
}
.moves-history {
position: absolute;
bottom: 72px;
left: 50%;
transform: translateX(-50%);
width: 100%;
max-width: calc(100vw - 360px);
overflow-x: hidden;
padding: 12px 12px 26px 12px;
background: rgba(0, 0, 0, 0.4);
border-radius: 8px;
backdrop-filter: blur(8px);
}
.moves-inner {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: flex-end;
gap: 6px; gap: 6px;
padding: 6px 10px;
border-radius: 6px;
background: rgba(0, 0, 0, 0.7);
color: #fff;
z-index: 60;
} }
.moves-row { .rotation-debug-target {
display: flex; font-size: 1.1rem;
column-gap: 8px; font-weight: 700;
} }
.moves-row-justify { .rotation-debug-current {
justify-content: space-between; font-size: 0.95rem;
opacity: 0.8;
} }
.move-pill { .moves-modal-backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.65);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 4px 8px; z-index: 200;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.2);
font-size: 0.8rem;
color: #f0f0f0;
white-space: nowrap;
} }
.move-pill-active { .moves-modal {
background: #ffd500; background: var(--panel-bg);
color: #000; border: 1px solid var(--panel-border);
border-color: #ffd500; color: var(--text-color);
border-radius: 10px;
padding: 24px;
min-width: 480px;
max-width: 800px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
} }
.move-pill-pending { .moves-modal-textarea {
opacity: 0.4; width: 100%;
min-height: 220px;
background: var(--panel-bg);
color: var(--text-color);
box-sizing: border-box;
border-radius: 6px;
border: 1px solid var(--panel-border);
padding: 10px;
resize: vertical;
font-family: inherit;
font-size: 0.85rem;
} }
.moves-actions { .moves-modal-textarea:focus {
position: absolute; outline: none;
right: 6px; box-shadow: none;
bottom: 6px; }
.moves-modal-actions {
margin-top: 20px;
display: flex; display: flex;
gap: 0px; justify-content: flex-end;
gap: 12px;
} }
.queue-action { .moves-modal-button {
border: none; font-size: 0.85rem;
background: transparent;
padding: 6px 6px;
color: #fff;
font-size: 0.8rem;
cursor: pointer;
} }
.moves-history::after { .moves-modal-button:focus {
content: none;
}
.queue-action:focus {
outline: none; outline: none;
box-shadow: none; box-shadow: none;
} }

View File

@@ -31,7 +31,7 @@
--toggle-btn-border: rgba(255, 255, 255, 0.2); --toggle-btn-border: rgba(255, 255, 255, 0.2);
--toggle-hover-border: #ffffff; --toggle-hover-border: #ffffff;
--toggle-active-shadow: 0 0 10px rgba(0, 242, 255, 0.3); --toggle-active-shadow: 0 0 10px rgba(0, 242, 255, 0.3);
--panel-bg: rgba(255, 255, 255, 0.1); --panel-bg: rgba(0, 0, 0, 0.4);
--panel-border: rgba(255, 255, 255, 0.1); --panel-border: rgba(255, 255, 255, 0.1);
--panel-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); --panel-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
--button-bg: rgba(255, 255, 255, 0.1); --button-bg: rgba(255, 255, 255, 0.1);