diff --git a/src/components/renderers/SmartCube.vue b/src/components/renderers/SmartCube.vue index 263ed50..2e17c05 100644 --- a/src/components/renderers/SmartCube.vue +++ b/src/components/renderers/SmartCube.vue @@ -271,6 +271,8 @@ const movesHistory = ref([]) const movesHistoryEl = ref(null) const samplePillEl = ref(null) const movesPerRow = ref(0) +const isAddModalOpen = ref(false) +const addMovesText = ref('') const displayMoves = computed(() => { const list = movesHistory.value.slice() @@ -374,6 +376,47 @@ const resetQueue = () => { nextTick(recalcMovesLayout) } +const openAddModal = () => { + addMovesText.value = '' + isAddModalOpen.value = true +} + +const closeAddModal = () => { + isAddModalOpen.value = false +} + +const handleAddMoves = () => { + const text = addMovesText.value || '' + 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)) + addMovesText.value = '' + isAddModalOpen.value = false +} + +const handleKeydown = (e) => { + if (e.key === 'Escape' && isAddModalOpen.value) { + e.preventDefault() + closeAddModal() + } +} + const getCubieStyle = (c) => { // Base Position const x = c.x * (SCALE + GAP) @@ -593,6 +636,7 @@ onMounted(() => { window.addEventListener('mousemove', onMouseMove) window.addEventListener('mouseup', onMouseUp) window.addEventListener('resize', recalcMovesLayout) + window.addEventListener('keydown', handleKeydown) nextTick(recalcMovesLayout) }) @@ -600,6 +644,7 @@ onUnmounted(() => { window.removeEventListener('mousemove', onMouseMove) window.removeEventListener('mouseup', onMouseUp) window.removeEventListener('resize', recalcMovesLayout) + window.removeEventListener('keydown', handleKeydown) }) watch(displayMoves, () => { @@ -691,9 +736,42 @@ watch(displayMoves, () => { -