From: xangelo Date: Wed, 9 Aug 2023 14:55:02 +0000 (-0400) Subject: fix: migrate stat increase to htmx X-Git-Tag: v0.2.6~1 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=734e42d2e50376ea74b592ec01401fa27a6536c8;p=risinglegends.git fix: migrate stat increase to htmx --- diff --git a/src/server/api.ts b/src/server/api.ts index 815c11b..b996401 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -419,7 +419,28 @@ app.post('/chat', authEndpoint, async (req: AuthRequest, res: Response) => { app.get('/player', authEndpoint, async (req: AuthRequest, res: Response) => { const inventory = await getEquippedItems(req.player.id); - res.send(renderPlayerBar(req.player, inventory) + (await renderProfilePage(req.player))); + res.send(renderPlayerBar(req.player, inventory) + renderProfilePage(req.player)); +}); + +app.post('/player/stat/:stat', authEndpoint, async (req: AuthRequest, res: Response) => { + const stat = req.params.stat; + if(!['strength', 'constitution', 'dexterity', 'intelligence'].includes(stat)) { + res.send(Alert.ErrorAlert(`Sorry, that's not a valid stat to increase`)); + return; + } + + if(req.player.stat_points <= 0) { + res.send(Alert.ErrorAlert(`Sorry, you don't have enough stat points`)); + return; + } + + req.player.stat_points -= 1; + req.player[stat]++; + + updatePlayer(req.player); + + const equippedItems = await getEquippedItems(req.player.id); + res.send(renderPlayerBar(req.player, equippedItems) + renderProfilePage(req.player)); }); app.get('/player/skills', authEndpoint, async (req: AuthRequest, res: Response) => { diff --git a/src/server/views/profile.ts b/src/server/views/profile.ts index 0d8468b..93a9bf7 100644 --- a/src/server/views/profile.ts +++ b/src/server/views/profile.ts @@ -1,9 +1,9 @@ import { Player, StatDef, StatDisplay } from "../../shared/player"; function statPointIncreaser(stat: StatDisplay) { - return ``; + return ``; } -export async function renderProfilePage(player: Player): Promise { +export function renderProfilePage(player: Player): string { let statBreakdown = ''; StatDef.forEach(stat => {