feat: add home and team editor templates

This commit is contained in:
Keith Solomon
2026-07-06 21:30:17 -05:00
parent c2233c1639
commit 7e6240733b
2 changed files with 106 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
use BattleForge\Domain\Archetype;
use BattleForge\Domain\ArchetypeCatalog;
use BattleForge\Http\Escape;
/**
* @var string $csrf Provided by the front controller.
* @var ?string $error Optional validator error message; HTML-escaped on output.
* @var array<string, string> $old Optional old form values, keyed by field name; HTML-escaped on output.
* @var array<string, mixed> $post Raw form data (for repopulating per-unit fields).
*/
$e = static fn (string $v): string => Escape::html($v);
$a = static fn (string $v): string => Escape::attr($v);
$archetypes = ArchetypeCatalog::templates();
?><?php
render_layout(static function () use ($csrf, $e, $a, $archetypes, $error, $old, $post): void {
?>
<h1>Team editor</h1>
<?php if ($error !== null) : ?>
<div class="bf-errors"><p><?= $e($error) ?></p></div>
<?php endif; ?>
<form method="post" action="<?= $a('/scenarios/' . $e($old['id'] ?? 'new') . '/edit/team') ?>" enctype="multipart/form-data">
<input type="hidden" name="_csrf" value="<?= $a($csrf) ?>">
<fieldset>
<legend>Scenario</legend>
<label>Id: <input type="text" name="id" value="<?= $e($old['id'] ?? '') ?>" required></label>
<label>Name: <input type="text" name="name" value="<?= $e($old['name'] ?? '') ?>" required></label>
<label>Battlefield width: <input type="number" name="battlefieldWidth" min="8" max="16" value="<?= $e($old['battlefieldWidth'] ?? '8') ?>" required></label>
<label>Battlefield height: <input type="number" name="battlefieldHeight" min="8" max="16" value="<?= $e($old['battlefieldHeight'] ?? '8') ?>" required></label>
</fieldset>
<fieldset>
<legend>Team A</legend>
<?php for ($i = 0; $i < 3; $i++) :
$row = $post['teamA']['units'][$i] ?? null; ?>
<div class="bf-unit">
<input type="text" name="teamA[units][<?= $i ?>][id]" placeholder="a-<?= $i + 1 ?>" value="<?= $e($row['id'] ?? '') ?>" required>
<select name="teamA[units][<?= $i ?>][archetype]" required>
<?php foreach ($archetypes as $key => $template) : ?>
<option value="<?= $a($key) ?>"<?= (($row['archetype'] ?? '') === $key) ? ' selected' : '' ?>><?= $e($key) ?></option>
<?php endforeach; ?>
</select>
<input type="number" name="teamA[units][<?= $i ?>][maxHealth]" placeholder="maxHealth" required>
<input type="number" name="teamA[units][<?= $i ?>][attack]" placeholder="attack" required>
<input type="number" name="teamA[units][<?= $i ?>][defense]" placeholder="defense" required>
<input type="number" name="teamA[units][<?= $i ?>][speed]" placeholder="speed" required>
<input type="text" name="teamA[units][<?= $i ?>][x]" placeholder="x" value="<?= $e($row['x'] ?? '0') ?>" required>
<input type="text" name="teamA[units][<?= $i ?>][y]" placeholder="y" value="<?= $e($row['y'] ?? '0') ?>" required>
<input type="file" name="teamA[units][<?= $i ?>][image]" accept="image/*">
<input type="hidden" name="teamA[units][<?= $i ?>][imageUrl]" value="<?= $e($row['imageUrl'] ?? '') ?>">
</div>
<?php endfor; ?>
</fieldset>
<fieldset>
<legend>Team B</legend>
<?php for ($i = 0; $i < 3; $i++) :
$row = $post['teamB']['units'][$i] ?? null; ?>
<div class="bf-unit">
<input type="text" name="teamB[units][<?= $i ?>][id]" placeholder="b-<?= $i + 1 ?>" value="<?= $e($row['id'] ?? '') ?>" required>
<select name="teamB[units][<?= $i ?>][archetype]" required>
<?php foreach ($archetypes as $key => $template) : ?>
<option value="<?= $a($key) ?>"<?= (($row['archetype'] ?? '') === $key) ? ' selected' : '' ?>><?= $e($key) ?></option>
<?php endforeach; ?>
</select>
<input type="number" name="teamB[units][<?= $i ?>][maxHealth]" placeholder="maxHealth" required>
<input type="number" name="teamB[units][<?= $i ?>][attack]" placeholder="attack" required>
<input type="number" name="teamB[units][<?= $i ?>][defense]" placeholder="defense" required>
<input type="number" name="teamB[units][<?= $i ?>][speed]" placeholder="speed" required>
<input type="text" name="teamB[units][<?= $i ?>][x]" placeholder="x" value="<?= $e($row['x'] ?? '7') ?>" required>
<input type="text" name="teamB[units][<?= $i ?>][y]" placeholder="y" value="<?= $e($row['y'] ?? '7') ?>" required>
<input type="file" name="teamB[units][<?= $i ?>][image]" accept="image/*">
<input type="hidden" name="teamB[units][<?= $i ?>][imageUrl]" value="<?= $e($row['imageUrl'] ?? '') ?>">
</div>
<?php endfor; ?>
</fieldset>
<fieldset>
<legend>Victory</legend>
<label><input type="radio" name="victoryCondition" value="eliminate_all"<?= (($old['victoryCondition'] ?? 'eliminate_all') === 'eliminate_all') ? ' checked' : '' ?>> Eliminate all</label>
<label><input type="radio" name="victoryCondition" value="hold_objective"<?= (($old['victoryCondition'] ?? '') === 'hold_objective') ? ' checked' : '' ?>> Hold objective</label>
<label>Hold rounds: <input type="number" name="holdRoundsRequired" min="1" max="10" value="<?= $e($old['holdRoundsRequired'] ?? '1') ?>"></label>
</fieldset>
<button type="submit">Save</button>
</form>
<?php
}, $csrf, 'Team editor');