49 lines
1.4 KiB
Dart
49 lines
1.4 KiB
Dart
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/brown_guard.dart';
|
|
import 'package:wolf_dart/features/entities/enemies/dog.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<EntitySpawner> _spawners = [
|
|
BrownGuard.trySpawn,
|
|
Dog.trySpawn,
|
|
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;
|
|
|
|
for (final spawner in _spawners) {
|
|
Entity? entity = spawner(objId, x, y, difficulty);
|
|
|
|
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
|
|
}
|
|
}
|