feat: debug panel with force unlocks and hard reset (#65)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m5s
CI / Lint, Build & Test (push) Successful in 1m10s

## Summary
- Adds a new **Debug** tab to the game UI with two self-service tools for players with broken save state
- **Force Unlocks**: scans the player's save and grants any zones, quests, bosses, and exploration areas they've earned but that are still locked — shows a breakdown of what was unlocked (or reports nothing needed fixing)
- **Hard Reset**: wipes progress back to a fresh save (preserving lifetime stats), guarded behind a confirmation modal to prevent accidental clicks

## Files added
- `apps/api/src/routes/debug.ts` — two POST endpoints (`/force-unlocks`, `/hard-reset`)
- `apps/web/src/components/game/debugPanel.tsx` — the Debug tab UI
- `apps/web/src/components/ui/confirmationModal.tsx` — reusable confirmation modal

## Files modified
- `apps/api/src/index.ts` — registers the debug router
- `packages/types/src/interfaces/api.ts` — adds `ForceUnlocksResponse` type
- `packages/types/src/index.ts` — exports the new type
- `apps/web/src/api/client.ts` — adds `forceUnlocks()` and `debugHardReset()` API calls
- `apps/web/src/context/gameContext.tsx` — wires both functions into game context
- `apps/web/src/components/game/gameLayout.tsx` — adds the Debug tab
- `apps/web/src/styles.css` — styles for action buttons, cards, result messages, and confirmation modal

 This PR was created with help from Hikari~ 🌸

Reviewed-on: #65
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #65.
This commit is contained in:
2026-03-18 12:37:06 -07:00
committed by Naomi Carrigan
parent 219d299e9f
commit 03b6c847b3
11 changed files with 1327 additions and 1 deletions
+145
View File
@@ -0,0 +1,145 @@
/**
* @file Debug panel component with administrative tools for correcting player state.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Panel has multiple async handlers and conditional renders */
/* eslint-disable stylistic/max-len -- Debug descriptions require full explanatory text */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { ConfirmationModal } from "../ui/confirmationModal.js";
type ActiveModal = "force-unlocks" | "hard-reset" | null;
/**
* Renders the debug panel with tools for fixing stuck game state.
* @returns The JSX element.
*/
const DebugPanel = (): JSX.Element => {
const { forceUnlocks, debugHardReset, isLoading } = useGame();
const [ activeModal, setActiveModal ] = useState<ActiveModal>(null);
const [ forceUnlocksResult, setForceUnlocksResult ] = useState<string | null>(null);
function handleOpenForceUnlocks(): void {
setForceUnlocksResult(null);
setActiveModal("force-unlocks");
}
function handleOpenHardReset(): void {
setActiveModal("hard-reset");
}
function handleCancel(): void {
setActiveModal(null);
}
function handleConfirmForceUnlocks(): void {
setActiveModal(null);
void (async(): Promise<void> => {
const result = await forceUnlocks();
const parts: Array<string> = [];
if (result.zonesUnlocked > 0) {
parts.push(`${String(result.zonesUnlocked)} zone(s)`);
}
if (result.questsUnlocked > 0) {
parts.push(`${String(result.questsUnlocked)} quest(s)`);
}
if (result.bossesUnlocked > 0) {
parts.push(`${String(result.bossesUnlocked)} boss(es)`);
}
if (result.explorationUnlocked > 0) {
parts.push(`${String(result.explorationUnlocked)} exploration area(s)`);
}
const total
= result.zonesUnlocked
+ result.questsUnlocked
+ result.bossesUnlocked
+ result.explorationUnlocked;
const message
= parts.length === 0
? "Everything looks correct — no missing unlocks were found."
: `Fixed ${String(total)} unlock(s): ${parts.join(", ")}.`;
setForceUnlocksResult(message);
})();
}
function handleConfirmHardReset(): void {
setActiveModal(null);
void debugHardReset();
}
return (
<div className="panel">
<h2>{"🔧 Debug Tools"}</h2>
<p className="panel-description">
{
"These tools are intended to fix broken game state. Use them with care — some operations are irreversible."
}
</p>
<div className="debug-actions">
<div className="debug-action-card">
<h3>{"🔓 Force Unlocks"}</h3>
<p>
{
"Scans your game state and unlocks any zones, quests, and bosses that you have earned but that are still incorrectly locked."
}
</p>
<button
className="action-button"
disabled={isLoading}
onClick={handleOpenForceUnlocks}
type="button"
>
{"Force Unlocks"}
</button>
{forceUnlocksResult !== null
&& <p className="debug-result-message">{forceUnlocksResult}</p>
}
</div>
<div className="debug-action-card">
<h3>{"💀 Hard Reset"}</h3>
<p>
{
"Completely wipes all progress and resets your account to a brand-new state. This cannot be undone."
}
</p>
<button
className="action-button action-button-danger"
disabled={isLoading}
onClick={handleOpenHardReset}
type="button"
>
{"Hard Reset"}
</button>
</div>
</div>
{activeModal === "force-unlocks"
&& <ConfirmationModal
confirmLabel="Yes, Force Unlocks"
description="This will scan your save data and grant access to any zones, quests, and bosses that you have already earned but are incorrectly locked. This operation is safe and non-destructive."
isLoading={isLoading}
onCancel={handleCancel}
onConfirm={handleConfirmForceUnlocks}
title="Force Unlocks"
/>
}
{activeModal === "hard-reset"
&& <ConfirmationModal
confirmLabel="Yes, Wipe Everything"
description="This will permanently delete all of your current progress — gold, adventurers, upgrades, bosses, quests, and zones — and reset your account to a brand-new state. Lifetime stats are preserved, but everything else will be gone forever."
isLoading={isLoading}
onCancel={handleCancel}
onConfirm={handleConfirmHardReset}
title="⚠️ Hard Reset — This Cannot Be Undone"
/>
}
</div>
);
};
export { DebugPanel };
+5 -1
View File
@@ -23,6 +23,7 @@ import { CodexToast } from "./codexToast.js";
import { CompanionPanel } from "./companionPanel.js";
import { CraftingPanel } from "./craftingPanel.js";
import { DailyChallengePanel } from "./dailyChallengePanel.js";
import { DebugPanel } from "./debugPanel.js";
import { EditProfileModal } from "./editProfileModal.js";
import { EquipmentPanel } from "./equipmentPanel.js";
import { ExplorationPanel } from "./explorationPanel.js";
@@ -57,7 +58,8 @@ type Tab =
| "crafting"
| "character"
| "companions"
| "story";
| "story"
| "debug";
const baseTabs: Array<{ id: Tab; label: string }> = [
{ id: "adventurers", label: "⚔️ Adventurers" },
@@ -78,6 +80,7 @@ const baseTabs: Array<{ id: Tab; label: string }> = [
{ id: "story", label: "📖 Story" },
{ id: "codex", label: "🗺️ Codex" },
{ id: "about", label: "️ About" },
{ id: "debug", label: "🔧 Debug" },
];
/**
@@ -242,6 +245,7 @@ const GameLayout = (): JSX.Element => {
{activeTab === "story" && <StoryPanel />}
{activeTab === "codex" && <CodexPanel />}
{activeTab === "about" && <AboutPanel />}
{activeTab === "debug" && <DebugPanel />}
</div>
</main>
</div>