b80ab9c53366199bff23c458c8dca8d7a1937328
[sketchy-heroes.git] / src / public / app / sections / overview.ts
1 import {Player} from "@prisma/client";
2 import $ from 'jquery';
3 import {maxExp, maxHp, maxStamina} from "../../../formulas";
4 import {progressBar} from "../components";
5
6 function renderStatText(id: string, value: number, incrementable: boolean) {
7   $(`#${id} .text`).html(value.toString());
8   if(incrementable) {
9     $(`#${id} .stat-increase`).removeClass('hidden');
10   }
11   else {
12     $(`#${id} .stat-increase`).addClass('hidden');
13   }
14 }
15
16 export function playerOverview(player: Player) {
17
18   const incrementable = player.statPoints > 0;
19
20   $('#name').html(`${player.username}, Level ${player.level}`);
21
22   renderStatText('pow', player.pow, incrementable);
23   renderStatText('zest', player.zest, incrementable);
24   renderStatText('woosh', player.woosh, incrementable);
25   renderStatText('aha', player.aha, incrementable);
26   renderStatText('luck', player.luck, incrementable);
27   renderStatText('wow', player.wow, incrementable);
28   renderStatText('stp', player.statPoints, incrementable);
29
30   $('#hit .progress-bar-wrapper').html(progressBar(player.hp, maxHp(player.level, player.zest), {
31     color: 'danger'
32   }));
33
34   $('#sta .progress-bar-wrapper').html(progressBar(player.stamina, maxStamina(player.level, player.woosh), {
35     color: 'success'
36   }));
37
38   $('#exp .progress-bar-wrapper').html(progressBar(player.exp, maxExp(player.level), {
39     color: 'info'
40   }));
41 }