Trefferwuerfe: Rechenkette anzeigen, Bearbeitung im Overlay mit einem Feld je Wurf

This commit is contained in:
torsten 2026-11-22 19:12:26 +01:00
parent 27a267893e
commit f9126675b2
5 changed files with 205 additions and 67 deletions

View file

@ -54,8 +54,15 @@
</label>
</div>
<div class="grid-4">
<?php $hp = hp_breakdown($values); ?>
<?php
// Trefferpunkte: Maximalwert ist aus den Einzelwürfen berechnet. Angezeigt
// wird die Rechenkette („3 + 4 + 7 + 8 = 25“); bearbeitet wird sie in einem
// Overlay mit einem Feld je Wurf (Stufe 0: 1W4, dann je Stufe 1W<Klassenwürfel>).
$hp = hp_breakdown($values);
$hpRolls = hp_rolls_parse($values['hp_rolls'] ?? '');
$hpSlotValue = static fn (int $slot): string => ((int) ($hpRolls[$slot] ?? 0)) > 0 ? (string) (int) $hpRolls[$slot] : '';
?>
<div class="grid-4" data-hp-widget data-hp-die="<?= (int) $hp['die'] ?>" data-hp-base="<?= (int) WS_HP_LEVEL0_DIE ?>" data-hp-con="<?= (int) $hp['con'] ?>">
<label class="field">
<span>TP aktuell</span>
<input type="number" name="hp_current" value="<?= (int) $values['hp_current'] ?>">
@ -64,20 +71,19 @@
<span>TP maximal <small class="muted">(berechnet)</small></span>
<input type="text" data-hp-total value="<?= (int) $hp['total'] ?>" readonly
title="1W<?= (int) WS_HP_LEVEL0_DIE ?> (Stufe 0) + 1W<?= (int) $hp['die'] ?> je Stufe + Konstitutionsbonus">
<small class="muted">
1W<?= (int) WS_HP_LEVEL0_DIE ?> + <?= (int) $hp['level'] ?>× 1W<?= (int) $hp['die'] ?> <?= e(signed((int) $hp['con'])) ?> KON
</small>
<small class="muted">1W<?= (int) WS_HP_LEVEL0_DIE ?> + <?= (int) $hp['level'] ?>× 1W<?= (int) $hp['die'] ?> <?= e(signed((int) $hp['con'])) ?> KON</small>
</label>
<div class="field" style="grid-column: span 2;">
<span>Trefferwürfe <small class="muted">Stufe 0 (1W<?= (int) WS_HP_LEVEL0_DIE ?>), dann Stufe 1 … <?= (int) $hp['level'] ?></small></span>
<div style="display:flex; gap:.4rem; align-items:center;">
<input type="text" name="hp_rolls" data-hp-rolls value="<?= e(hp_rolls_format(hp_rolls_parse($values['hp_rolls']))) ?>"
inputmode="numeric" placeholder="z. B. 3 7 5 2" style="flex:1 1 auto; min-width:0;"
data-hp-die="<?= (int) $hp['die'] ?>" data-hp-base="<?= (int) WS_HP_LEVEL0_DIE ?>"
data-hp-slots="<?= (int) $hp['slots'] ?>" data-hp-con="<?= (int) $hp['con'] ?>">
<button class="btn" type="button" data-hp-roll title="Fehlende Würfe auswürfeln">Würfeln</button>
</div>
<small class="muted" data-hp-label><?= e(hp_rolls_label($values)) ?> = <?= (int) $hp['total'] ?></small>
<input type="hidden" name="hp_rolls" data-hp-input value="<?= e(hp_rolls_format($hpRolls)) ?>">
<button class="hp-sum" type="button" data-dialog-open="#hp-rolls-dialog" title="Einzelne Würfe bearbeiten">
<span data-hp-sum><?= e(hp_rolls_sum($values)) ?></span>
<small>bearbeiten</small>
</button>
<small class="muted">
<?= (int) $hp['con'] === 0 ? 'ohne Konstitutionsbonus' : 'Konstitutionsbonus ' . e(signed((int) $hp['con'])) . ' eingerechnet' ?>
· fehlende Würfe zählen nicht mit
</small>
</div>
<label class="field">
<span>Rüstungsklasse (leer = automatisch)</span>
@ -182,3 +188,35 @@
<textarea name="notes" rows="3" maxlength="4000"><?= e((string) $values['notes']) ?></textarea>
</label>
</div>
<dialog class="selector hp-rolls-dialog" id="hp-rolls-dialog" aria-labelledby="hp-rolls-dialog-title">
<div class="selector-head">
<h2 id="hp-rolls-dialog-title">Trefferwürfe</h2>
<button class="btn btn-small" type="button" data-dialog-close>Schließen</button>
</div>
<div class="selector-body">
<p class="selector-hint muted" style="margin-top:0;">
Stufe 0: 1W<?= (int) WS_HP_LEVEL0_DIE ?> · je Stufe 1W<?= (int) $hp['die'] ?>
· Konstitutionsbonus <?= e(signed((int) $hp['con'])) ?> (einmal, Hausregel V1.1)
</p>
<div class="hp-roll-grid">
<label class="field">
<span>Stufe 0 <small class="muted">1W<?= (int) WS_HP_LEVEL0_DIE ?></small></span>
<input type="number" inputmode="numeric" min="1" max="<?= (int) WS_HP_LEVEL0_DIE ?>"
data-hp-slot="0" value="<?= e($hpSlotValue(0)) ?>">
</label>
<?php for ($slot = 1; $slot <= (int) $hp['level']; $slot++): ?>
<label class="field">
<span>Stufe <?= $slot ?> <small class="muted">1W<?= (int) $hp['die'] ?></small></span>
<input type="number" inputmode="numeric" min="1" max="<?= (int) $hp['die'] ?>"
data-hp-slot="<?= $slot ?>" value="<?= e($hpSlotValue($slot)) ?>">
</label>
<?php endfor; ?>
</div>
<div class="selector-actions" style="margin-top:0.9rem;">
<button class="btn" type="button" data-hp-roll>Fehlende würfeln</button>
<button class="btn btn-primary" type="button" data-hp-apply>Übernehmen</button>
<span class="muted" data-hp-dialog-sum><?= e(hp_rolls_sum($values)) ?></span>
</div>
</div>
</dialog>