Skip to content

Commit 5d6438b

Browse files
committed
Updated secrets
1 parent 3cb05da commit 5d6438b

9 files changed

Lines changed: 147 additions & 95 deletions

File tree

‎src/components/background/BackgroundView.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
import React, { useEffect, useRef, useState } from 'react';
44
import { useSecret } from '@context/SecretContext';
5-
import PixelatedBackground from '@components/background/PixelatedBackground';
5+
import SecretBackground from '@src/components/background/SecretBackground';
66
import WebGlBackground from '@components/background/webGlBackground';
77

88
export default function BackgroundView() {
99

10-
const { isMissingNoSecretActive } = useSecret();
10+
const [isSecretBg, setIsSecretBg] = useState(false);
11+
12+
// if konami, missingno, or 404 secrets are active, use the PixelatedBackground
13+
// otherwise default to WebGlBackground
14+
const { isKonamiSecretActive, isMissingNoSecretActive, is404SecretActive } = useSecret();
15+
16+
useEffect(() => {
17+
const secretBg = isKonamiSecretActive || isMissingNoSecretActive || is404SecretActive;
18+
setIsSecretBg(secretBg);
19+
}, [isKonamiSecretActive, isMissingNoSecretActive, is404SecretActive]);
1120

1221
return (
1322
<>
14-
{isMissingNoSecretActive
15-
? <PixelatedBackground />
23+
{isSecretBg
24+
? <SecretBackground />
1625
: <WebGlBackground />}
1726
</>
1827
);

src/components/background/PixelatedBackground.tsx renamed to src/components/background/SecretBackground.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use client';
22

3-
import React, { useEffect, useRef } from 'react';
4-
import "./pixelatedBackground.css";
3+
import React, { useEffect, useRef, useState } from 'react';
4+
import "./secretBackground.css";
55
import { useSecret } from '@src/context/SecretContext';
66

7-
export default function PixelatedBackground() {
7+
export default function SecretBackground() {
88
const canvasRef = useRef<HTMLCanvasElement | null>(null);
99
const contextRef = useRef<WebGLRenderingContext | null>(null);
1010
const shaderProgramRef = useRef<WebGLProgram | null>(null);
@@ -13,7 +13,8 @@ export default function PixelatedBackground() {
1313
const resolutionUniformLocationRef = useRef<WebGLUniformLocation | null>(null);
1414
const positionBufferRef = useRef<WebGLBuffer | null>(null);
1515
const frameRef = useRef<number | null>(null);
16-
const { isMissingNoSecretActive, is404SecretActive } = useSecret();
16+
const { isMissingNoSecretActive, is404SecretActive, isKonamiSecretActive } = useSecret();
17+
const [fsSource, setFsSource] = useState<string | null>(null);
1718

1819
// 2. Define Vertex Shader (Draws a full-screen quad)
1920
const vsSource = `
@@ -179,7 +180,28 @@ void main() {
179180
}
180181
`;
181182

182-
// Render loop
183+
// sets the current fsSource based on which secret is active
184+
useEffect(() => {
185+
186+
let source;
187+
188+
if (is404SecretActive) {
189+
// 404
190+
source = sh1fsSource;
191+
}
192+
else if (isMissingNoSecretActive) {
193+
// missingno
194+
source = missingNofsSource;
195+
}
196+
else {
197+
// konami
198+
source = defaultfsSource;
199+
}
200+
201+
setFsSource(source);
202+
203+
}, [isKonamiSecretActive, is404SecretActive, isMissingNoSecretActive]);
204+
183205
function render(time: number) {
184206
const canvas = canvasRef.current;
185207
if (!canvas) return;
@@ -215,18 +237,7 @@ void main() {
215237
if (!canvas) return;
216238
const gl = contextRef.current;
217239
if (!gl) return;
218-
219-
let fsSource;
220-
221-
if (is404SecretActive) {
222-
fsSource = sh1fsSource;
223-
}
224-
else if (isMissingNoSecretActive) {
225-
fsSource = missingNofsSource;
226-
}
227-
else {
228-
fsSource = defaultfsSource;
229-
}
240+
if (!fsSource) return;
230241

231242
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vsSource);
232243
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fsSource);
@@ -328,7 +339,7 @@ void main() {
328339
}
329340
contextRef.current = null;
330341
};
331-
}, []);
342+
}, [fsSource]);
332343

333344
return (
334345
<canvas
File renamed without changes.

‎src/components/modal/views/about.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const AboutView = () => {
7676
{
7777
Object.entries(displayItems).map(([key, value]) => (
7878
<tr className="" key={key}>
79-
<th scope="row" className="px-3 py-2.5 text-sm md:text-base text-gray-300 whitespace-nowrap dark:text-gray-300 text-right">
79+
<th scope="row" className="px-3 py-2.5 text-sm md:text-base text-gray-300 whitespace-nowrap dark:text-gray-300 text-right align-baseline">
8080
<span className="inline-block align-baseline select-none">{key}</span>
8181
</th>
8282
<td className="px-3 py-2.5 text-wrap whitespace-normal text-left text-sm md:text-base -indent-4 md:indent-0">

‎src/components/modal/views/help.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tr:not(.content-center) > :first-child {
1+
.modal-content-help tr:not(.content-center) > :first-child {
22
text-align: right;
33
display: flex;
44
justify-content: end;

‎src/components/modal/views/help.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import { Type } from "typescript";
103103

104104
export const HelpView = () => {
105105
return (
106-
<div className="grid h-full">
106+
<div className="modal-content modal-content-help grid h-full">
107107
<div className="modal-content content-center justify-items-center items-center mx-auto max-h-full overflow-y-scroll my-2">
108108
<table className="text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 max-w-[600px]">
109109
<thead className="text-xs text-gray-400 uppercase items-center relative">

‎src/components/modal/views/secrets.tsx‎

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
"use client";
22

33
import React, { useCallback, useEffect, useRef, useState } from "react";
4-
import { useSecret, StatDefinition, PlayerStat, AchievementId, SecretGroupType } from "@context/SecretContext";
4+
import { useSecret, PlayerStat, AchievementId, SecretGroupType } from "@context/SecretContext";
55
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
66
import { faQuestionCircle, faLock, faUnlock, faUnlockAlt, faCheck, faCheckCircle, faToggleOff, faToggleOn, IconDefinition, faMinus } from "@fortawesome/free-solid-svg-icons";
77
import "./secrets.css";
88

9-
export interface SecretsViewProps
10-
{
11-
title: string;
12-
description?: string;
13-
}
9+
const SECRET_TAP_MIN = 5;
1410

1511
export interface SecretViewProps
1612
{
1713
id: AchievementId,
1814
stat: PlayerStat;
1915
}
2016

21-
const SECRET_TAP_MIN = 5;
22-
2317
const SecretView = ({ id, stat }: SecretViewProps) => {
2418

2519
const { secrets, setSecretEnabled, isSecretUnlocked, isSecretEnabled, lockSecret, unlockSecret, stats } = useSecret();
@@ -93,17 +87,19 @@ const SecretView = ({ id, stat }: SecretViewProps) => {
9387
}, [unlocked]);
9488

9589
return (
96-
<>
97-
<tr key={id} className="">
98-
<td className={`border-b border-gray-400/25 text-center ${unlocked ? 'bg-green-300/50' : 'bg-gray-700'} pointer-events-none select-none`}>
90+
<React.Fragment key={id}>
91+
<tr>
92+
<td className={`border-b border-gray-400/25 text-center ${unlocked ? 'bg-green-300/50' : 'bg-gray-800'} pointer-events-none select-none justify-center items-center`}>
9993
<FontAwesomeIcon icon={stat.isUnlocked ? faUnlockAlt : faLock}
100-
className={`py-3 w-full h-full mx-auto`} size="xl" />
94+
className={`py-3 w-full h-full mx-3`} size="lg" />
10195
</td>
10296
<td className={`border border-gray-300/25 text-ellipsis text-nowrap text-xs md:text-lg px-2 ${!unlocked && 'text-gray-400'}`}
10397
ref={elementRef}>
104-
{unlocked ? secret.title : 'Hidden'}
98+
<span className="pointer-events-none select-none">
99+
{unlocked ? secret.title : 'Hidden'}
100+
</span>
105101
</td>
106-
<td className={`border border-gray-300/25 text-ellipsis text-nowrap text-xs md:text-lg px-2 ${!unlocked && 'text-gray-400'} pointer-events-none select-none`}>
102+
<td className={`border border-gray-300/25 text-wrap text-xs md:text-lg px-2 ${!unlocked && 'text-gray-400'} pointer-events-none select-none`}>
107103
{unlocked ? secret.description : 'Hidden'}
108104
</td>
109105
<td className={`border border-gray-300/25 ${enabled && 'bg-green-300/50'}`}>
@@ -117,33 +113,30 @@ const SecretView = ({ id, stat }: SecretViewProps) => {
117113
)
118114
}
119115
</div>
120-
{/* <button onClick={toggleEnabled} className={`${enabled ? 'bg-green-300' : 'bg-gray-500'} w-full h-full text-white`}>
121-
{icon && <FontAwesomeIcon icon={icon} />}
122-
</button> */}
123116
</td>
124117
</tr>
125-
</>
118+
</React.Fragment>
126119
);
127120

128121
};
129122

130-
export const SecretsView = ({ title, description }: SecretsViewProps) => {
123+
export const SecretsView = () => {
131124

132125
const { stats, secrets, secretGroups } = useSecret();
133126

134127
return (
135128
<>
136-
<div className="w-full h-full text-white my-auto">
137-
<table className="table-auto border-collapse mx-auto w-full my-auto">
138-
<thead className="">
129+
<div className="modal-content modal-content-secrets text-white h-full lg:m-4">
130+
<table className="table-auto border-collapse mx-auto w-full">
131+
<thead className="bg-gray-600/40">
139132
<tr className="content-center">
140-
<th className=" bg-gray-800 text-sm md:text-md border border-gray-400/25">
141-
<FontAwesomeIcon icon={faQuestionCircle} className="m-2 p-1 w-full h-full mx-auto my-auto" size="xl"
142-
aria-label="Status" />
133+
<th className=" text-sm md:text-lg border border-gray-400/25">
134+
{/* <FontAwesomeIcon icon={faQuestionCircle} className="m-2 p-1 w-full h-full mx-auto my-auto" size="xl"
135+
aria-label="Status" /> */}
143136
</th>
144-
<th className="p-2 bg-gray-800 text-sm border border-gray-400/25">Name</th>
145-
<th className="p-2 bg-gray-800 text-sm border border-gray-400/25">Description</th>
146-
<th className="p-2 bg-gray-800 text-sm border border-gray-400/25">Enabled</th>
137+
<th className="p-2 text-sm md:text-lg border border-gray-400/25">Name</th>
138+
<th className="p-2 text-sm md:text-lg border border-gray-400/25">Description</th>
139+
<th className="p-2 text-sm md:text-lg border border-gray-400/25">Enabled</th>
147140
</tr>
148141
</thead>
149142
<tbody className="bg-gray-600/40">
@@ -156,22 +149,23 @@ export const SecretsView = ({ title, description }: SecretsViewProps) => {
156149
if (type === 'default') return stat[1].stat.type === undefined;
157150
return stat[1].stat.type === type;
158151
});
159-
return <>
160-
<tr className="text-xl secret-group-title my-2 text-left">
161-
<td colSpan={3} className="text-xl py-2">
162-
<div className="text-left w-full h-full pl-2">
152+
return (
153+
<React.Fragment key={g}>
154+
<tr className="bg-gray-600/40">
155+
<td />
156+
<th className="md:text-xl py-2 pl-2 text-left align-middle pointer-events-none select-none" colSpan={4}>
163157
{group.title}
164-
</div>
165-
</td>
166-
</tr>
167-
{
168-
items && items.map(([id, stat]) => {
169-
return (
170-
<SecretView key={id} id={id} stat={stat} />
171-
);
172-
})
173-
}
174-
</>;
158+
</th>
159+
</tr>
160+
{
161+
items && items.map(([id, stat]) => {
162+
return (
163+
<SecretView key={id} id={id} stat={stat} />
164+
);
165+
})
166+
}
167+
</React.Fragment>
168+
);
175169
})
176170
}
177171
</tbody>

‎src/context/SecretContext.tsx‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ export interface SecretContextType {
149149
isMissingNoSecretActive: boolean;
150150

151151
isSecretUnlocked: (id: AchievementId) => boolean;
152-
setSecretUnlocked: (id: AchievementId, isUnlocked: boolean) => void;
152+
setSecretUnlocked: (id: AchievementId, isUnlocked: boolean, refresh?: boolean) => void;
153153
isSecretEnabled: (id: AchievementId) => boolean;
154-
setSecretEnabled: (id: AchievementId, isEnabled: boolean) => void;
154+
setSecretEnabled: (id: AchievementId, isEnabled: boolean, refresh?: boolean) => void;
155155
lockSecret: (id: AchievementId) => Promise<void>;
156156
unlockSecret: (id: AchievementId) => Promise<void>;
157157
toggleSecret: (id: AchievementId) => Promise<void>;
@@ -196,12 +196,13 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
196196
return value === 'true';
197197
};
198198

199-
const setSecretUnlocked = useCallback((id: AchievementId, isUnlocked: boolean) => {
199+
const setSecretUnlocked = (id: AchievementId, isUnlocked: boolean, refresh: boolean = true) => {
200200
const settingName = getUnlockedKey(id);
201201
localStorage.setItem(settingName, isUnlocked ? 'true' : 'false');
202202

203-
refreshStats();
204-
}, [stats]);
203+
if (refresh)
204+
refreshStats();
205+
};
205206

206207
const isSecretEnabled = (id: AchievementId) => {
207208
const settingName = getEnabledKey(id);
@@ -210,12 +211,13 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
210211
return value === 'true';
211212
};
212213

213-
const setSecretEnabled = useCallback((id: AchievementId, isEnabled: boolean) => {
214+
const setSecretEnabled = (id: AchievementId, isEnabled: boolean, refresh: boolean = true) => {
214215
const settingName = getEnabledKey(id);
215216
localStorage.setItem(settingName, isEnabled ? 'true' : 'false');
216217

217-
refreshStats();
218-
}, [stats]);
218+
if (refresh)
219+
refreshStats();
220+
};
219221

220222
const lockSecret = useCallback(async (id: AchievementId) => {
221223

@@ -229,7 +231,7 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
229231

230232
const secret = secrets[id];
231233
const variant: SnackbarVariant = 'lock';
232-
showSnackbar(`Secret ${secret.title} Locked`, undefined, variant);
234+
showSnackbar(`Secret Locked`, `'${secret.title}' is now locked.`, variant);
233235

234236
if (id === AchievementId.konami_code) {
235237
setIsKonamiSecretUnlocked(false);
@@ -278,7 +280,7 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
278280
setSecretEnabled(id, true);
279281

280282
const secret = secrets[id];
281-
showSnackbar(`Secret ${secret.title} Unlocked`, secret.description, 'unlock');
283+
showSnackbar(`Secret Unlocked`, `${secret.description}`, 'unlock');
282284

283285
play(SECRET_AUDIO_SRC);
284286

@@ -330,7 +332,7 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
330332
const action = newState ? 'Enabled' : 'Disabled';
331333
const variant: SnackbarVariant = newState ? 'enable' : 'disable';
332334

333-
showSnackbar(`Secret ${id} ${action}`, variant);
335+
showSnackbar(`Secret ${action}`, `'${id}' is now disabled.`, variant);
334336

335337
// save the new setting value
336338
setSecretEnabled(id, newState);
@@ -397,6 +399,40 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
397399
setStats(playerStats);
398400
};
399401

402+
// only allow one bg to be active at a time
403+
useEffect(() => {
404+
if (isKonamiSecretActive) {
405+
setSecretEnabled(AchievementId.missing_no, false, false);
406+
setIsMissingNoSecretActive(false);
407+
setSecretEnabled(AchievementId._404, false, false);
408+
setIs404SecretActive(false);
409+
}
410+
411+
refreshStats();
412+
}, [isKonamiSecretActive]);
413+
414+
useEffect(() => {
415+
if (isMissingNoSecretActive) {
416+
setSecretEnabled(AchievementId.konami_code, false, false);
417+
setIsKonamiSecretActive(false);
418+
setSecretEnabled(AchievementId._404, false, false);
419+
setIs404SecretActive(false);
420+
}
421+
422+
refreshStats();
423+
}, [isMissingNoSecretActive]);
424+
425+
useEffect(() => {
426+
if (is404SecretActive) {
427+
setSecretEnabled(AchievementId.konami_code, false, false);
428+
setIsKonamiSecretActive(false);
429+
setSecretEnabled(AchievementId.missing_no, false, false);
430+
setIsMissingNoSecretActive(false);
431+
}
432+
433+
refreshStats();
434+
}, [is404SecretActive]);
435+
400436
useKeySequence(KONAMI_CODE, () => {
401437
unlockSecret(AchievementId.konami_code);
402438
});

0 commit comments

Comments
 (0)