feat: add battlefield, match stub, and upload result templates
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use BattleForge\Http\Escape;
|
||||
|
||||
/**
|
||||
* @var string $csrf Provided by the front controller.
|
||||
* @var string $scenarioId Provided by the front controller from the URL.
|
||||
* @var int $width Battlefield width (8-16).
|
||||
* @var int $height Battlefield height (8-16).
|
||||
*/
|
||||
$e = static fn (string $v): string => Escape::html($v);
|
||||
$a = static fn (string $v): string => Escape::attr($v);
|
||||
$terrain = ['open', 'forest', 'rough', 'water', 'blocking'];
|
||||
?><?php
|
||||
render_layout(static function () use ($csrf, $e, $a, $scenarioId, $width, $height, $terrain): void {
|
||||
?>
|
||||
<h1>Battlefield editor</h1>
|
||||
<p>Scenario: <strong><?= $e($scenarioId) ?></strong></p>
|
||||
<form id="battlefield-form" method="post" action="<?= $a('/scenarios/' . $e($scenarioId) . '/edit/battlefield') ?>" enctype="application/x-www-form-urlencoded">
|
||||
<input type="hidden" name="_csrf" value="<?= $a($csrf) ?>">
|
||||
<fieldset>
|
||||
<legend>Battlefield</legend>
|
||||
<label>Width: <input type="number" name="battlefieldWidth" min="8" max="16" value="<?= $e((string) $width) ?>" required></label>
|
||||
<label>Height: <input type="number" name="battlefieldHeight" min="8" max="16" value="<?= $e((string) $height) ?>" required></label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Terrain palette</legend>
|
||||
<?php foreach ($terrain as $t) : ?>
|
||||
<button type="button" data-paint="<?= $a($t) ?>" class="bf-paint"><?= $e($t) ?></button>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Grid (<?= $e((string) $width) ?> × <?= $e((string) $height) ?>)</legend>
|
||||
<table class="bf-grid" id="bf-grid">
|
||||
<?php for ($y = 0; $y < $height; $y++) : ?>
|
||||
<tr>
|
||||
<?php for ($x = 0; $x < $width; $x++) : ?>
|
||||
<td><button type="button" class="bf-tile" data-x="<?= $e((string) $x) ?>" data-y="<?= $e((string) $y) ?>" data-paint="open">.</button></td>
|
||||
<?php endfor; ?>
|
||||
</tr>
|
||||
<?php endfor; ?>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Deployment zones</legend>
|
||||
<label><input type="radio" name="zoneMode" value="alpha" checked> Place team A zones</label>
|
||||
<label><input type="radio" name="zoneMode" value="bravo"> Place team B zones</label>
|
||||
<label><input type="radio" name="zoneMode" value="objective"> Place objective</label>
|
||||
</fieldset>
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
<script type="module" src="<?= $a('/js/grid-editor.js') ?>"></script>
|
||||
<?php
|
||||
}, $csrf, 'Battlefield editor');
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use BattleForge\Http\Escape;
|
||||
|
||||
/**
|
||||
* @var string $csrf Provided by the front controller.
|
||||
* @var ?string $matchJson The match:current JSON from localStorage, encoded as a string.
|
||||
* Null if no match is in progress.
|
||||
*/
|
||||
$e = static fn (string $v): string => Escape::html($v);
|
||||
$matchInfo = $matchJson !== null ? "Match loaded." : "No match in progress.";
|
||||
?><?php
|
||||
render_layout(static function () use ($e, $matchInfo, $matchJson): void {
|
||||
?>
|
||||
<h1>Match</h1>
|
||||
<p><?= $e($matchInfo) ?></p>
|
||||
<?php if ($matchJson !== null) : ?>
|
||||
<details>
|
||||
<summary>Match state (debug)</summary>
|
||||
<pre><?= $e($matchJson) ?></pre>
|
||||
</details>
|
||||
<?php endif; ?>
|
||||
<p>Battle interface coming in Plan 4.</p>
|
||||
<p><a href="/">Back to home</a></p>
|
||||
<?php
|
||||
}, $csrf, 'Match');
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use BattleForge\Http\Escape;
|
||||
|
||||
/**
|
||||
* @var string $csrf Provided by the front controller.
|
||||
* @var string $url The uploaded image's URL, written into the parent form's hidden field.
|
||||
*/
|
||||
$e = static fn (string $v): string => Escape::html($v);
|
||||
$json = json_encode(['url' => $url], JSON_THROW_ON_ERROR);
|
||||
?><?php
|
||||
render_layout(static function () use ($e, $url, $json): void {
|
||||
?>
|
||||
<p>Uploaded: <code><?= $e($url) ?></code></p>
|
||||
<script>
|
||||
(function () {
|
||||
var data = <?= $json /* trusted raw JSON; $url was validated server-side */ ?>;
|
||||
if (window.parent && window.parent !== window) {
|
||||
window.parent.postMessage(Object.assign({type: 'bf-upload'}, data), '*');
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
}, $csrf, 'Upload complete');
|
||||
Reference in New Issue
Block a user