import 'component.dart'; /// 实体ID生成器 class EntityIdGenerator { static int _id = 0; static int nextId() => _id++; } /// 实体类 - 代表地图上的一个对象 class Entity { final int id; final String name; int entityType; final Map _components = {}; Entity({int? id, required this.name, this.entityType = 0}) : id = id ?? EntityIdGenerator.nextId(); /// 添加组件 void addComponent(T component) { _components[T.toString()] = component; } /// 获取组件 T? getComponent() { return _components[T.toString()] as T?; } /// 检查是否有特定类型的组件 bool hasComponent() { return _components.containsKey(T.toString()); } /// 移除组件 void removeComponent() { _components.remove(T.toString()); } /// 获取所有组件 Map get components => _components; }