initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user