Files
zombie-game/app/Game/EntityList.php
T
2026-09-07 20:37:40 +02:00

42 lines
863 B
PHP

<?php
declare(strict_types=1);
namespace App\Game;
final class EntityList extends \ArrayObject
{
public function remove(GameObject $gameObject): void
{
foreach (array_keys($this->getArrayCopy()) as $key) {
if ($this[$key] === $gameObject) {
$this->offsetUnset($key);
break;
}
}
}
public function findByKind(string $kind): array
{
$found = [];
foreach ($this as $entity) {
if ($entity->kind() === $kind) {
$found[] = $entity;
}
}
return $found;
}
/** Snapshot copy so entities added mid-iteration are not touched. */
public function copy(): array
{
$copy = [];
foreach ($this as $entity) {
$copy[] = $entity;
}
return $copy;
}
}