denniskaselow / dartemis

A Dart port of the Artemis Entity System Framework
BSD 2-Clause "Simplified" License
49 stars 6 forks source link

Entity.getComponent can be like getSafe #30

Closed davidB closed 11 years ago

davidB commented 11 years ago

En return null if the components isn't available

  Component _getComponent(Entity e, ComponentType type) {
    int index = type.id;
    Bag<Component> components = _componentsByType[index];
    if(components != null && components.isIndexWithinBounds(e.id)) { //<-- checkIndex
      return components[e.id];
    }
    return null;
denniskaselow commented 11 years ago

Good catch. You're really going into detail ;)