Skip to content

Commit e995d09

Browse files
committed
feat(thermite): used next/image to render the assets
1 parent cc6b539 commit e995d09

File tree

11 files changed

+59
-34
lines changed

11 files changed

+59
-34
lines changed

app/page.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import Image from "next/image";
22
import Link from "next/link";
33

4+
import { thermiteImg } from "@/public/images/puzzles";
5+
46
const puzzles = [
57
{
68
href: "/puzzles/thermite",
7-
img: "" /* TODO: add preview image */,
9+
img: thermiteImg,
810
title: "Thermite",
911
description:
1012
"Replica of the Thermite hack that is triggered when disabling lasers inside the Maze Bank on NoPixel 4.0",

app/puzzles/thermite/Thermite.tsx

+24-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import { NPSettingsRange } from "@/app/components/NPSettings";
1818
import NPButton from "@/app/components/NPButton";
1919
import usePersistantState from "@/app/utils/usePersistentState";
2020

21+
import Image from "next/image";
22+
import crossImg from "@/public/images/thermite/cross.svg";
23+
import backgroundImg from "@/public/images/thermite/background.svg";
24+
2125
import "@/app/puzzles/thermite/style.css";
2226

2327
const Thermite: FC = () => {
@@ -67,6 +71,7 @@ const Thermite: FC = () => {
6771
setComboCounter(0);
6872
setLastKillTimestamp(-1);
6973
setTotalCombos(0);
74+
setOutOfMoves(false);
7075
}, [columns, rows]);
7176

7277
/**
@@ -78,7 +83,6 @@ const Thermite: FC = () => {
7883
(newStatus: number): void => {
7984
switch (newStatus) {
8085
case 1:
81-
setOutOfMoves(false);
8286
setResetAnimation(false);
8387
resetBoard();
8488
break;
@@ -152,28 +156,17 @@ const Thermite: FC = () => {
152156
const [targetRow, targetCol] = targetCoord;
153157
const [attackerRow, attackerCol] = attackerCoord;
154158

155-
let distance = 1;
156-
switch (attackerPiece) {
157-
case "long":
158-
distance = 3;
159-
break;
160-
case "medium":
161-
distance = 2;
162-
break;
163-
case "short":
164-
distance = 1;
165-
break;
166-
}
167-
168159
/**
169160
* I'm pretty sure there's a much more clever way to code this
170161
* condition but I was born dumb.
171162
*/
172163
return (
173-
targetCol % distance === attackerCol % distance &&
174-
targetRow % distance === attackerRow % distance &&
175-
Math.abs(targetCol - attackerCol) <= distance &&
176-
Math.abs(targetRow - attackerRow) <= distance
164+
targetCol % attackerPiece.distance ===
165+
attackerCol % attackerPiece.distance &&
166+
targetRow % attackerPiece.distance ===
167+
attackerRow % attackerPiece.distance &&
168+
Math.abs(targetCol - attackerCol) <= attackerPiece.distance &&
169+
Math.abs(targetRow - attackerRow) <= attackerPiece.distance
177170
);
178171
},
179172
[]
@@ -346,8 +339,8 @@ const Thermite: FC = () => {
346339
title={"Target score"}
347340
value={settingsTargetScore}
348341
setValue={setSettingsTargetScore}
349-
min={14}
350-
max={38}
342+
min={10}
343+
max={75}
351344
/>
352345
<NPSettingsRange
353346
title={"Timer"}
@@ -469,13 +462,18 @@ const Thermite: FC = () => {
469462
onClick={() => handleClick([rowIndex, columnIndex])}
470463
>
471464
<span className="piece">
472-
<embed src={`/images/thermite-${square.piece}.svg`} />
465+
<Image
466+
src={square.piece.img}
467+
alt=""
468+
width={75}
469+
height={75}
470+
/>
473471
</span>
474472
<div className="crosses">
475-
<embed src={`/images/thermite-cross.svg`} />
476-
<embed src={`/images/thermite-cross.svg`} />
477-
<embed src={`/images/thermite-cross.svg`} />
478-
<embed src={`/images/thermite-cross.svg`} />
473+
<Image src={crossImg} alt="" width={16} height={16} />
474+
<Image src={crossImg} alt="" width={16} height={16} />
475+
<Image src={crossImg} alt="" width={16} height={16} />
476+
<Image src={crossImg} alt="" width={16} height={16} />
479477
</div>
480478
<div
481479
className="highlight"
@@ -497,7 +495,7 @@ const Thermite: FC = () => {
497495
CRC Bypassed!
498496
</span>
499497
</div>
500-
<embed className="background" src={`/images/bg-circuit.svg`} />
498+
<Image src={backgroundImg} alt="" fill />
501499
</Fragment>
502500
</div>
503501
</NPHackContainer>

app/puzzles/thermite/style.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
.piece {
2929
@apply w-full h-full p-[25%];
30-
31-
embed {
32-
@apply relative w-full h-full z-20 pointer-events-none;
33-
}
3430
}
3531

3632
.crosses {
3733
@apply absolute size-full grid grid-rows-[min-content_min-content] grid-cols-[min-content_min-content] justify-between content-between p-1 opacity-30;
34+
35+
img {
36+
@apply max-w-none;
37+
}
3838
}
3939

4040
.highlight {

app/puzzles/thermite/utils.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1-
export type SquarePiece = "short" | "medium" | "long";
2-
export const squarePieces: SquarePiece[] = ["short", "medium", "long"];
1+
import shortImg from "@/public/images/thermite/short.svg";
2+
import mediumImg from "@/public/images/thermite/medium.svg";
3+
import longImg from "@/public/images/thermite/long.svg";
4+
5+
export type PieceType = "short" | "medium" | "long";
6+
export type SquarePiece = {type: PieceType, distance: number, img: any};
7+
const squarePieces: SquarePiece[] = [
8+
{
9+
type: "short",
10+
distance: 1,
11+
img: shortImg,
12+
},
13+
{
14+
type: "medium",
15+
distance: 2,
16+
img: mediumImg,
17+
},
18+
{
19+
type: "long",
20+
distance: 3,
21+
img: longImg,
22+
},
23+
];
24+
325
export type SquareStatus = "full" | "half" | "empty";
426
export type Square = {
527
piece: SquarePiece,
@@ -31,7 +53,7 @@ export const presets = [
3153
];
3254
export const initialBoard: GridRow[] = new Array(presets[0].rows).fill(
3355
new Array(presets[0].columns).fill({
34-
piece: "short",
56+
piece: squarePieces[0],
3557
status: "full",
3658
highlighted: false,
3759
})

public/images/puzzles/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import thermiteImg from "./thermite.png";
2+
3+
export {thermiteImg};

public/images/puzzles/thermite.png

862 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)