First commit, phased 1 and 2 created but untested
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Hero - Emberfall</title>
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-container">
|
||||
<h1>Emberfall</h1>
|
||||
<h2>Create Your Hero</h2>
|
||||
<div id="error" class="error" style="display:none;"></div>
|
||||
<form id="create-hero-form">
|
||||
<label for="hero-name">Hero Name</label>
|
||||
<input type="text" id="hero-name" name="hero-name" required minlength="3" maxlength="16" pattern="[A-Za-z0-9 ']+">
|
||||
|
||||
<label for="hero-class">Class</label>
|
||||
<select id="hero-class" name="hero-class" required>
|
||||
<option value="">Choose a class...</option>
|
||||
<option value="warrior">Warrior — Armoured frontliner (STR 8, AGI 4, INT 2, VIT 8)</option>
|
||||
<option value="mage">Mage — Glass-cannon spellcaster (STR 2, AGI 4, INT 9, VIT 5)</option>
|
||||
<option value="ranger">Ranger — Fast skirmisher (STR 5, AGI 9, INT 3, VIT 5)</option>
|
||||
</select>
|
||||
|
||||
<button type="submit">Begin Your Journey</button>
|
||||
</form>
|
||||
</div>
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/create-hero.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,176 @@
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
background: #1a1a2e;
|
||||
color: #e0e0e0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.auth-container {
|
||||
background: #16213e;
|
||||
padding: 2rem 2.5rem;
|
||||
border-radius: 8px;
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
}
|
||||
|
||||
h1 { text-align: center; color: #e94560; margin-bottom: 0.25rem; }
|
||||
h2 { text-align: center; color: #a0a0a0; font-weight: 400; margin-bottom: 1.5rem; }
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
color: #a0a0a0;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid #333;
|
||||
border-radius: 4px;
|
||||
background: #0f3460;
|
||||
color: #e0e0e0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
input:focus { outline: none; border-color: #e94560; }
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
margin-top: 1.25rem;
|
||||
padding: 0.625rem;
|
||||
background: #e94560;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover { background: #c73650; }
|
||||
|
||||
.error {
|
||||
background: #5c1111;
|
||||
color: #ff8888;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.redirect {
|
||||
text-align: center;
|
||||
margin-top: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.redirect a { color: #e94560; }
|
||||
|
||||
/* Game dashboard layout */
|
||||
.game-container {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
background: #16213e;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.logo { color: #e94560; font-size: 1.25rem; font-weight: bold; }
|
||||
|
||||
.user-info { display: flex; align-items: center; gap: 1rem; }
|
||||
.user-info span { color: #a0a0a0; }
|
||||
.user-info a { color: #e94560; text-decoration: none; }
|
||||
|
||||
.main-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.main-content { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: #16213e;
|
||||
padding: 1.25rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.panel h3 {
|
||||
color: #e94560;
|
||||
margin-bottom: 0.75rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.stat-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.25rem 0;
|
||||
border-bottom: 1px solid #1a1a2e;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.stat-row .label { color: #a0a0a0; }
|
||||
|
||||
.stat-row.derived {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid #333;
|
||||
color: #88cc88;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
color: #a0a0a0;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #666;
|
||||
font-size: 0.875rem;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
/* Energy bar */
|
||||
.energy-bar-container {
|
||||
width: 100%;
|
||||
height: 12px;
|
||||
background: #0f3460;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.energy-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #4a90d9, #67b8f7);
|
||||
border-radius: 6px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.energy-timer {
|
||||
font-size: 0.75rem;
|
||||
color: #666;
|
||||
margin-top: 0.25rem;
|
||||
text-align: right;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Emberfall — Dashboard</title>
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="game-container">
|
||||
<!-- Top bar -->
|
||||
<header class="top-bar">
|
||||
<div class="logo">Emberfall</div>
|
||||
<div class="user-info">
|
||||
<span id="player-name"></span>
|
||||
<a href="/api/auth/logout" id="logout-btn">Logout</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Main content -->
|
||||
<main class="main-content">
|
||||
<!-- Stats panel -->
|
||||
<section class="panel stats-panel" id="stats-panel">
|
||||
<h3>Your Hero</h3>
|
||||
<div id="hero-loading" class="loading">Loading...</div>
|
||||
<div id="hero-error" class="error" style="display:none;"></div>
|
||||
<div id="hero-stats" style="display:none;">
|
||||
<div class="stat-row">
|
||||
<span class="label">Name:</span>
|
||||
<span id="char-name"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">Class:</span>
|
||||
<span id="char-class"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">Level:</span>
|
||||
<span id="char-level"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">HP:</span>
|
||||
<span id="char-hp"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">Energy:</span>
|
||||
<span id="char-energy"></span>
|
||||
</div>
|
||||
<div class="energy-bar-container">
|
||||
<div class="energy-bar" id="energy-bar"></div>
|
||||
</div>
|
||||
<div class="energy-timer" id="energy-timer"></div>
|
||||
<div class="stat-row">
|
||||
<span class="label">Gold:</span>
|
||||
<span id="char-gold"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">XP:</span>
|
||||
<span id="char-xp"></span>
|
||||
</div>
|
||||
<div class="stat-row">
|
||||
<span class="label">STR:</span><span id="char-str"></span>
|
||||
<span class="label">AGI:</span><span id="char-agi"></span>
|
||||
<span class="label">INT:</span><span id="char-int"></span>
|
||||
<span class="label">VIT:</span><span id="char-vit"></span>
|
||||
</div>
|
||||
<div class="stat-row derived">
|
||||
<span>ATK: <span id="derived-atk"></span></span>
|
||||
<span>DEF: <span id="derived-def"></span></span>
|
||||
<span>SPD: <span id="derived-spd"></span></span>
|
||||
<span>Crit: <span id="derived-crit"></span>%</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Action panel -->
|
||||
<section class="panel action-panel" id="action-panel">
|
||||
<h3>Actions</h3>
|
||||
<p class="placeholder">Hunting and other actions will appear here in the next phase.</p>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
const API_BASE = '/api';
|
||||
|
||||
const api = {
|
||||
async post(path, body) {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
const msg = data.error ? data.error.message : 'Request failed.';
|
||||
const errorEl = document.getElementById('error');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = msg;
|
||||
errorEl.style.display = 'block';
|
||||
}
|
||||
throw new Error(msg);
|
||||
}
|
||||
return data.data;
|
||||
},
|
||||
|
||||
async get(path) {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
const msg = data.error ? data.error.message : 'Request failed.';
|
||||
const errorEl = document.getElementById('error');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = msg;
|
||||
errorEl.style.display = 'block';
|
||||
}
|
||||
throw new Error(msg);
|
||||
}
|
||||
return data.data;
|
||||
},
|
||||
};
|
||||
|
||||
function showError(msg) {
|
||||
const errorEl = document.getElementById('error');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = msg;
|
||||
errorEl.style.display = 'block';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('create-hero-form');
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const name = document.getElementById('hero-name').value.trim();
|
||||
const classKey = document.getElementById('hero-class').value;
|
||||
|
||||
if (!name || !classKey) {
|
||||
showError('Please enter a hero name and choose a class.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await api.post('/character', { name, class: classKey });
|
||||
window.location.href = '/game.html';
|
||||
} catch (_) {
|
||||
// Error already shown via api()
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
// Game dashboard: load character profile and populate stats.
|
||||
|
||||
let energyInterval = null;
|
||||
|
||||
async function loadCharacter() {
|
||||
try {
|
||||
const data = await api.get('/character');
|
||||
if (!data) {
|
||||
// No character yet — redirect to create-hero
|
||||
window.location.href = '/create-hero.html';
|
||||
return;
|
||||
}
|
||||
|
||||
const { character, derived, energy } = data;
|
||||
|
||||
// Show stats, hide loading
|
||||
document.getElementById('hero-loading').style.display = 'none';
|
||||
document.getElementById('hero-stats').style.display = 'block';
|
||||
|
||||
// Basic info
|
||||
document.getElementById('player-name').textContent = character.name;
|
||||
document.getElementById('char-name').textContent = character.name;
|
||||
document.getElementById('char-class').textContent = character.class.charAt(0).toUpperCase() + character.class.slice(1);
|
||||
document.getElementById('char-level').textContent = character.level;
|
||||
document.getElementById('char-hp').textContent = `${character.hp_current} / ${derived.maxHp}`;
|
||||
document.getElementById('char-energy').textContent = `${energy.current} / ${energy.max}`;
|
||||
document.getElementById('char-gold').textContent = character.gold;
|
||||
document.getElementById('char-xp').textContent = `${character.xp} / ${xpToNext(character.level)}`;
|
||||
document.getElementById('char-str').textContent = character.str;
|
||||
document.getElementById('char-agi').textContent = character.agi;
|
||||
document.getElementById('char-int').textContent = character.int;
|
||||
document.getElementById('char-vit').textContent = character.vit;
|
||||
document.getElementById('derived-atk').textContent = derived.attack;
|
||||
document.getElementById('derived-def').textContent = derived.defense;
|
||||
document.getElementById('derived-spd').textContent = derived.speed;
|
||||
document.getElementById('derived-crit').textContent = derived.critChance;
|
||||
|
||||
// Update energy bar
|
||||
updateEnergyBar(energy.current, energy.max, energy.nextTickInSec);
|
||||
} catch (err) {
|
||||
// Not authenticated — redirect to login
|
||||
window.location.href = '/login.html';
|
||||
}
|
||||
}
|
||||
|
||||
function xpToNext(level) {
|
||||
return Math.floor(100 * Math.pow(level, 1.5));
|
||||
}
|
||||
|
||||
function updateEnergyBar(current, max, nextTickSec) {
|
||||
// Update text
|
||||
const energyEl = document.getElementById('char-energy');
|
||||
if (energyEl) energyEl.textContent = `${current} / ${max}`;
|
||||
|
||||
// Update bar fill
|
||||
const barEl = document.getElementById('energy-bar');
|
||||
if (barEl) {
|
||||
const pct = Math.round((current / max) * 100);
|
||||
barEl.style.width = `${pct}%`;
|
||||
barEl.title = `${current}/${max} energy`;
|
||||
}
|
||||
|
||||
// Update countdown
|
||||
const timerEl = document.getElementById('energy-timer');
|
||||
if (timerEl) {
|
||||
if (current >= max) {
|
||||
timerEl.textContent = 'Energy full';
|
||||
} else {
|
||||
const mins = Math.floor(nextTickSec / 60);
|
||||
const secs = nextTickSec % 60;
|
||||
timerEl.textContent = `Next +1 in ${mins}:${secs.toString().padStart(2, '0')}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Start countdown
|
||||
if (energyInterval) clearInterval(energyInterval);
|
||||
if (current < max && nextTickSec > 0) {
|
||||
energyInterval = setInterval(() => {
|
||||
nextTickSec--;
|
||||
if (nextTickSec <= 0) {
|
||||
clearInterval(energyInterval);
|
||||
loadCharacter();
|
||||
return;
|
||||
}
|
||||
const mins = Math.floor(nextTickSec / 60);
|
||||
const secs = nextTickSec % 60;
|
||||
if (timerEl) timerEl.textContent = `Next +1 in ${mins}:${secs.toString().padStart(2, '0')}`;
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Logout handler
|
||||
document.getElementById('logout-btn')?.addEventListener('click', async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await api.post('/auth/logout', {});
|
||||
} catch (_) {}
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', loadCharacter);
|
||||
@@ -0,0 +1,21 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('login-form');
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
const data = await api.post('/auth/login', { username, password });
|
||||
if (data.hasHero) {
|
||||
window.location.href = '/game.html';
|
||||
} else {
|
||||
window.location.href = '/create-hero.html';
|
||||
}
|
||||
} catch (_) {
|
||||
// Error already shown via api()
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('register-form');
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
await api.post('/auth/register', { username, password });
|
||||
window.location.href = '/create-hero.html';
|
||||
} catch (_) {
|
||||
// Error already shown via api()
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Emberfall</title>
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-container">
|
||||
<h1>Emberfall</h1>
|
||||
<h2>Login</h2>
|
||||
<div id="error" class="error" style="display:none;"></div>
|
||||
<form id="login-form">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" required minlength="3" maxlength="20" autocomplete="username">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required minlength="8" maxlength="72" autocomplete="current-password">
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
<p class="redirect">Don't have an account? <a href="/register.html">Register</a></p>
|
||||
</div>
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Register - Emberfall</title>
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-container">
|
||||
<h1>Emberfall</h1>
|
||||
<h2>Register</h2>
|
||||
<div id="error" class="error" style="display:none;"></div>
|
||||
<form id="register-form">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" required minlength="3" maxlength="20" pattern="[A-Za-z0-9_]+" autocomplete="username">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required minlength="8" maxlength="72" autocomplete="new-password">
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
<p class="redirect">Already have an account? <a href="/login.html">Login</a></p>
|
||||
</div>
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/register.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user