Dart DocumentationdartemisTagManager

TagManager class

If you need to tag any entity, use this. A typical usage would be to tag entities such as "PLAYER", "BOSS" or something that is very unique. An Entity can only belong to one tag (0,1) at a time.

class TagManager extends Manager {
 final Map<String, Entity> _entitiesByTag;
 final Map<Entity, String> _tagsByEntity;

 TagManager() : _entitiesByTag = new Map<String, Entity>(),
                _tagsByEntity = new Map<Entity, String>();

 void register(Entity e, String tag) {
   _entitiesByTag[tag] = e;
   _tagsByEntity[e] = tag;
 }

 void unregister(String tag) {
   _tagsByEntity.remove(_entitiesByTag.remove(tag));
 }

 bool isRegistered(String tag) => _entitiesByTag.containsKey(tag);
 Entity getEntity(String tag) => _entitiesByTag[tag];
 Iterable<String> getRegisteredTags() => _tagsByEntity.values;

 void deleted(Entity e) {
   String removedTag = _tagsByEntity.remove(e);
   if(removedTag != null) {
     _entitiesByTag.remove(removedTag);
   }
 }

 void initialize() {}
}

Extends

Manager > TagManager

Constructors

new TagManager() #

TagManager() : _entitiesByTag = new Map<String, Entity>(),
              _tagsByEntity = new Map<Entity, String>();

Methods

void added(Entity e) #

inherited from Manager
void added(Entity e) {}

void changed(Entity e) #

inherited from Manager
void changed(Entity e) {}

void deleted(Entity e) #

void deleted(Entity e) {
 String removedTag = _tagsByEntity.remove(e);
 if(removedTag != null) {
   _entitiesByTag.remove(removedTag);
 }
}

void disabled(Entity e) #

inherited from Manager
void disabled(Entity e) {}

void enabled(Entity e) #

inherited from Manager
void enabled(Entity e) {}

Entity getEntity(String tag) #

Entity getEntity(String tag) => _entitiesByTag[tag];

Iterable<String> getRegisteredTags() #

Iterable<String> getRegisteredTags() => _tagsByEntity.values;

void initialize() #

void initialize() {}

bool isRegistered(String tag) #

bool isRegistered(String tag) => _entitiesByTag.containsKey(tag);

void register(Entity e, String tag) #

void register(Entity e, String tag) {
 _entitiesByTag[tag] = e;
 _tagsByEntity[e] = tag;
}

void unregister(String tag) #

void unregister(String tag) {
 _tagsByEntity.remove(_entitiesByTag.remove(tag));
}