triggerEvents method

void triggerEvents(
  1. List<ActorComponent> components,
  2. double fromTime,
  3. double toTime,
  4. List<AnimationEventArgs> triggerEvents,
)

Implementation

void triggerEvents(List<ActorComponent> components, double fromTime,
    double toTime, List<AnimationEventArgs> triggerEvents) {
  for (int i = 0; i < _triggerComponents.length; i++) {
    ComponentAnimation keyedComponent = _triggerComponents[i];
    for (final PropertyAnimation? property in keyedComponent.properties) {
      switch (property!.propertyType) {
        case PropertyTypes.trigger:
          List<KeyFrame?> keyFrames = property.keyFrames!;

          int kfl = keyFrames.length;
          if (kfl == 0) {
            continue;
          }

          int idx = 0;
          // Binary find the keyframe index.
          {
            int mid = 0;
            double element = 0.0;
            int start = 0;
            int end = kfl - 1;

            while (start <= end) {
              mid = (start + end) >> 1;
              element = keyFrames[mid]!.time;
              if (element < toTime) {
                start = mid + 1;
              } else if (element > toTime) {
                end = mid - 1;
              } else {
                start = mid;
                break;
              }
            }

            idx = start;
          }

          if (idx == 0) {
            if (kfl > 0 && keyFrames[0]!.time == toTime) {
              ActorComponent component =
                  components[keyedComponent.componentIndex];
              triggerEvents.add(AnimationEventArgs(component.name, component,
                  property.propertyType, toTime, 0.0));
            }
          } else {
            for (int k = idx - 1; k >= 0; k--) {
              KeyFrame frame = keyFrames[k]!;

              if (frame.time > fromTime) {
                ActorComponent component =
                    components[keyedComponent.componentIndex];
                triggerEvents.add(AnimationEventArgs(
                    component.name,
                    component,
                    property.propertyType,
                    frame.time,
                    toTime - frame.time));
                /*triggered.push({
										name:component._Name,
										component:component,
										propertyType:property._Type,
										keyFrameTime:frame._Time,
										elapsed:toTime-frame._Time
									});*/
              } else {
                break;
              }
            }
          }
          break;
        default:
          break;
      }
    }
  }
}