Files
wolf_dart/lib/features/entities/entity_registry.dart
2026-03-13 22:35:37 +01:00

45 lines
1.3 KiB
Dart

import 'package:wolf_dart/features/entities/collectible.dart';
import 'package:wolf_dart/features/entities/decorative.dart';
import 'package:wolf_dart/features/entities/enemies/brown_guard.dart';
import 'package:wolf_dart/features/entities/enemies/dog.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 = [
Collectible.trySpawn, // Check collectibles
Decorative.trySpawn, // Then check decorations
BrownGuard.trySpawn, // Then check guards
Dog.trySpawn, // Then check dogs
];
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
}
}