Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added public/.DS_Store
Binary file not shown.
Binary file added public/breaking-sound/Rooted_Dirt_break1.ogg.mp3
Binary file not shown.
Binary file added public/breaking-sound/Rooted_Dirt_break2.ogg.mp3
Binary file not shown.
Binary file added public/breaking-sound/Rooted_Dirt_break3.ogg.mp3
Binary file not shown.
Binary file added public/breaking-sound/Rooted_Dirt_break4.ogg.mp3
Binary file not shown.
Binary file added public/breaking-sound/orb.mp3
Binary file not shown.
Binary file added public/breaking/destroy_stage_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/breaking/destroy_stage_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/explosion/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pixelbluzzi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions src/app/about.section.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ReactElement } from "react";
import { SocialButton } from "#source/lib/components/social-button";
import { BreakablePhoto } from "#source/lib/components/breakable-photo";

Check failure on line 3 in src/app/about.section.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Expected "#source/lib/components/breakable-photo" to come before "#source/lib/components/social-button"
import { Text } from "#source/lib/components/text";
import Image from "next/image";

export const AboutSection = (): ReactElement => {
return (
Expand All @@ -20,9 +20,7 @@
</div>
</div>

<div className="relative h-32 w-32 rounded-lg rotate-3 hover:-rotate-2 transition-transform hover:border border-white cursor-crosshair shrink-0 max-sm:hidden">
<Image src="/camille.jpg" alt="Profile picture" fill className="rounded-lg" />
</div>
<BreakablePhoto src="/camille.jpg" brokenSrc="/pixelbluzzi.png" alt="Profile picture" />
</div>
);
};
179 changes: 179 additions & 0 deletions src/lib/components/breakable-photo/breakable-photo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
"use client";

import type { BreakablePhotoProps } from "./breakable-photo.type";
import type { ReactElement } from "react";
import { useState, useRef, useCallback, useEffect } from "react";
import Image from "next/image";

Check failure on line 6 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Expected "next/image" to come before "react"

const TOTAL_STAGES = 10;
const STAGE_INTERVAL_MS = 180;
const EXPLOSION_FRAMES = 9;
const EXPLOSION_FRAME_MS = 35;
const SOUND_VOLUME = 0.15;
const ORB_VOLUME = 0.2;

const BREAK_SOUND_PATHS = [
"/breaking-sound/Rooted_Dirt_break1.ogg.mp3",
"/breaking-sound/Rooted_Dirt_break2.ogg.mp3",
"/breaking-sound/Rooted_Dirt_break3.ogg.mp3",
"/breaking-sound/Rooted_Dirt_break4.ogg.mp3",
];

const BREAKING_IMAGE_PATHS = Array.from({ length: TOTAL_STAGES }, (_, i) => `/breaking/destroy_stage_${i}.png`);

Check failure on line 22 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Invalid type "number" of template literal expression
const EXPLOSION_IMAGE_PATHS = Array.from({ length: EXPLOSION_FRAMES }, (_, i) => `/explosion/${i + 1}.png`);

Check failure on line 23 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Invalid type "number" of template literal expression

const preloadImage = (src: string): void => {
const img = new globalThis.Image();
img.src = src;
};

const preloadAudio = (src: string): HTMLAudioElement => {
const audio = new Audio(src);
audio.load();
return audio;
};

export const BreakablePhoto = ({ src, brokenSrc, alt }: BreakablePhotoProps): ReactElement => {
const [stage, setStage] = useState(0);
const [isBroken, setIsBroken] = useState(false);
const [explosionFrame, setExplosionFrame] = useState<number | null>(null);

const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
const stageRef = useRef(0);
const breakSoundsRef = useRef<HTMLAudioElement[]>([]);
const orbSoundRef = useRef<HTMLAudioElement | null>(null);

// --- Preload all assets on mount ---

useEffect(() => {
breakSoundsRef.current = BREAK_SOUND_PATHS.map(preloadAudio);
orbSoundRef.current = preloadAudio("/breaking-sound/orb.mp3");

BREAKING_IMAGE_PATHS.forEach(preloadImage);

Check failure on line 52 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

`forEach` is more limited than a for loop as it doesn't support `break` for early exits or return values for chaining operations
EXPLOSION_IMAGE_PATHS.forEach(preloadImage);

Check failure on line 53 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

`forEach` is more limited than a for loop as it doesn't support `break` for early exits or return values for chaining operations
preloadImage(brokenSrc);
}, [brokenSrc]);

// --- Sound ---

const playBreakSound = useCallback(() => {
const source = breakSoundsRef.current[Math.floor(Math.random() * breakSoundsRef.current.length)];
const clone = source.cloneNode() as HTMLAudioElement;
clone.volume = SOUND_VOLUME;
clone.play().catch(() => {});

Check failure on line 63 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected empty arrow function
}, []);

// --- Explosion ---

const playExplosion = useCallback(() => {
let frame = 1;
setExplosionFrame(frame);

const tick = setInterval(() => {
frame += 1;

if (frame > EXPLOSION_FRAMES) {
clearInterval(tick);
setExplosionFrame(null);
return;
}

setExplosionFrame(frame);
}, EXPLOSION_FRAME_MS);
}, []);

// --- Breaking logic ---

const stopInterval = useCallback(() => {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
}, []);

const breakBlock = useCallback(() => {
stopInterval();
playExplosion();
setIsBroken(true);
setStage(0);

if (orbSoundRef.current) {
const orb = orbSoundRef.current.cloneNode() as HTMLAudioElement;
orb.volume = ORB_VOLUME;
orb.play().catch(() => {});

Check failure on line 103 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected empty arrow function
}
}, [stopInterval, playExplosion]);

const startBreaking = useCallback(() => {
if (isBroken || intervalRef.current) return;

stageRef.current = 0;
setStage(0);
playBreakSound();

intervalRef.current = setInterval(() => {
stageRef.current += 1;

if (stageRef.current >= TOTAL_STAGES) {
breakBlock();
return;
}

playBreakSound();
setStage(stageRef.current);
}, STAGE_INTERVAL_MS);
}, [isBroken, breakBlock, playBreakSound]);

const cancelBreaking = useCallback(() => {
stopInterval();
if (!isBroken) {
stageRef.current = 0;
setStage(0);
}
}, [isBroken, stopInterval]);

useEffect(() => {
return () => stopInterval();
}, [stopInterval]);

return (
<div
className="relative h-32 w-32 shrink-0 max-sm:hidden select-none"
onMouseDown={startBreaking}
onMouseUp={cancelBreaking}
onMouseLeave={cancelBreaking}
onTouchStart={startBreaking}
onTouchEnd={cancelBreaking}
>
<div className={`relative h-full w-full rounded-lg rotate-3 hover:-rotate-2 transition-transform cursor-crosshair overflow-hidden ${!isBroken ? "hover:border border-white" : ""}`}>
<Image
src={isBroken ? brokenSrc : src}
alt={alt}
fill
className="rounded-lg pointer-events-none"
draggable={false}
/>

{stage > 0 && !isBroken && (
<img

Check warning on line 158 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
src={`/breaking/destroy_stage_${stage - 1}.png`}

Check failure on line 159 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Invalid type "number" of template literal expression
alt=""
className="absolute inset-0 h-full w-full pointer-events-none z-10"
style={{ imageRendering: "pixelated" }}
draggable={false}
/>
)}
</div>

{explosionFrame !== null && (
<img

Check warning on line 169 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
src={`/explosion/${explosionFrame}.png`}

Check failure on line 170 in src/lib/components/breakable-photo/breakable-photo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Invalid type "number" of template literal expression
alt=""
className="absolute inset-0 h-full w-full pointer-events-none z-20 scale-200"
style={{ imageRendering: "pixelated" }}
draggable={false}
/>
)}
</div>
);
};
5 changes: 5 additions & 0 deletions src/lib/components/breakable-photo/breakable-photo.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type BreakablePhotoProps = {
src: string;
brokenSrc: string;
alt: string;
};
1 change: 1 addition & 0 deletions src/lib/components/breakable-photo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BreakablePhoto } from "./breakable-photo";
1 change: 1 addition & 0 deletions src/lib/styles/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
--radius: 0.25rem;
--radius-lg: 0.5rem;
--radius-full: 9999px;

}
Loading