preAdd method

  1. @mustCallSuper
void preAdd(
  1. Component c
)

This method is called for every component added, both via add and addLater methods.

You can use this to setup your mixins, pre-calculate stuff on every component, or anything you desire. By default, this calls the first time resize for every component, so don't forget to call super.preAdd when overriding.

Implementation

@mustCallSuper
void preAdd(Component c) {
  if (c is Tapable) {
    assert(
      this is HasTapableComponents,
      'Tapable Components can only be added to a BaseGame with HasTapableComponents',
    );
  }

  if (debugMode() && c is PositionComponent) {
    c.debugMode = true;
  }

  if (c is HasGameRef) {
    (c as HasGameRef).gameRef = this;
  }

  // first time resize
  if (size != null) {
    c.resize(size);
  }

  if (c is ComposedComponent) {
    c.components.forEach(preAdd);
  }

  c.onMount();
}