Skip to content

Commit 72ca388

Browse files
committed
feat: implement Netliclicker
1 parent 1d52a46 commit 72ca388

File tree

4 files changed

+110
-224
lines changed

4 files changed

+110
-224
lines changed

src/ui/components.tsx/Disk.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ui/components.tsx/Game.tsx

Lines changed: 110 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,116 @@
1-
import React from "react";
2-
import { Level } from "./Level";
1+
import { useMemo, useState } from "react";
2+
import { Button, ButtonGroup, Card } from "@netlify/sdk/ui/react/components";
3+
4+
const NETLIFY_EPOCH = new Date("2014-11-09");
5+
const SECONDS_SINCE_NETLIFY_EPOCH =
6+
(Date.now() - NETLIFY_EPOCH.getTime()) / 1000;
7+
8+
const CONFIG = {
9+
levels: [
10+
{
11+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60 / 60 / 24 / 365), // ~10
12+
multiplier: 2,
13+
},
14+
{
15+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60 / 60 / 24 / 30), // ~100
16+
multiplier: 2,
17+
},
18+
{
19+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60 / 60 / 24 / 7), // ~500
20+
multiplier: 4,
21+
},
22+
{
23+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60 / 60 / 24), // ~4K
24+
multiplier: 4,
25+
},
26+
{
27+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60 / 60), // ~100K
28+
multiplier: 8,
29+
},
30+
{
31+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH / 60), // ~5M
32+
multiplier: 16,
33+
},
34+
{
35+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH), // ~300M
36+
multiplier: 32,
37+
},
38+
{
39+
threshold: Math.floor(SECONDS_SINCE_NETLIFY_EPOCH) * 1000, // ~300B
40+
multiplier: 1024,
41+
},
42+
{
43+
threshold: Number.MAX_SAFE_INTEGER,
44+
multiplier: 1,
45+
},
46+
],
47+
};
48+
49+
const ClickerButtonGroup = ({
50+
completedLevels,
51+
onClick,
52+
}: {
53+
completedLevels: typeof CONFIG.levels;
54+
onClick: (count: number) => void;
55+
}) => {
56+
const multipliers = useMemo(
57+
() =>
58+
completedLevels
59+
.reduce(
60+
(acc, { multiplier }) => [
61+
...acc,
62+
(acc[acc.length - 1] ?? 1) * multiplier,
63+
],
64+
[] as number[],
65+
)
66+
.reverse(),
67+
[completedLevels],
68+
);
69+
70+
return (
71+
<ButtonGroup>
72+
{multipliers.map((multiplier, index) => (
73+
<Button key={index} onClick={() => onClick(multiplier)}>
74+
Click {multiplier}x
75+
</Button>
76+
))}
77+
</ButtonGroup>
78+
);
79+
};
380

481
export const Game = () => {
5-
const [challenge, setChallenge] = React.useState(3);
82+
const [clickCount, setClickCount] = useState(0);
83+
const [remainingLevels, setRemainingLevels] = useState([...CONFIG.levels]);
84+
const [completedLevels, setCompletedLevels] = useState([
85+
{ threshold: 0, multiplier: 1 },
86+
]);
87+
88+
const handleClick = (count: number) => {
89+
setClickCount((prev) => {
90+
const cur = prev + count;
91+
92+
for (const level of remainingLevels) {
93+
if (cur >= level.threshold) {
94+
setCompletedLevels((prev) => [...prev, level]);
95+
setRemainingLevels((prev) => prev.slice(1));
96+
}
97+
}
98+
99+
return cur;
100+
});
101+
};
6102

7103
return (
8-
<Level
9-
key={challenge}
10-
challenge={challenge}
11-
onNextLevel={() => {
12-
setChallenge(challenge + 1);
13-
}}
14-
/>
104+
<>
105+
<Card className="tw-text-center tw-text-xl">
106+
Clicks: <span className="tw-font-bold">{clickCount}</span>
107+
</Card>
108+
<Card>
109+
<ClickerButtonGroup
110+
completedLevels={completedLevels}
111+
onClick={handleClick}
112+
/>
113+
</Card>
114+
</>
15115
);
16116
};

src/ui/components.tsx/Level.tsx

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/ui/components.tsx/Rod.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)