Show AC on each tracker row

Combatant snapshots armor_class from the enemy when added (like maxHp),
shown as an "AC n" pill next to the name for quick hit checks. Migration
backfills existing combatants from their enemy.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Frank
2026-09-06 19:34:24 +02:00
co-authored by Claude Sonnet 5
parent 2ed169fc78
commit cb23d5b9ac
4 changed files with 48 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260906173325 extends AbstractMigration
{
public function getDescription(): string
{
return 'Snapshot armor class onto each combatant';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE combatant ADD armor_class SMALLINT DEFAULT 10 NOT NULL');
$this->addSql('UPDATE combatant c JOIN enemy e ON c.enemy_id = e.id SET c.armor_class = e.armor_class');
$this->addSql('ALTER TABLE combatant ALTER armor_class DROP DEFAULT');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE combatant DROP armor_class');
}
}
+1
View File
@@ -77,6 +77,7 @@ class TrackerController extends AbstractController
(new Combatant()) (new Combatant())
->setEnemy($enemy) ->setEnemy($enemy)
->setLabel($label) ->setLabel($label)
->setArmorClass($enemy->getArmorClass())
->setMaxHp($enemy->getHitPoints()) ->setMaxHp($enemy->getHitPoints())
->setCurrentHp($enemy->getHitPoints()) ->setCurrentHp($enemy->getHitPoints())
->setPosition($pos++) ->setPosition($pos++)
+15
View File
@@ -30,6 +30,9 @@ class Combatant
#[ORM\Column(length: 120)] #[ORM\Column(length: 120)]
private string $label = ''; private string $label = '';
#[ORM\Column(type: Types::SMALLINT)]
private int $armorClass = 10;
#[ORM\Column(type: Types::SMALLINT)] #[ORM\Column(type: Types::SMALLINT)]
private int $maxHp = 1; private int $maxHp = 1;
@@ -113,6 +116,18 @@ class Combatant
return $this; return $this;
} }
public function getArmorClass(): int
{
return $this->armorClass;
}
public function setArmorClass(int $armorClass): static
{
$this->armorClass = $armorClass;
return $this;
}
public function getMaxHp(): int public function getMaxHp(): int
{ {
return $this->maxHp; return $this->maxHp;
+1
View File
@@ -51,6 +51,7 @@
<div class="col-12 col-md-4"> <div class="col-12 col-md-4">
<div class="fw-semibold {{ c.isDown ? 'text-decoration-line-through' : '' }}"> <div class="fw-semibold {{ c.isDown ? 'text-decoration-line-through' : '' }}">
{{ c.label }} {{ c.label }}
<span class="badge rounded-pill text-bg-secondary ms-1" title="Armor Class">AC {{ c.armorClass }}</span>
{% if c.isDown %}<span class="badge text-bg-secondary ms-1">Down</span>{% endif %} {% if c.isDown %}<span class="badge text-bg-secondary ms-1">Down</span>{% endif %}
</div> </div>
{% if c.enemy %} {% if c.enemy %}