diff --git a/.pi/docs/webapp.md b/.pi/docs/webapp.md index 3197bb4..02cd5dd 100644 --- a/.pi/docs/webapp.md +++ b/.pi/docs/webapp.md @@ -58,6 +58,14 @@ zauberturm.de: Nachtblau/Schwarz/Gold, Pergament, Animationen. `WS_SAVE_TABLES` (`app/rules.php`, OSE-SRD-Werte, Westreiche-Klassen auf die Grundklassen abgebildet) und werden bei Stufen-/Klassenwechsel neu gesetzt. **Falls der SL eigene RW-Tabellen führt: dort in `app/rules.php` ändern**, +- **Praxispunkte (PP):** `character_skills.pp` (TINYINT 0–10, Migration 7) – im + Bogen zehn ankreuzbare Kästchen je Fertigkeit, Klick speichert per fetch auf + `/characters//skills//pp` (`character_skill_set_pp()`); ohne JS + läuft dasselbe Formular als normaler POST mit Redirect auf `#fertigkeiten`. +- **Fertigkeitswürfel:** `skill_die()`/`skill_tier()` in `app/rules.php` + (`WS_SKILL_DICE`): Stufe 0 = W4 (ungelernt), 1 = W6, 2 = W8, 3 = W10, + 4 = W12, 5 = 2W6, 6+ = 3W6. Der Würfel steht im HTML-Bogen und im PDF + (`app/sheet.php`, Spalte rechts neben Stufe; PP-Kästchen ganz rechts). nicht in der DB. - **Trefferpunkte:** berechnet aus Einzelwürfen – `1W4` für Stufe 0 + je Stufenlevel `1W` (`WS_HIT_DICE`: Kämpferklassen W8, Kleriker diff --git a/westreiche_website/app/character.php b/westreiche_website/app/character.php index ad66c07..4d4e9aa 100644 --- a/westreiche_website/app/character.php +++ b/westreiche_website/app/character.php @@ -344,7 +344,7 @@ function skills_catalog_delete(int $id): void function character_skills(int $characterId): array { $stmt = db()->prepare( - "SELECT cs.id, cs.character_id, cs.skill_id, cs.name, cs.bonus, cs.note, + "SELECT cs.id, cs.character_id, cs.skill_id, cs.name, cs.bonus, cs.note, cs.pp, COALESCE(NULLIF(cs.attribute, ''), s.attribute) AS attribute, s.category FROM character_skills cs @@ -378,6 +378,35 @@ function character_skill_add(int $characterId, ?int $skillId, string $name, int ]); } +/** + * Praxispunkte einer Fertigkeit setzen (0 … WS_SKILL_PRACTICE_SLOTS). + * + * Klick auf das zuletzt gefüllte Kästchen nimmt den Punkt wieder weg, deshalb + * toggelt die Funktion bei gleichem Wert auf eins weniger. + * + * @return int gespeicherter Wert + */ +function character_skill_set_pp(int $characterId, int $id, int $pp): int +{ + $current = character_skill_pp($characterId, $id); + $pp = max(0, min(WS_SKILL_PRACTICE_SLOTS, $pp)); + if ($current !== null && $pp === $current) { + $pp = max(0, $pp - 1); + } + db()->prepare('UPDATE character_skills SET pp = ? WHERE id = ? AND character_id = ?') + ->execute([$pp, $id, $characterId]); + return $pp; +} + +/** Gespeicherte Praxispunkte einer Fertigkeit; null, wenn sie nicht existiert. */ +function character_skill_pp(int $characterId, int $id): ?int +{ + $stmt = db()->prepare('SELECT pp FROM character_skills WHERE id = ? AND character_id = ? LIMIT 1'); + $stmt->execute([$id, $characterId]); + $value = $stmt->fetchColumn(); + return $value === false ? null : (int) $value; +} + function character_skill_delete(int $characterId, int $id): void { db()->prepare('DELETE FROM character_skills WHERE id = ? AND character_id = ?')->execute([$id, $characterId]); diff --git a/westreiche_website/app/migrations.php b/westreiche_website/app/migrations.php index 542eb28..82713eb 100644 --- a/westreiche_website/app/migrations.php +++ b/westreiche_website/app/migrations.php @@ -65,6 +65,10 @@ const WS_MIGRATIONS = [ 6 => [ "ALTER TABLE characters ADD COLUMN IF NOT EXISTS hp_rolls VARCHAR(160) NOT NULL DEFAULT '' AFTER hp_max", ], + // 7: Praxispunkte je Fertigkeit (Bogen-Spalte „PP", 0 … 10 ankreuzbar). + 7 => [ + 'ALTER TABLE character_skills ADD COLUMN IF NOT EXISTS pp TINYINT UNSIGNED NOT NULL DEFAULT 0 AFTER note', + ], ]; function ws_migrations_apply(PDO $pdo): void diff --git a/westreiche_website/app/pages.php b/westreiche_website/app/pages.php index 7525fa1..cda9f56 100644 --- a/westreiche_website/app/pages.php +++ b/westreiche_website/app/pages.php @@ -132,6 +132,29 @@ function page_handle(string $method, string $path): void flash('info', '„' . $character['name'] . '“ wurde gelöscht.'); redirect('/'); } + if (preg_match('#^/characters/(\d+)/skills/(\d+)/pp$#', $path, $m) === 1) { + require_post(); + $character = character_require((int) $m[1], $user); + $wantsJson = strtolower((string) ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '')) === 'fetch'; + if (!csrf_valid()) { + if ($wantsJson) { + http_response_code(419); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => false, 'error' => 'Sitzung abgelaufen.'], JSON_UNESCAPED_UNICODE); + return; + } + flash('error', 'Die Sitzung ist abgelaufen. Bitte erneut versuchen.'); + redirect('/characters/' . $character['id'] . '#fertigkeiten'); + } + $pp = max(0, min(WS_SKILL_PRACTICE_SLOTS, post_int('pp', 0))); + $pp = character_skill_set_pp((int) $character['id'], (int) $m[2], $pp); + if ($wantsJson) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => true, 'pp' => $pp], JSON_UNESCAPED_UNICODE); + return; + } + redirect('/characters/' . $character['id'] . '#fertigkeiten'); + } if (preg_match('#^/characters/(\d+)/skills/(add|\d+/delete)$#', $path, $m) === 1) { require_post(); $character = character_require((int) $m[1], $user); diff --git a/westreiche_website/app/rules.php b/westreiche_website/app/rules.php index ba27e4d..fd4c6ae 100644 --- a/westreiche_website/app/rules.php +++ b/westreiche_website/app/rules.php @@ -111,6 +111,16 @@ const WS_SKILL_CATALOG = [ 'Zauberkunde' => ['INT', 'Wissen'], ]; +/** + * Fertigkeitsstufen des Charakterbogens (RPG/6-Dokumente/Charakterbogen.pdf): + * Index = Stufe. Stufe 0 = ungelernt, ab Stufe 6 immer 3W6. + */ +const WS_SKILL_DICE = ['W4', 'W6', 'W8', 'W10', 'W12', '2W6', '3W6']; +const WS_SKILL_TIERS = ['ungelernt', 'Anfänger', 'Geselle', 'Könner', 'Profi', 'Meister', 'Großmeister']; + +/** Ankreuzbare Praxispunkte je Fertigkeit (Bogen-Spalte „PP"). */ +const WS_SKILL_PRACTICE_SLOTS = 10; + const WS_CHARACTER_STATUS = [ 'active' => 'im Spiel', 'dead' => 'gefallen', @@ -148,6 +158,26 @@ function bonus_class(int $value): string return $value > 0 ? 'bonus-pos' : ($value < 0 ? 'bonus-neg' : 'bonus-zero'); } +/** + * Stufe einer Fertigkeit auf die Würfelleiter abbilden (0 … 6). + */ +function skill_tier_index(int $level): int +{ + return max(0, min(count(WS_SKILL_DICE) - 1, $level)); +} + +/** Würfel der Fertigkeitsstufe, z. B. Stufe 3 → „W10". */ +function skill_die(int $level): string +{ + return WS_SKILL_DICE[skill_tier_index($level)]; +} + +/** Bezeichnung der Fertigkeitsstufe, z. B. Stufe 0 → „ungelernt". */ +function skill_tier(int $level): string +{ + return WS_SKILL_TIERS[skill_tier_index($level)]; +} + /** Attributkürzel (STR, GES, …) prüfen; unbekannte Werte werden zu ''. */ function skill_attribute_code(string $value): string { diff --git a/westreiche_website/app/sheet.php b/westreiche_website/app/sheet.php index ef4aa9b..0eff5dc 100644 --- a/westreiche_website/app/sheet.php +++ b/westreiche_website/app/sheet.php @@ -334,19 +334,37 @@ function character_pdf(array $c, array $extra): string $skill = $rows[$index]; $cx = $M + $col * ($colW + 16); $mod = skill_attribute_modifier($c, $skill); + $right = $cx + $colW; $skillName = shorten((string) $skill['name'], 34); $pdf->text($cx, $y + 8.5, 8.4, 'F3', $ink, $skillName); $skillNote = trim((string) ($skill['note'] ?? '')); if ($skillNote !== '') { $noteX = $cx + WsPdf::textWidth($skillName, 8.4, 'F3') + 6; - $noteLimit = $cx + $colW - 84; + $noteLimit = $right - 128; if ($noteLimit - $noteX > 26) { $pdf->text($noteX, $y + 8.4, 6.8, 'F1', $soft, WsPdf::fit($skillNote, 6.8, 'F1', $noteLimit - $noteX)); } } - $pdf->text($cx + $colW - 64, $y + 8.2, 6.6, 'F1', $soft, trim((string) ($skill['attribute'] ?? ''))); - $pdf->textRight($cx + $colW - 28, $y + 8.2, 6.8, 'F1', $soft, $mod === null ? '–' : signed($mod)); - $pdf->textRight($cx + $colW, $y + 8.5, 8.4, 'F2', $gold, (string) max(0, (int) $skill['bonus'])); + $pdf->textRight($right - 112, $y + 8.2, 6.6, 'F1', $soft, trim((string) ($skill['attribute'] ?? ''))); + $pdf->textRight($right - 92, $y + 8.2, 6.8, 'F1', $soft, $mod === null ? '–' : signed($mod)); + $pdf->textRight($right - 74, $y + 8.5, 8.4, 'F2', $gold, (string) max(0, (int) $skill['bonus'])); + // Würfel der Fertigkeitsstufe (W4 ungelernt … 3W6 Großmeister) + $pdf->textRight($right, $y + 8.3, 7.0, 'F2', $ink, skill_die((int) $skill['bonus'])); + // Praxispunkte: 10 ankreuzbare Kästchen + $pp = max(0, min(WS_SKILL_PRACTICE_SLOTS, (int) ($skill['pp'] ?? 0))); + $slotW = 4.2; + $slotGap = 0.9; + $slotH = 5.4; + $slotsRight = $right - 22; + $slotsLeft = $slotsRight - (WS_SKILL_PRACTICE_SLOTS * $slotW + (WS_SKILL_PRACTICE_SLOTS - 1) * $slotGap); + for ($slot = 1; $slot <= WS_SKILL_PRACTICE_SLOTS; $slot++) { + $sx = $slotsLeft + ($slot - 1) * ($slotW + $slotGap); + if ($slot <= $pp) { + $pdf->rect($sx, $y + 4.6, $slotW, $slotH, $gold, $gold, 0.2); + } else { + $pdf->rect($sx, $y + 4.6, $slotW, $slotH, null, $goldLight, 0.25); + } + } $pdf->line($cx, $y + 10.4, $cx + $colW, $y + 10.4, $goldLight, 0.22); } $y += 12.6; diff --git a/westreiche_website/assets/app.css b/westreiche_website/assets/app.css index 9caed82..11927a5 100644 --- a/westreiche_website/assets/app.css +++ b/westreiche_website/assets/app.css @@ -813,6 +813,24 @@ input[type="file"] { MOD (regulär) und STUFE (fett) exakt auf gleicher Höhe stehen. */ .skill-table td.num { vertical-align: baseline; } +/* Würfelspalte und ankreuzbare Praxispunkte (PP) */ +.skill-table th.die, .skill-table td.die { width: 3.4rem; white-space: nowrap; } +.skill-table td.pp-cell { white-space: nowrap; vertical-align: baseline; } +.pp-slots { display: inline-flex; gap: 0.16rem; margin: 0; padding: 0; border: 0; } +.pp-slot { + width: 0.68rem; + height: 0.68rem; + padding: 0; + border: 1px solid rgba(201, 162, 39, 0.55); + border-radius: 2px; + background: transparent; + cursor: pointer; + transition: background 0.12s ease, border-color 0.12s ease; +} +.pp-slot:hover { border-color: var(--gold); } +.pp-slot.is-filled { background: var(--gold); border-color: var(--gold); } +.pp-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; } + /* --- Boni: positiv grün, null grau, negativ rot ------------------------- */ .bonus-pos { color: #79d29a; } .bonus-zero { color: var(--parchment-dim); } diff --git a/westreiche_website/assets/app.js b/westreiche_website/assets/app.js index 4d5b417..6c9ac87 100644 --- a/westreiche_website/assets/app.js +++ b/westreiche_website/assets/app.js @@ -201,6 +201,36 @@ }); } + // Praxispunkte im Charakterbogen: Klick setzt die Punkte ohne Reload + document.addEventListener('submit', async function (event) { + const form = event.target.closest('[data-pp-form]'); + if (!form) { + return; + } + event.preventDefault(); + const pressed = event.submitter; + const want = pressed ? parseInt(pressed.value, 10) || 0 : 0; + try { + const response = await fetch(form.action, { + method: 'POST', + body: new FormData(form), + headers: { 'X-Requested-With': 'fetch' } + }); + const data = await response.json(); + if (!data || data.ok !== true) { + return; + } + form.querySelectorAll('.pp-slot').forEach(function (slot) { + const value = parseInt(slot.value, 10) || 0; + const filled = value <= data.pp; + slot.classList.toggle('is-filled', filled); + slot.setAttribute('aria-pressed', filled ? 'true' : 'false'); + }); + } catch (error) { + form.submit(); + } + }); + // Selektor-Schirme: Fertigkeiten und Zauber aus dem Katalog wählen // Blendet Überschriften aus, wenn keine ihrer Einträge sichtbar ist. const hideEmptyGroups = function (dialog) { diff --git a/westreiche_website/sql/schema.sql b/westreiche_website/sql/schema.sql index c34db51..68a5c8c 100644 --- a/westreiche_website/sql/schema.sql +++ b/westreiche_website/sql/schema.sql @@ -145,6 +145,7 @@ CREATE TABLE IF NOT EXISTS character_skills ( attribute VARCHAR(3) NOT NULL DEFAULT '', bonus SMALLINT NOT NULL DEFAULT 0, note VARCHAR(255) NOT NULL DEFAULT '', + pp TINYINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY uq_character_skills (character_id, name), CONSTRAINT fk_character_skills_character FOREIGN KEY (character_id) REFERENCES characters (id) ON DELETE CASCADE, diff --git a/westreiche_website/views/character_sheet.php b/westreiche_website/views/character_sheet.php index 17e7dcb..722ec15 100644 --- a/westreiche_website/views/character_sheet.php +++ b/westreiche_website/views/character_sheet.php @@ -157,23 +157,40 @@ $equipped = array_values(array_filter($items, static fn ($item) => (int) $item[' -
+

Fertigkeiten

+

+ Die Stufe bestimmt den Würfel: 0 = W4 (ungelernt), 1 = W6, 2 = W8, 3 = W10, + 4 = W12, 5 = 2W6, 6+ = 3W6. Die Kästchen sind die Praxispunkte (max. ). +

Noch keine Fertigkeiten eingetragen. Ergänzen

$groupSkills): ?>

- + + + +
FertigkeitAttributMODStufeNotiz
FertigkeitAttributMODStufeWürfelPPNotiz
+
+ + + + +
+