import 'package:wolf_dart/features/difficulty/difficulty.dart'; import 'package:wolf_dart/features/entities/collectible.dart'; import 'package:wolf_dart/features/entities/decorative.dart'; import 'package:wolf_dart/features/entities/enemies/bosses/hans_grosse.dart'; import 'package:wolf_dart/features/entities/enemies/dog.dart'; import 'package:wolf_dart/features/entities/enemies/enemy.dart'; import 'package:wolf_dart/features/entities/enemies/guard.dart'; import 'package:wolf_dart/features/entities/enemies/mutant.dart'; import 'package:wolf_dart/features/entities/enemies/officer.dart'; import 'package:wolf_dart/features/entities/enemies/ss.dart'; import 'package:wolf_dart/features/entities/entity.dart'; import 'package:wolf_dart/features/entities/map_objects.dart'; typedef EntitySpawner = Entity? Function( int objId, double x, double y, Difficulty difficulty, ); abstract class EntityRegistry { static final List _spawners = [ // Enemies need to try to spawn first Guard.trySpawn, Officer.trySpawn, SS.trySpawn, Mutant.trySpawn, Dog.trySpawn, // Bosses HansGrosse.trySpawn, // Everything else Collectible.trySpawn, Decorative.trySpawn, ]; static Entity? spawn( int objId, double x, double y, Difficulty difficulty, int maxSprites, ) { // 1. Difficulty check before even looking for a spawner if (!MapObject.shouldSpawn(objId, difficulty)) return null; if (objId == 0) return null; for (final spawner in _spawners) { Entity? entity = spawner(objId, x, y, difficulty); final EnemyType? type = EnemyType.fromMapId(objId); if (type != null) { print("Spawning ${type.name} enemy"); } if (entity != null) { // Safety bounds check for the VSWAP array if (entity.spriteIndex >= 0 && entity.spriteIndex < maxSprites) { print("Spawned entity with objId $objId"); return entity; } print("VSWAP doesn't have this sprite! objId $objId"); return null; // VSWAP doesn't have this sprite! } } print("No class claimed this Map ID > objId $objId"); return null; // No class claimed this Map ID } }