feat: 3-state projection toggle, English UI titles, fix simple mode
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { Sun, Moon, Grid2x2, Layers } from "lucide-vue-next";
|
import { Sun, Moon, Grid2x2, Layers, Layers2, LayersPlus } from "lucide-vue-next";
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted, computed } from "vue";
|
||||||
import { useSettings } from "../composables/useSettings";
|
import { useSettings } from "../composables/useSettings";
|
||||||
|
|
||||||
const { isCubeTranslucent, toggleCubeTranslucent, showFaceProjections, toggleFaceProjections } = useSettings();
|
const { isCubeTranslucent, toggleCubeTranslucent, projectionMode, cycleProjectionMode } = useSettings();
|
||||||
const isDark = ref(true);
|
const isDark = ref(true);
|
||||||
|
|
||||||
const setTheme = (dark) => {
|
const setTheme = (dark) => {
|
||||||
@@ -17,6 +17,12 @@ const toggleTheme = () => {
|
|||||||
setTheme(!isDark.value);
|
setTheme(!isDark.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const projectionTitle = computed(() => {
|
||||||
|
if (projectionMode.value === 0) return 'Show rear face projections';
|
||||||
|
if (projectionMode.value === 1) return 'Enable animated projections';
|
||||||
|
return 'Disable projections';
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const savedTheme = localStorage.getItem("theme");
|
const savedTheme = localStorage.getItem("theme");
|
||||||
if (savedTheme) {
|
if (savedTheme) {
|
||||||
@@ -40,33 +46,31 @@ onMounted(() => {
|
|||||||
@click="toggleCubeTranslucent"
|
@click="toggleCubeTranslucent"
|
||||||
:title="
|
:title="
|
||||||
isCubeTranslucent
|
isCubeTranslucent
|
||||||
? 'Wyłącz przezroczystość kostki'
|
? 'Disable cube transparency'
|
||||||
: 'Włącz przezroczystość kostki'
|
: 'Enable cube transparency'
|
||||||
"
|
"
|
||||||
:class="{ active: isCubeTranslucent }"
|
:class="{ active: isCubeTranslucent }"
|
||||||
>
|
>
|
||||||
<Grid2x2 :size="20" />
|
<Grid2x2 :size="20" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Face Projections Toggle -->
|
<!-- Face Projections Toggle (3-state) -->
|
||||||
<button
|
<button
|
||||||
class="btn-neon nav-btn icon-only"
|
class="btn-neon nav-btn icon-only"
|
||||||
@click="toggleFaceProjections"
|
@click="cycleProjectionMode"
|
||||||
:title="
|
:title="projectionTitle"
|
||||||
showFaceProjections
|
:class="{ active: projectionMode > 0 }"
|
||||||
? 'Ukryj podgląd tylnych ścian'
|
|
||||||
: 'Pokaż podgląd tylnych ścian'
|
|
||||||
"
|
|
||||||
:class="{ active: showFaceProjections }"
|
|
||||||
>
|
>
|
||||||
<Layers :size="20" />
|
<Layers2 v-if="projectionMode === 0" :size="20" />
|
||||||
|
<Layers v-else-if="projectionMode === 1" :size="20" />
|
||||||
|
<LayersPlus v-else :size="20" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Theme Toggle -->
|
<!-- Theme Toggle -->
|
||||||
<button
|
<button
|
||||||
class="btn-neon nav-btn icon-only"
|
class="btn-neon nav-btn icon-only"
|
||||||
@click="toggleTheme"
|
@click="toggleTheme"
|
||||||
:title="isDark ? 'Przełącz na jasny' : 'Przełącz na ciemny'"
|
:title="isDark ? 'Switch to light mode' : 'Switch to dark mode'"
|
||||||
>
|
>
|
||||||
<Sun v-if="isDark" :size="20" />
|
<Sun v-if="isDark" :size="20" />
|
||||||
<Moon v-else :size="20" />
|
<Moon v-else :size="20" />
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ const props = defineProps({
|
|||||||
viewMatrix: { type: Array, required: true },
|
viewMatrix: { type: Array, required: true },
|
||||||
FACES: { type: Object, required: true },
|
FACES: { type: Object, required: true },
|
||||||
SCALE: { type: Number, default: 100 },
|
SCALE: { type: Number, default: 100 },
|
||||||
|
activeLayer: { type: Object, default: null },
|
||||||
|
currentLayerRotation: { type: Number, default: 0 },
|
||||||
|
animateLayers: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
// The 6 face definitions with logical-space normals and grid axes
|
// Face definitions with logical normals and grid axes
|
||||||
const FACE_DEFS = computed(() => {
|
const FACE_DEFS = computed(() => {
|
||||||
const F = props.FACES;
|
const F = props.FACES;
|
||||||
return [
|
return [
|
||||||
@@ -22,109 +25,149 @@ const FACE_DEFS = computed(() => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine which 3 faces are hidden (transformed normal Z < 0 in CSS space)
|
// Which faces are hidden (for static cells)
|
||||||
const hiddenFaces = computed(() => {
|
const hiddenFaceKeys = computed(() => {
|
||||||
const m = props.viewMatrix;
|
const m = props.viewMatrix;
|
||||||
return FACE_DEFS.value.filter((fd) => {
|
const keys = new Set();
|
||||||
|
for (const fd of FACE_DEFS.value) {
|
||||||
const [nx, ny, nz] = fd.normal;
|
const [nx, ny, nz] = fd.normal;
|
||||||
// viewMatrix is in CSS space where Y is inverted, so negate ny
|
const tz = nx * m[2] + (-ny) * m[6] + nz * m[10];
|
||||||
const cssNy = -ny;
|
if (tz < 0) keys.add(fd.faceKey);
|
||||||
const tz = nx * m[2] + cssNy * m[6] + nz * m[10];
|
}
|
||||||
return tz < 0; // Pointing away from camera = hidden
|
return keys;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// For each hidden face, extract the 3x3 grid of sticker colors and 3D transform
|
// Orientation: cells face INWARD (toward cube center)
|
||||||
const faceGrids = computed(() => {
|
// Combined with backface-visibility: hidden, this means:
|
||||||
const S = props.SCALE;
|
// - hidden face cells: front faces camera → visible
|
||||||
const dist = REAR_FACE_DISTANCE * S * 3; // distance in px (cube width = 3*SCALE)
|
// - visible face cells: front faces away → invisible
|
||||||
|
// - rotating cells crossing the plane: naturally swap visibility
|
||||||
|
const inwardRotation = (nx, ny, nz) => {
|
||||||
|
if (nx === 1) return 'rotateY(-90deg)';
|
||||||
|
if (nx === -1) return 'rotateY(90deg)';
|
||||||
|
if (ny === 1) return 'rotateX(-90deg)';
|
||||||
|
if (ny === -1) return 'rotateX(90deg)';
|
||||||
|
if (nz === -1) return ''; // front faces +Z (toward camera)
|
||||||
|
return 'rotateY(180deg)'; // nz === 1: flip to face -Z (toward center)
|
||||||
|
};
|
||||||
|
|
||||||
return hiddenFaces.value.map((fd) => {
|
// Build cells for one face
|
||||||
const [nx, ny, nz] = fd.normal;
|
const buildFaceCells = (fd, S, dist, al, rot, isRotatingOnly) => {
|
||||||
|
const [nx, ny, nz] = fd.normal;
|
||||||
|
const [gu, gv] = [fd.gridU, fd.gridV];
|
||||||
|
const orient = inwardRotation(nx, ny, nz);
|
||||||
|
const d = S * 1.5 + dist;
|
||||||
|
const cells = [];
|
||||||
|
|
||||||
// Get the 9 cubies on this face
|
const faceCubies = props.cubies.filter((c) => {
|
||||||
const faceCubies = props.cubies.filter((c) => {
|
if (nx !== 0) return c.x === nx;
|
||||||
if (nx !== 0) return c.x === nx;
|
if (ny !== 0) return c.y === ny;
|
||||||
if (ny !== 0) return c.y === ny;
|
if (nz !== 0) return c.z === nz;
|
||||||
if (nz !== 0) return c.z === nz;
|
return false;
|
||||||
return false;
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Build 3x3 grid: map cubie positions to grid cells
|
for (let v = 1; v >= -1; v--) {
|
||||||
const [gu, gv] = [fd.gridU, fd.gridV];
|
for (let u = -1; u <= 1; u++) {
|
||||||
const cells = [];
|
const cx = nx * Math.max(Math.abs(nx), 0) || u * gu[0] + v * gv[0];
|
||||||
for (let v = 1; v >= -1; v--) { // top to bottom
|
const cy = ny * Math.max(Math.abs(ny), 0) || u * gu[1] + v * gv[1];
|
||||||
for (let u = -1; u <= 1; u++) { // left to right
|
const cz = nz * Math.max(Math.abs(nz), 0) || u * gu[2] + v * gv[2];
|
||||||
const cx = nx * Math.max(Math.abs(nx), 0) || u * gu[0] + v * gv[0];
|
|
||||||
const cy = ny * Math.max(Math.abs(ny), 0) || u * gu[1] + v * gv[1];
|
|
||||||
const cz = nz * Math.max(Math.abs(nz), 0) || u * gu[2] + v * gv[2];
|
|
||||||
|
|
||||||
const cubie = faceCubies.find(
|
const inLayer = al && (
|
||||||
(c) => c.x === cx && c.y === cy && c.z === cz
|
(al.axis === 'x' && cx === al.index) ||
|
||||||
);
|
(al.axis === 'y' && cy === al.index) ||
|
||||||
const color = cubie ? cubie.faces[fd.faceKey] || 'black' : 'black';
|
(al.axis === 'z' && cz === al.index)
|
||||||
cells.push(color);
|
);
|
||||||
|
|
||||||
|
// Skip: if isRotatingOnly, only include rotating cells
|
||||||
|
// If not isRotatingOnly (hidden face), include non-rotating cells
|
||||||
|
if (isRotatingOnly && !inLayer) continue;
|
||||||
|
if (!isRotatingOnly && inLayer && props.animateLayers) continue;
|
||||||
|
|
||||||
|
const cubie = faceCubies.find(
|
||||||
|
(c) => c.x === cx && c.y === cy && c.z === cz
|
||||||
|
);
|
||||||
|
const color = cubie ? cubie.faces[fd.faceKey] || 'black' : 'black';
|
||||||
|
|
||||||
|
// 3D position
|
||||||
|
const posX = nx * d + u * gu[0] * S + v * gv[0] * S;
|
||||||
|
const posY = ny * d + u * gu[1] * S + v * gv[1] * S;
|
||||||
|
const posZ = nz * d + u * gu[2] * S + v * gv[2] * S;
|
||||||
|
|
||||||
|
let transform = `translate3d(${posX}px, ${-posY}px, ${posZ}px) ${orient}`;
|
||||||
|
|
||||||
|
// Rotating cells: prepend rotation around scene center (only in advanced mode)
|
||||||
|
if (props.animateLayers && inLayer && rot !== 0) {
|
||||||
|
let rotPre = '';
|
||||||
|
if (al.axis === 'x') rotPre = `rotateX(${-rot}deg)`;
|
||||||
|
else if (al.axis === 'y') rotPre = `rotateY(${rot}deg)`;
|
||||||
|
else if (al.axis === 'z') rotPre = `rotateZ(${-rot}deg)`;
|
||||||
|
transform = `${rotPre} ${transform}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cells.push({
|
||||||
|
key: `${fd.faceKey}-${u}-${v}`,
|
||||||
|
color,
|
||||||
|
transform,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cells;
|
||||||
|
};
|
||||||
|
|
||||||
|
// All cells to render
|
||||||
|
const allCells = computed(() => {
|
||||||
|
const S = props.SCALE;
|
||||||
|
const dist = REAR_FACE_DISTANCE * S * 3;
|
||||||
|
const al = props.activeLayer;
|
||||||
|
const rot = props.currentLayerRotation;
|
||||||
|
const cells = [];
|
||||||
|
|
||||||
|
for (const fd of FACE_DEFS.value) {
|
||||||
|
const isHidden = hiddenFaceKeys.value.has(fd.faceKey);
|
||||||
|
|
||||||
|
if (isHidden) {
|
||||||
|
// Hidden face: render non-rotating cells (static projections)
|
||||||
|
cells.push(...buildFaceCells(fd, S, dist, al, rot, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position: ALONG the normal direction (behind the cube from camera's perspective)
|
// ALL faces: render rotating-layer cells (they swap via backface-visibility)
|
||||||
const d = S * 1.5 + dist;
|
if (props.animateLayers && al && rot !== 0) {
|
||||||
const offsetX = nx * d;
|
cells.push(...buildFaceCells(fd, S, dist, al, rot, true));
|
||||||
const cssY = -ny * d; // Logical Y → CSS Y (inverted)
|
}
|
||||||
const offsetZ = nz * d;
|
}
|
||||||
|
|
||||||
let transform = `translate3d(${offsetX}px, ${cssY}px, ${offsetZ}px)`;
|
return cells;
|
||||||
|
|
||||||
// Rotate panel to face OUTWARD from cube center
|
|
||||||
if (nx === 1) transform += ' rotateY(90deg)';
|
|
||||||
else if (nx === -1) transform += ' rotateY(-90deg)';
|
|
||||||
else if (ny === 1) transform += ' rotateX(90deg)';
|
|
||||||
else if (ny === -1) transform += ' rotateX(-90deg)';
|
|
||||||
else if (nz === -1) transform += ' rotateY(180deg)';
|
|
||||||
// nz === 1: default orientation (front faces +z)
|
|
||||||
|
|
||||||
return {
|
|
||||||
faceKey: fd.faceKey,
|
|
||||||
cells,
|
|
||||||
transform,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="face-projections-root">
|
||||||
v-for="grid in faceGrids"
|
|
||||||
:key="grid.faceKey"
|
|
||||||
class="face-projection"
|
|
||||||
:style="{ transform: grid.transform }"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
v-for="(color, idx) in grid.cells"
|
v-for="cell in allCells"
|
||||||
:key="idx"
|
:key="cell.key"
|
||||||
class="proj-cell"
|
class="proj-cell"
|
||||||
:class="color"
|
:class="cell.color"
|
||||||
|
:style="{ transform: cell.transform }"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.face-projection {
|
.face-projections-root {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: grid;
|
transform-style: preserve-3d;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
|
||||||
width: 300px;
|
|
||||||
height: 300px;
|
|
||||||
/* Center the grid on its position */
|
|
||||||
margin-left: -150px;
|
|
||||||
margin-top: -150px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.proj-cell {
|
.proj-cell {
|
||||||
|
position: absolute;
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
margin-left: -50px;
|
||||||
|
margin-top: -50px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: #000;
|
background: #000;
|
||||||
border: 1px solid #000;
|
border: 1px solid #000;
|
||||||
position: relative;
|
backface-visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.proj-cell::after {
|
.proj-cell::after {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { getFaceNormal as getFaceNormalRaw, getAllowedAxes as getAllowedAxesRaw,
|
|||||||
import { tokenReducer } from "../../utils/tokenReducer.js";
|
import { tokenReducer } from "../../utils/tokenReducer.js";
|
||||||
|
|
||||||
const { cubies, deepCubeState, initCube, rotateLayer, rotateSlice, turn, FACES, solve, solveResult, solveError, isSolverReady } = useCube();
|
const { cubies, deepCubeState, initCube, rotateLayer, rotateSlice, turn, FACES, solve, solveResult, solveError, isSolverReady } = useCube();
|
||||||
const { isCubeTranslucent, showFaceProjections } = useSettings();
|
const { isCubeTranslucent, projectionMode } = useSettings();
|
||||||
|
|
||||||
// Bind FACES and viewMatrix to imported helpers
|
// Bind FACES and viewMatrix to imported helpers
|
||||||
const getFaceNormal = (face) => getFaceNormalRaw(face, FACES);
|
const getFaceNormal = (face) => getFaceNormalRaw(face, FACES);
|
||||||
@@ -881,11 +881,14 @@ onUnmounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FaceProjections
|
<FaceProjections
|
||||||
v-if="showFaceProjections"
|
v-if="projectionMode > 0"
|
||||||
:cubies="cubies"
|
:cubies="cubies"
|
||||||
:view-matrix="viewMatrix"
|
:view-matrix="viewMatrix"
|
||||||
:FACES="FACES"
|
:FACES="FACES"
|
||||||
:SCALE="SCALE"
|
:SCALE="SCALE"
|
||||||
|
:active-layer="activeLayer"
|
||||||
|
:current-layer-rotation="currentLayerRotation"
|
||||||
|
:animate-layers="projectionMode === 2"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -8,16 +8,17 @@ try {
|
|||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|
||||||
let initialShowFaceProjections = false;
|
// 0 = off, 1 = simple projections, 2 = advanced (animated layers)
|
||||||
|
let initialProjectionMode = 0;
|
||||||
try {
|
try {
|
||||||
const stored = localStorage.getItem("showFaceProjections");
|
const stored = localStorage.getItem("projectionMode");
|
||||||
if (stored !== null) {
|
if (stored !== null) {
|
||||||
initialShowFaceProjections = stored === "true";
|
initialProjectionMode = Math.min(2, Math.max(0, parseInt(stored, 10) || 0));
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|
||||||
const isCubeTranslucent = ref(initialCubeTranslucent);
|
const isCubeTranslucent = ref(initialCubeTranslucent);
|
||||||
const showFaceProjections = ref(initialShowFaceProjections);
|
const projectionMode = ref(initialProjectionMode);
|
||||||
|
|
||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
const toggleCubeTranslucent = () => {
|
const toggleCubeTranslucent = () => {
|
||||||
@@ -27,17 +28,17 @@ export function useSettings() {
|
|||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleFaceProjections = () => {
|
const cycleProjectionMode = () => {
|
||||||
showFaceProjections.value = !showFaceProjections.value;
|
projectionMode.value = (projectionMode.value + 1) % 3;
|
||||||
try {
|
try {
|
||||||
localStorage.setItem("showFaceProjections", String(showFaceProjections.value));
|
localStorage.setItem("projectionMode", String(projectionMode.value));
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isCubeTranslucent,
|
isCubeTranslucent,
|
||||||
toggleCubeTranslucent,
|
toggleCubeTranslucent,
|
||||||
showFaceProjections,
|
projectionMode,
|
||||||
toggleFaceProjections,
|
cycleProjectionMode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user