generated from nhcarrigan/template
feat: add lifetime stats to player profile
Introduce six lifetime stat fields (gold, clicks, bosses, quests, adventurers, achievements) that accumulate across all prestige and transcendence resets and are never cleared. - schema: add six new Float fields to the Player model - prestige route: capture current-run totals and increment lifetime fields before resetting per-run counters to zero - profile route: return lifetime fields as the All Time section data; add four new ProfileSettings toggles for visibility control - ProfilePage: display lifetime bosses/quests/adventurers/achievements in All Time section; remove GameProvider dependency by importing formatNumber directly (fixes crash on public profile pages) - EditProfileModal: add four new All Time stat toggles - types: update Player, ProfileSettings, and PublicProfileResponse
This commit is contained in:
@@ -18,8 +18,14 @@ model Player {
|
||||
profileSettings Json?
|
||||
createdAt Float
|
||||
lastSavedAt Float
|
||||
totalGoldEarned Float @default(0)
|
||||
totalClicks Float @default(0)
|
||||
totalGoldEarned Float @default(0)
|
||||
totalClicks Float @default(0)
|
||||
lifetimeGoldEarned Float @default(0)
|
||||
lifetimeClicks Float @default(0)
|
||||
lifetimeBossesDefeated Float @default(0)
|
||||
lifetimeQuestsCompleted Float @default(0)
|
||||
lifetimeAdventurersRecruited Float @default(0)
|
||||
lifetimeAchievementsUnlocked Float @default(0)
|
||||
}
|
||||
|
||||
model GameState {
|
||||
|
||||
@@ -62,6 +62,12 @@ authRouter.get("/callback", async (context) => {
|
||||
lastSavedAt: player.lastSavedAt,
|
||||
totalGoldEarned: player.totalGoldEarned,
|
||||
totalClicks: player.totalClicks,
|
||||
lifetimeGoldEarned: player.lifetimeGoldEarned,
|
||||
lifetimeClicks: player.lifetimeClicks,
|
||||
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
|
||||
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
|
||||
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
|
||||
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
|
||||
};
|
||||
|
||||
const initialState = INITIAL_GAME_STATE(playerShape, playerShape.characterName);
|
||||
|
||||
@@ -63,6 +63,12 @@ prestigeRouter.post("/", async (context) => {
|
||||
},
|
||||
};
|
||||
|
||||
// Capture current-run stats to accumulate into lifetime totals before resetting
|
||||
const runBossesDefeated = state.bosses.filter((b) => b.status === "defeated").length;
|
||||
const runQuestsCompleted = state.quests.filter((q) => q.status === "completed").length;
|
||||
const runAdventurersRecruited = state.adventurers.reduce((sum, a) => sum + a.count, 0);
|
||||
const runAchievementsUnlocked = (state.achievements ?? []).filter((a) => a.unlockedAt !== null).length;
|
||||
|
||||
const now = Date.now();
|
||||
await prisma.gameState.update({
|
||||
where: { discordId },
|
||||
@@ -73,8 +79,16 @@ prestigeRouter.post("/", async (context) => {
|
||||
where: { discordId },
|
||||
data: {
|
||||
characterName,
|
||||
// Reset current-run counters
|
||||
totalGoldEarned: 0,
|
||||
totalClicks: 0,
|
||||
// Accumulate into lifetime totals — never reset
|
||||
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
|
||||
lifetimeClicks: { increment: state.player.totalClicks },
|
||||
lifetimeBossesDefeated: { increment: runBossesDefeated },
|
||||
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
|
||||
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
|
||||
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
|
||||
lastSavedAt: now,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -22,8 +22,14 @@ const parseProfileSettings = (raw: unknown): ProfileSettings => {
|
||||
return {
|
||||
showTotalGold: obj.showTotalGold !== false,
|
||||
showTotalClicks: obj.showTotalClicks !== false,
|
||||
showPrestige: obj.showPrestige !== false,
|
||||
showLifetimeBossesDefeated: obj.showLifetimeBossesDefeated !== false,
|
||||
showLifetimeQuestsCompleted: obj.showLifetimeQuestsCompleted !== false,
|
||||
showLifetimeAdventurersRecruited: obj.showLifetimeAdventurersRecruited !== false,
|
||||
showLifetimeAchievementsUnlocked: obj.showLifetimeAchievementsUnlocked !== false,
|
||||
showGuildFounded: obj.showGuildFounded !== false,
|
||||
showCurrentGold: obj.showCurrentGold !== false,
|
||||
showCurrentClicks: obj.showCurrentClicks !== false,
|
||||
showPrestige: obj.showPrestige !== false,
|
||||
showBossesDefeated: obj.showBossesDefeated !== false,
|
||||
showQuestsCompleted: obj.showQuestsCompleted !== false,
|
||||
showAdventurersRecruited: obj.showAdventurersRecruited !== false,
|
||||
@@ -63,14 +69,22 @@ profileRouter.get("/:discordId", async (context) => {
|
||||
avatar: player.avatar ?? null,
|
||||
bio: player.bio ?? "",
|
||||
profileSettings,
|
||||
createdAt: player.createdAt,
|
||||
// All Time stats — cumulative across all runs, never reset
|
||||
totalGoldEarned: player.lifetimeGoldEarned,
|
||||
totalClicks: player.lifetimeClicks,
|
||||
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
|
||||
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
|
||||
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
|
||||
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
|
||||
// Current Run stats — from live GameState, reset on prestige & transcendence
|
||||
currentRunGold: state?.player.totalGoldEarned ?? 0,
|
||||
currentRunClicks: state?.player.totalClicks ?? 0,
|
||||
prestigeCount,
|
||||
totalGoldEarned: player.totalGoldEarned,
|
||||
totalClicks: player.totalClicks,
|
||||
bossesDefeated,
|
||||
questsCompleted,
|
||||
adventurersRecruited,
|
||||
achievementsUnlocked,
|
||||
createdAt: player.createdAt,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,8 +100,14 @@ profileRouter.put("/", authMiddleware, async (context) => {
|
||||
const profileSettings: ProfileSettings = {
|
||||
showTotalGold: body.profileSettings?.showTotalGold !== false,
|
||||
showTotalClicks: body.profileSettings?.showTotalClicks !== false,
|
||||
showPrestige: body.profileSettings?.showPrestige !== false,
|
||||
showLifetimeBossesDefeated: body.profileSettings?.showLifetimeBossesDefeated !== false,
|
||||
showLifetimeQuestsCompleted: body.profileSettings?.showLifetimeQuestsCompleted !== false,
|
||||
showLifetimeAdventurersRecruited: body.profileSettings?.showLifetimeAdventurersRecruited !== false,
|
||||
showLifetimeAchievementsUnlocked: body.profileSettings?.showLifetimeAchievementsUnlocked !== false,
|
||||
showGuildFounded: body.profileSettings?.showGuildFounded !== false,
|
||||
showCurrentGold: body.profileSettings?.showCurrentGold !== false,
|
||||
showCurrentClicks: body.profileSettings?.showCurrentClicks !== false,
|
||||
showPrestige: body.profileSettings?.showPrestige !== false,
|
||||
showBossesDefeated: body.profileSettings?.showBossesDefeated !== false,
|
||||
showQuestsCompleted: body.profileSettings?.showQuestsCompleted !== false,
|
||||
showAdventurersRecruited: body.profileSettings?.showAdventurersRecruited !== false,
|
||||
|
||||
@@ -8,14 +8,29 @@ interface EditProfileModalProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const STAT_TOGGLES: { key: keyof ProfileSettings; label: string; icon: string }[] = [
|
||||
{ key: "showTotalGold", label: "Total Gold Earned", icon: "🪙" },
|
||||
{ key: "showTotalClicks", label: "Total Clicks", icon: "👆" },
|
||||
interface StatToggle {
|
||||
key: keyof ProfileSettings;
|
||||
label: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
const CURRENT_RUN_TOGGLES: StatToggle[] = [
|
||||
{ key: "showCurrentGold", label: "Gold Earned This Run", icon: "🪙" },
|
||||
{ key: "showCurrentClicks", label: "Clicks This Run", icon: "👆" },
|
||||
{ key: "showPrestige", label: "Prestige Level", icon: "⭐" },
|
||||
{ key: "showBossesDefeated", label: "Bosses Defeated", icon: "💀" },
|
||||
{ key: "showQuestsCompleted", label: "Quests Completed", icon: "📜" },
|
||||
{ key: "showAdventurersRecruited", label: "Adventurers Recruited", icon: "⚔️" },
|
||||
{ key: "showAchievementsUnlocked", label: "Achievements Unlocked", icon: "🏆" },
|
||||
];
|
||||
|
||||
const ALL_TIME_TOGGLES: StatToggle[] = [
|
||||
{ key: "showTotalGold", label: "Total Gold Earned", icon: "🪙" },
|
||||
{ key: "showTotalClicks", label: "Total Clicks", icon: "👆" },
|
||||
{ key: "showLifetimeBossesDefeated", label: "Bosses Defeated", icon: "💀" },
|
||||
{ key: "showLifetimeQuestsCompleted", label: "Quests Completed", icon: "📜" },
|
||||
{ key: "showLifetimeAdventurersRecruited", label: "Adventurers Recruited", icon: "⚔️" },
|
||||
{ key: "showLifetimeAchievementsUnlocked", label: "Achievements Unlocked", icon: "🏆" },
|
||||
{ key: "showGuildFounded", label: "Guild Founded Date", icon: "📅" },
|
||||
];
|
||||
|
||||
@@ -126,8 +141,27 @@ export const EditProfileModal = ({ onClose }: EditProfileModalProps): React.JSX.
|
||||
<div className="edit-profile-section">
|
||||
<p className="edit-profile-label">Visible Stats</p>
|
||||
<p className="edit-profile-sublabel">Choose which stats appear on your public profile.</p>
|
||||
|
||||
<p className="edit-profile-stat-group-heading">Current Run</p>
|
||||
<div className="stat-toggles">
|
||||
{STAT_TOGGLES.map(({ key, label, icon }) => (
|
||||
{CURRENT_RUN_TOGGLES.map(({ key, label, icon }) => (
|
||||
<button
|
||||
key={key}
|
||||
className={`stat-toggle-btn ${settings[key] ? "stat-toggle-on" : "stat-toggle-off"}`}
|
||||
onClick={() => { toggleSetting(key); }}
|
||||
type="button"
|
||||
>
|
||||
<span>{icon} {label}</span>
|
||||
<span className="stat-toggle-indicator">
|
||||
{settings[key] ? "✓ Shown" : "Hidden"}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<p className="edit-profile-stat-group-heading">All Time</p>
|
||||
<div className="stat-toggles">
|
||||
{ALL_TIME_TOGGLES.map(({ key, label, icon }) => (
|
||||
<button
|
||||
key={key}
|
||||
className={`stat-toggle-btn ${settings[key] ? "stat-toggle-on" : "stat-toggle-off"}`}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import type { PublicProfileResponse } from "@elysium/types";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useGame } from "../../context/GameContext.js";
|
||||
import { formatNumber } from "../../utils/format.js";
|
||||
|
||||
interface ProfilePageProps {
|
||||
discordId: string;
|
||||
}
|
||||
|
||||
interface StatEntry {
|
||||
icon: string;
|
||||
value: string;
|
||||
label: string;
|
||||
date: boolean;
|
||||
}
|
||||
|
||||
export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element => {
|
||||
const { formatNumber } = useGame();
|
||||
const [profile, setProfile] = useState<PublicProfileResponse | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
@@ -51,6 +57,7 @@ export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element
|
||||
}
|
||||
|
||||
const s = profile.profileSettings;
|
||||
const fmt = (n: number): string => formatNumber(n, s.numberFormat);
|
||||
|
||||
const avatarUrl = profile.avatar
|
||||
? `https://cdn.discordapp.com/avatars/${discordId}/${profile.avatar}.png?size=128`
|
||||
@@ -62,17 +69,17 @@ export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element
|
||||
day: "numeric",
|
||||
});
|
||||
|
||||
const visibleStats = [
|
||||
s.showTotalGold && {
|
||||
const currentRunStats = [
|
||||
s.showCurrentGold && {
|
||||
icon: "🪙",
|
||||
value: formatNumber(profile.totalGoldEarned),
|
||||
label: "Total Gold Earned",
|
||||
value: fmt(profile.currentRunGold),
|
||||
label: "Gold Earned",
|
||||
date: false,
|
||||
},
|
||||
s.showTotalClicks && {
|
||||
s.showCurrentClicks && {
|
||||
icon: "👆",
|
||||
value: formatNumber(profile.totalClicks),
|
||||
label: "Total Clicks",
|
||||
value: fmt(profile.currentRunClicks),
|
||||
label: "Clicks",
|
||||
date: false,
|
||||
},
|
||||
s.showBossesDefeated && {
|
||||
@@ -89,7 +96,7 @@ export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element
|
||||
},
|
||||
s.showAdventurersRecruited && {
|
||||
icon: "⚔️",
|
||||
value: formatNumber(profile.adventurersRecruited),
|
||||
value: fmt(profile.adventurersRecruited),
|
||||
label: "Adventurers Recruited",
|
||||
date: false,
|
||||
},
|
||||
@@ -99,13 +106,66 @@ export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element
|
||||
label: "Achievements Unlocked",
|
||||
date: false,
|
||||
},
|
||||
].filter(Boolean) as StatEntry[];
|
||||
|
||||
const allTimeStats = [
|
||||
s.showTotalGold && {
|
||||
icon: "🪙",
|
||||
value: fmt(profile.totalGoldEarned),
|
||||
label: "Total Gold Earned",
|
||||
date: false,
|
||||
},
|
||||
s.showTotalClicks && {
|
||||
icon: "👆",
|
||||
value: fmt(profile.totalClicks),
|
||||
label: "Total Clicks",
|
||||
date: false,
|
||||
},
|
||||
s.showLifetimeBossesDefeated && {
|
||||
icon: "💀",
|
||||
value: String(profile.lifetimeBossesDefeated),
|
||||
label: "Bosses Defeated",
|
||||
date: false,
|
||||
},
|
||||
s.showLifetimeQuestsCompleted && {
|
||||
icon: "📜",
|
||||
value: String(profile.lifetimeQuestsCompleted),
|
||||
label: "Quests Completed",
|
||||
date: false,
|
||||
},
|
||||
s.showLifetimeAdventurersRecruited && {
|
||||
icon: "⚔️",
|
||||
value: fmt(profile.lifetimeAdventurersRecruited),
|
||||
label: "Adventurers Recruited",
|
||||
date: false,
|
||||
},
|
||||
s.showLifetimeAchievementsUnlocked && {
|
||||
icon: "🏆",
|
||||
value: String(profile.lifetimeAchievementsUnlocked),
|
||||
label: "Achievements Unlocked",
|
||||
date: false,
|
||||
},
|
||||
s.showGuildFounded && {
|
||||
icon: "📅",
|
||||
value: memberSince,
|
||||
label: "Guild Founded",
|
||||
date: true,
|
||||
},
|
||||
].filter(Boolean) as Array<{ icon: string; value: string; label: string; date: boolean }>;
|
||||
].filter(Boolean) as StatEntry[];
|
||||
|
||||
const renderStats = (stats: StatEntry[]): React.JSX.Element => (
|
||||
<div className="profile-stats">
|
||||
{stats.map((stat) => (
|
||||
<div key={stat.label} className="profile-stat">
|
||||
<span className="profile-stat-icon">{stat.icon}</span>
|
||||
<span className={`profile-stat-value ${stat.date ? "profile-stat-date" : ""}`}>
|
||||
{stat.value}
|
||||
</span>
|
||||
<span className="profile-stat-label">{stat.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="profile-page">
|
||||
@@ -131,17 +191,17 @@ export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element
|
||||
<p className="profile-bio">{profile.bio}</p>
|
||||
)}
|
||||
|
||||
{visibleStats.length > 0 && (
|
||||
<div className="profile-stats">
|
||||
{visibleStats.map((stat) => (
|
||||
<div key={stat.label} className="profile-stat">
|
||||
<span className="profile-stat-icon">{stat.icon}</span>
|
||||
<span className={`profile-stat-value ${stat.date ? "profile-stat-date" : ""}`}>
|
||||
{stat.value}
|
||||
</span>
|
||||
<span className="profile-stat-label">{stat.label}</span>
|
||||
</div>
|
||||
))}
|
||||
{currentRunStats.length > 0 && (
|
||||
<div className="profile-stats-section">
|
||||
<h3 className="profile-stats-heading">Current Run</h3>
|
||||
{renderStats(currentRunStats)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{allTimeStats.length > 0 && (
|
||||
<div className="profile-stats-section">
|
||||
<h3 className="profile-stats-heading">All Time</h3>
|
||||
{renderStats(allTimeStats)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user