Skip to content

Commit 1e597b1

Browse files
authored
Redo puzzle mode animation (#184)
1 parent bb5e227 commit 1e597b1

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

src/components/Game.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function addLastSet(board, lastSet) {
3131
if (lastSet?.length) {
3232
const n = lastSet?.length % 3;
3333
if (n > 0) {
34-
lastSet = lastSet.concat([null]);
34+
lastSet = [...lastSet, null];
3535
if (n === 1) lastSet.splice(-3, 0, null);
3636
}
3737
board = lastSet.concat(board);
@@ -57,13 +57,13 @@ function Game({
5757
const isHorizontal = cardOrientation === "horizontal";
5858
const isLandscape = layoutOrientation === "landscape";
5959
const [gameDimensions, gameEl] = useDimensions();
60-
const [highlightCards, setHighlightCards] = useState(null);
60+
const [movingCards, setMovingCards] = useState(null);
6161

6262
const lastKeptCards = lastKeptSet?.join("|");
6363
useEffect(() => {
64-
setHighlightCards(lastKeptCards?.split("|"));
64+
setMovingCards(lastKeptCards?.split("|").map((card) => " " + card));
6565
if (lastKeptCards) {
66-
const timer = setTimeout(() => setHighlightCards(null), 300);
66+
const timer = setTimeout(() => setMovingCards(null), 0);
6767
return () => clearTimeout(timer);
6868
}
6969
}, [lastKeptCards]);
@@ -117,7 +117,7 @@ function Game({
117117
// NOTE: put rotate into useTransition() instead of adding it to the style
118118
// outside to get a nice animation when cardOrientation changes.
119119
const cardProps = (card) => {
120-
const i = board.indexOf(card);
120+
const i = board.indexOf(card?.trimLeft());
121121
let positionX, positionY;
122122
let r, c;
123123
if (!isLandscape) {
@@ -145,13 +145,16 @@ function Game({
145145
opacity: 1,
146146
};
147147
};
148-
const transitions = useTransition(board, {
149-
from: {
150-
left: -cardWidth,
151-
top: gameHeight / 2 - cardHeight / 2,
152-
rotate: rotateAmount,
153-
opacity: 0,
154-
},
148+
const transitions = useTransition(movingCards?.concat(board) || board, {
149+
from: (card) =>
150+
card?.startsWith(" ")
151+
? cardProps(card)
152+
: {
153+
left: -cardWidth,
154+
top: gameHeight / 2 - cardHeight / 2,
155+
rotate: rotateAmount,
156+
opacity: 0,
157+
},
155158
enter: cardProps,
156159
update: cardProps,
157160
leave: {
@@ -244,7 +247,6 @@ function Game({
244247
(style, card) =>
245248
card && (
246249
<animated.div
247-
key={card}
248250
className={to([style.left, style.top], () =>
249251
style.left.idle && style.top.idle
250252
? classes.staticCard
@@ -273,11 +275,10 @@ function Game({
273275
</div>
274276
) : (
275277
<ResponsiveSetCard
276-
value={card}
278+
value={card.trimLeft()}
277279
width={cardWidth}
278280
hinted={answer?.includes(card)}
279281
active={selected?.includes(card)}
280-
highlight={highlightCards?.includes(card)}
281282
faceDown={
282283
faceDown === "all" ||
283284
(faceDown &&

src/components/KeyboardLayoutDialog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ function KeyboardLayoutDialog(props) {
6363
);
6464
};
6565

66-
const menuItems = Object.keys(standardLayouts)
67-
.concat(["Custom"])
68-
.map((layoutName) => (
66+
const menuItems = [...Object.keys(standardLayouts), "Custom"].map(
67+
(layoutName) => (
6968
<MenuItem key={layoutName} value={layoutName}>
7069
{layoutName}
7170
</MenuItem>
72-
));
71+
)
72+
);
7373

7474
return (
7575
<Dialog open={open} onClose={onClose}>

src/components/ResponsiveSetCard.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ const useStyles = makeStyles((theme) => ({
3131
active: {
3232
boxShadow: "0px 0px 5px 3px #4b9e9e !important",
3333
},
34-
highlight: {
35-
backgroundColor: theme.setCard.highlight,
36-
},
3734
hintedOverlay: {
3835
position: "absolute",
3936
inset: 0,
@@ -73,7 +70,7 @@ function ResponsiveSetCard(props) {
7370
const theme = useTheme();
7471

7572
// Black magic below to scale cards given any width
76-
const { width, value, onClick, hinted, active, highlight, faceDown } = props;
73+
const { width, value, onClick, hinted, active, faceDown } = props;
7774
const height = Math.round(width / 1.6);
7875
const margin = Math.round(width * 0.035);
7976
const contentWidth = width - 2 * margin;
@@ -114,7 +111,6 @@ function ResponsiveSetCard(props) {
114111
className={clsx(classes.card, {
115112
[classes.clickable]: onClick,
116113
[classes.active]: active,
117-
[classes.highlight]: highlight,
118114
})}
119115
style={{
120116
...extraStyle,

src/themes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const darkTheme = createTheme({
5050
orange: "#47b0ff",
5151
background: "#262626",
5252
hinted: "rgba(41, 182, 246, 0.25)",
53-
highlight: "#404040",
5453
backColors: [
5554
grey[900],
5655
grey[800],
@@ -110,7 +109,6 @@ export const lightTheme = createTheme({
110109
orange: "#fb8c00",
111110
background: "#fff",
112111
hinted: "rgba(3, 169, 244, 0.2)",
113-
highlight: "#fffedc",
114112
backColors: [
115113
indigo[600],
116114
indigo[300],

0 commit comments

Comments
 (0)