Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09df96922e | ||
|
|
0add9e4ef1 | ||
|
|
3eb85d7d72 | ||
|
|
eb3700a57d |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
||||
## [4.67.1](https://github.com/antialias/soroban-abacus-flashcards/compare/v4.67.0...v4.67.1) (2025-10-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **complement-race:** fix react-spring interpolation TypeScript errors ([0add9e4](https://github.com/antialias/soroban-abacus-flashcards/commit/0add9e4ef1d69e4e92ffe279cce09c68efa43714))
|
||||
|
||||
## [4.67.0](https://github.com/antialias/soroban-abacus-flashcards/compare/v4.66.2...v4.67.0) (2025-10-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **complement-race:** add react-spring animations to ghost trains for smooth movement ([eb3700a](https://github.com/antialias/soroban-abacus-flashcards/commit/eb3700a57d035a142c64b60d5d1b21181d21b69f))
|
||||
|
||||
## [4.66.2](https://github.com/antialias/soroban-abacus-flashcards/compare/v4.66.1...v4.66.2) (2025-10-22)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useSpring, useSprings, animated, to } from '@react-spring/web'
|
||||
import { useMemo, useRef } from 'react'
|
||||
import type { PlayerState } from '@/arcade-games/complement-race/types'
|
||||
import type { RailroadTrackGenerator } from '../../lib/RailroadTrackGenerator'
|
||||
@@ -56,8 +57,8 @@ export function GhostTrain({
|
||||
}: GhostTrainProps) {
|
||||
const ghostRef = useRef<SVGGElement>(null)
|
||||
|
||||
// Calculate ghost train locomotive transform and opacity
|
||||
const locomotiveTransform = useMemo<CarTransform | null>(() => {
|
||||
// Calculate target transform for locomotive (used by spring animation)
|
||||
const locomotiveTarget = useMemo<CarTransform | null>(() => {
|
||||
if (!pathRef.current) {
|
||||
return null
|
||||
}
|
||||
@@ -82,8 +83,17 @@ export function GhostTrain({
|
||||
}
|
||||
}, [trainPosition, localTrainCarPositions, pathRef])
|
||||
|
||||
// Calculate ghost train car transforms (each car behind locomotive)
|
||||
const carTransforms = useMemo<CarTransform[]>(() => {
|
||||
// Animated spring for smooth locomotive movement
|
||||
const locomotiveSpring = useSpring({
|
||||
x: locomotiveTarget?.x ?? 0,
|
||||
y: locomotiveTarget?.y ?? 0,
|
||||
rotation: locomotiveTarget?.rotation ?? 0,
|
||||
opacity: locomotiveTarget?.opacity ?? 1,
|
||||
config: { tension: 280, friction: 60 }, // Smooth but responsive
|
||||
})
|
||||
|
||||
// Calculate target transforms for cars (used by spring animations)
|
||||
const carTargets = useMemo<CarTransform[]>(() => {
|
||||
if (!pathRef.current) {
|
||||
return []
|
||||
}
|
||||
@@ -115,20 +125,32 @@ export function GhostTrain({
|
||||
return cars
|
||||
}, [trainPosition, maxCars, carSpacing, localTrainCarPositions, pathRef])
|
||||
|
||||
// Animated springs for smooth car movement (useSprings for multiple cars)
|
||||
const carSprings = useSprings(
|
||||
carTargets.length,
|
||||
carTargets.map((target) => ({
|
||||
x: target.x,
|
||||
y: target.y,
|
||||
rotation: target.rotation,
|
||||
opacity: target.opacity,
|
||||
config: { tension: 280, friction: 60 },
|
||||
}))
|
||||
)
|
||||
|
||||
// Don't render if position data isn't ready
|
||||
if (!locomotiveTransform) {
|
||||
if (!locomotiveTarget) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<g ref={ghostRef} data-component="ghost-train" data-player-id={player.id}>
|
||||
{/* Ghost locomotive */}
|
||||
<g
|
||||
transform={`translate(${locomotiveTransform.x}, ${locomotiveTransform.y}) rotate(${locomotiveTransform.rotation}) scale(-1, 1)`}
|
||||
opacity={locomotiveTransform.opacity}
|
||||
style={{
|
||||
transition: 'opacity 0.3s ease-in-out',
|
||||
}}
|
||||
{/* Ghost locomotive - animated */}
|
||||
<animated.g
|
||||
transform={to(
|
||||
[locomotiveSpring.x, locomotiveSpring.y, locomotiveSpring.rotation],
|
||||
(x, y, rot) => `translate(${x}, ${y}) rotate(${rot}) scale(-1, 1)`
|
||||
)}
|
||||
opacity={locomotiveSpring.opacity}
|
||||
>
|
||||
<text
|
||||
data-element="ghost-locomotive"
|
||||
@@ -179,17 +201,17 @@ export function GhostTrain({
|
||||
>
|
||||
{player.score}
|
||||
</text>
|
||||
</g>
|
||||
</animated.g>
|
||||
|
||||
{/* Ghost cars - each with individual opacity */}
|
||||
{carTransforms.map((car, index) => (
|
||||
<g
|
||||
{/* Ghost cars - each with individual animated opacity and position */}
|
||||
{carSprings.map((spring, index) => (
|
||||
<animated.g
|
||||
key={`car-${index}`}
|
||||
transform={`translate(${car.x}, ${car.y}) rotate(${car.rotation}) scale(-1, 1)`}
|
||||
opacity={car.opacity}
|
||||
style={{
|
||||
transition: 'opacity 0.3s ease-in-out',
|
||||
}}
|
||||
transform={to(
|
||||
[spring.x, spring.y, spring.rotation],
|
||||
(x, y, rot) => `translate(${x}, ${y}) rotate(${rot}) scale(-1, 1)`
|
||||
)}
|
||||
opacity={spring.opacity}
|
||||
>
|
||||
<text
|
||||
data-element={`ghost-car-${index}`}
|
||||
@@ -204,7 +226,7 @@ export function GhostTrain({
|
||||
>
|
||||
🚃
|
||||
</text>
|
||||
</g>
|
||||
</animated.g>
|
||||
))}
|
||||
</g>
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "soroban-monorepo",
|
||||
"version": "4.66.2",
|
||||
"version": "4.67.1",
|
||||
"private": true,
|
||||
"description": "Beautiful Soroban Flashcard Generator - Monorepo",
|
||||
"workspaces": [
|
||||
|
||||
Reference in New Issue
Block a user