1 import { EquippedItemDetails } from "shared/equipped";
2 import { EquipmentSlot } from "shared/inventory";
3 import { expToLevel, maxHp, Player } from "../../shared/player";
5 function displayLoginSignupForm(): string {
7 <details id="signup-prompt" hx-swap-oob="true" open>
9 Hey there! It looks like you're using a SESSION account. This allows you to play right away, but the account is tied to your current device, and will be lost if you ever clear your cookies.
11 <form id="signup" hx-post="/auth" hx-swap="none">
12 <div class="form-group">
13 <label>Username:</label>
14 <input type="text" name="username">
16 <div class="form-group">
17 <label>Password:</label>
18 <input type="password" name="password">
20 <button type="submit" name="authType" value="signup">Create your Account</button>
21 <button type="submit" name="authType" value="login" id="login">Login To Existing Account</button>
28 function generateProgressBar(current: number, max: number, opts: ProgressBarOptions): string {
31 percent = Math.floor((current / max) * 100);
33 const display = `${percent}% - `;
34 return `<div class="progress-bar" style="background: linear-gradient(to right, ${opts.startingColor}, ${opts.endingColor} ${percent}%, transparent ${percent}%, transparent)" title="${display}${current}/${max}">${display}${current}/${max}</div>`;
37 function calcAp(inventoryItem: EquippedItemDetails[]): string {
38 const ap: Record<any | EquipmentSlot, {currentAp: number, maxAp: number}> = {};
39 inventoryItem.forEach(item => {
40 if(item.is_equipped && item.type === 'ARMOUR') {
41 ap[item.equipment_slot] = {
42 currentAp: item.currentAp,
50 <img src="/assets/img/helm.png" class="icon">
51 ${generateProgressBar(ap.HEAD?.currentAp || 0, ap.HEAD?.maxAp || 0, { startingColor: '#5ebb5e', endingColor: '#7be67b'})}
54 <img src="/assets/img/arms.png" class="icon">
55 ${generateProgressBar(ap.ARMS?.currentAp || 0, ap.ARMS?.maxAp || 0, { startingColor: '#5ebb5e', endingColor: '#7be67b'})}
58 <img src="/assets/img/chest.png" class="icon">
59 ${generateProgressBar(ap.CHEST?.currentAp || 0, ap.CHEST?.maxAp || 0, { startingColor: '#5ebb5e', endingColor: '#7be67b'})}
62 <img src="/assets/img/legs.png" class="icon">
63 ${generateProgressBar(ap.LEGS?.currentAp || 0, ap.LEGS?.maxAp || 0, { startingColor: '#5ebb5e', endingColor: '#7be67b'})}
68 interface ProgressBarOptions {
69 startingColor: string;
73 function progressBar(current: number, max: number, id: string, opts: ProgressBarOptions) {
76 percent = Math.floor((current / max) * 100);
79 return `<div class="progress-bar" id="${id}" style="background: linear-gradient(to right, ${opts.startingColor}, ${opts.endingColor} ${percent}%, transparent ${percent}%, transparent)"
80 title="${percent}% - ${current}/${max}">${current}/${max} - ${percent}%</div>`;
83 export function renderPlayerBar(player: Player, inventory: EquippedItemDetails[]): string {
85 <div id="stat-bars" hx-swap-oob="true">
86 <div id="player-section">
87 <div id="username">${player.username}, level ${player.level} ${player.profession}</div>
88 <div class="gold">${player.gold.toLocaleString()}</div>
90 <div id="ap-bar">${calcAp(inventory)}</div>
91 ${progressBar(player.hp, maxHp(player.constitution, player.level), 'hp-bar', { endingColor: '#ff7070', startingColor: '#d62f2f' })}
92 ${progressBar(player.exp, expToLevel(player.level + 1), 'exp-bar', { endingColor: '#5997f9', startingColor: '#1d64d4'})}
94 ${player.account_type === 'session' ? displayLoginSignupForm() : ''}