Break out spawnable entities and use a registry to spawn them.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-13 20:07:44 +01:00
parent 7835a6051e
commit bca8d10964
10 changed files with 110 additions and 52 deletions

View File

@@ -0,0 +1,35 @@
import 'package:wolf_dart/features/entities/decorative.dart';
import 'package:wolf_dart/features/entities/enemies/brown_guard.dart';
import 'package:wolf_dart/features/entities/entity.dart';
typedef EntitySpawner =
Entity? Function(int objId, double x, double y, int difficultyLevel);
abstract class EntityRegistry {
// Add future enemies (SSGuard, Dog, etc.) to this list!
static final List<EntitySpawner> _spawners = [
Decorative.trySpawn,
BrownGuard.trySpawn,
];
static Entity? spawn(
int objId,
double x,
double y,
int difficultyLevel,
int maxSprites,
) {
for (final spawner in _spawners) {
Entity? entity = spawner(objId, x, y, difficultyLevel);
if (entity != null) {
// Safety bounds check for the VSWAP array
if (entity.spriteIndex >= 0 && entity.spriteIndex < maxSprites) {
return entity;
}
return null; // VSWAP doesn't have this sprite!
}
}
return null; // No class claimed this Map ID
}
}