Charakterverwalter: Ausrüstungskatalog mit Selektor im Inventar

- data/item_catalog.csv als kuratierbare Master-Liste (481 Gegenstände nach
  OSE-Kernlisten plus Hausrat, Handel und Schatz), Preise in Silbertalern
  (OSE-Goldmünzen 1:1), Art aus WS_ITEM_CATEGORIES, Verfügbarkeit gestaffelt
  (Methaven/Garana/selten)
- tools/build_item_catalog.py erzeugt app/item_catalog_data.php und
  sql/seed_items.sql; item_catalog_sync() spiegelt den Katalog in die neue
  Tabelle item_catalog (Migration 3)
- Selektor-Dialog im Inventar filtert serverseitig nach Art, Verfügbarkeit und
  Suche (GET item_kind/item_avail/item_q) und übernimmt die Auswahl als
  Inventarzeile (POST /characters/{id}/items/from-catalog)
- Admin-Ansicht Ausrüstung listet den Katalog und liest die CSV neu ein
This commit is contained in:
torsten 2026-11-21 14:31:29 +01:00
parent b68e92f581
commit 5f01146d4b
17 changed files with 2029 additions and 4 deletions

View file

@ -0,0 +1,99 @@
<?php
/**
* Selektor-Schirm: Ausrüstung aus dem Katalog ins Inventar übernehmen.
*
* Wird aus views/character_edit.php eingebunden; erwartet $base, $character,
* $itemCatalog, $itemCatalogCount, $itemFilters und $itemSelectorOpen.
*
* Gefiltert wird serverseitig über GET-Parameter (item_kind/item_avail/item_q),
* damit der Katalog auch mit hunderten Einträgen ohne JavaScript bedienbar
* bleibt. Die Auswahl selbst ist ein POST auf /characters/{id}/items/from-catalog.
*
* @var string $base
* @var array $character
* @var list<array<string,mixed>> $itemCatalog
* @var int $itemCatalogCount
* @var array{kind:string,availability:string,needle:string} $itemFilters
* @var bool $itemSelectorOpen
*/
$availabilityShort = ['methaven' => 'Methaven', 'garana' => 'Garana', 'selten' => 'selten'];
$filterUrl = $base . '/characters/' . (int) $character['id'] . '/edit';
?>
<dialog class="selector" id="item-selector" aria-labelledby="item-selector-title"<?= $itemSelectorOpen ? ' data-autopen' : '' ?>>
<div class="selector-head">
<h2 id="item-selector-title">Ausrüstung aus dem Katalog</h2>
<button class="btn btn-small" type="button" data-dialog-close>Schließen</button>
</div>
<div class="selector-body">
<form method="get" action="<?= e($filterUrl) ?>" class="selector-filters">
<label class="field">
<span>Suche</span>
<input type="search" name="item_q" value="<?= e($itemFilters['needle']) ?>" placeholder="Name oder Notiz …" autocomplete="off">
</label>
<label class="field">
<span>Art</span>
<select name="item_kind">
<option value="">Alle Arten</option>
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
<option value="<?= e($category) ?>"<?= $itemFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
<?php endforeach; ?>
</select>
</label>
<label class="field">
<span>Verfügbarkeit</span>
<select name="item_avail">
<option value="">Alle (auch Seltenes)</option>
<?php foreach (WS_ITEM_AVAILABILITY as $key => $label): ?>
<option value="<?= e($key) ?>"<?= $itemFilters['availability'] === $key ? ' selected' : '' ?>><?= e($label) ?></option>
<?php endforeach; ?>
</select>
</label>
<div class="selector-filter-actions">
<button class="btn btn-small" type="submit">Filtern</button>
<a class="btn btn-small" href="<?= e($filterUrl . '#inventar') ?>">Zurücksetzen</a>
</div>
</form>
<p class="selector-hint muted">
<?= count($itemCatalog) ?> von <?= (int) $itemCatalogCount ?> Gegenständen
<?php if ((int) $itemCatalogCount > count($itemCatalog)): ?>
– Suche oder Filter eingrenzen, um mehr zu sehen.
<?php endif; ?>
</p>
<p class="selector-hint muted">
Verfügbarkeit ist gestaffelt: Garana schließt Methaven ein, „Alle“ zeigt auch das,
was in keiner der beiden Ortschaften zu kaufen ist. Gewicht in OSE-Münzeinheiten
(10 Münzen ≈ 1 Pfund).
</p>
<form method="post" action="<?= e($base . '/characters/' . (int) $character['id'] . '/items/from-catalog') ?>">
<?= csrf_field() ?>
<div class="selector-groups">
<?php $lastKind = ''; ?>
<?php foreach ($itemCatalog as $entry): ?>
<?php $kind = (string) $entry['kind']; ?>
<?php if ($kind !== $lastKind): ?>
<?php $lastKind = $kind; ?>
<p class="selector-group"><?= e($kind) ?></p>
<?php endif; ?>
<button class="selector-item selector-item-wide" type="submit" name="catalog_id" value="<?= (int) $entry['id'] ?>">
<span class="selector-item-main"><?= e((string) $entry['name']) ?></span>
<span class="meta">
<?= e(item_cost_label($entry['cost'])) ?>
<?php if (item_weight_label($entry['weight']) !== ''): ?>
· <?= e(item_weight_label($entry['weight'])) ?>
<?php endif; ?>
· <?= e($availabilityShort[(string) $entry['availability']] ?? (string) $entry['availability']) ?>
<?php if ((string) $entry['note'] !== ''): ?>
· <em><?= e((string) $entry['note']) ?></em>
<?php endif; ?>
</span>
</button>
<?php endforeach; ?>
<?php if ($itemCatalog === []): ?>
<p class="selector-empty">Kein Gegenstand passt zu Suche und Filtern.</p>
<?php endif; ?>
</div>
</form>
</div>
</dialog>

View file

@ -46,3 +46,60 @@
</tbody>
</table>
</section>
<?php
/**
* Ausrüstungskatalog (Selektor im Inventar).
*
* @var list<array<string,mixed>> $itemCatalog
* @var int $itemCatalogCount
* @var array{kind:string,needle:string,limit:int} $itemFilters
*/
$availabilityShort = ['methaven' => 'Methaven', 'garana' => 'Garana', 'selten' => 'selten'];
?>
<section class="panel">
<h2>Ausrüstungskatalog</h2>
<p class="muted">
Quelle ist <code>data/item_catalog.csv</code> (dort kuratieren, dann
<code>python3 tools/build_item_catalog.py</code>). Preise in Silbertalern;
OSE-Goldmünzen sind 1:1 übernommen.
</p>
<form method="post" action="<?= e($base . '/admin/equipment/items/sync') ?>" class="inline-form" style="margin-bottom:.8rem">
<?= csrf_field() ?>
<button class="btn btn-small" type="submit">Katalog aus der CSV neu einlesen</button>
<span class="muted"><?= (int) $itemCatalogCount ?> Gegenstände im Filter, <?= count($itemCatalog) ?> gelistet.</span>
</form>
<form method="get" action="<?= e($base . '/admin/equipment') ?>" class="selector-filters">
<label class="field">
<span>Suche</span>
<input type="search" name="q" value="<?= e($itemFilters['needle']) ?>" placeholder="Name oder Notiz …">
</label>
<label class="field">
<span>Art</span>
<select name="kind">
<option value="">Alle Arten</option>
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
<option value="<?= e($category) ?>"<?= $itemFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
<?php endforeach; ?>
</select>
</label>
<button class="btn btn-small" type="submit">Filtern</button>
</form>
<table class="data">
<thead><tr><th>Name</th><th>Art</th><th class="num">Preis</th><th>Gewicht</th><th>Verfügbarkeit</th><th>Notiz</th></tr></thead>
<tbody>
<?php foreach ($itemCatalog as $entry): ?>
<tr>
<td><?= e((string) $entry['name']) ?></td>
<td class="muted"><?= e((string) $entry['kind']) ?></td>
<td class="num"><?= e(item_cost_label($entry['cost'])) ?></td>
<td class="muted"><?= e(item_weight_label($entry['weight'])) ?></td>
<td class="muted"><?= e($availabilityShort[(string) $entry['availability']] ?? (string) $entry['availability']) ?></td>
<td class="muted"><?= e((string) $entry['note']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</section>

View file

@ -436,6 +436,12 @@ $base = url('/characters/' . $cid);
<?php endif; ?>
<hr class="divider">
<div class="selector-actions" style="margin-bottom:.8rem">
<button class="btn btn-primary" type="button" data-dialog-open="#item-selector">Gegenstand aus dem Katalog</button>
<span class="muted"><?= (int) ($itemCatalogCount ?? 0) ?> Gegenstände, filterbar nach Art und Verfügbarkeit (Methaven/Garana/Alle).</span>
</div>
<?php require WS_ROOT . '/views/_selector_items.php'; ?>
<form method="post" action="<?= e($base . '/items/add') ?>" class="inline-form">
<?= csrf_field() ?>
<label class="field grow">