generate method

  1. @override
Widget generate(
  1. Context context
)
override

Implementation

@override
Widget generate(Context context) {
  Score? maxScore;
  int? maxStep;
  id = IndexedFile.getIndexed('ray') + 1;

  if (max != null && max! > 0) {
    maxScore = Score(Entity.Self(), scoreName);
    maxStep = max! ~/ step;
  }

  var children = <Widget>[
    If.not(through, then: [_isHit.add()])
  ];
  if (ray != null) children.insert(0, ray!(_stop, _hit));

  /// all and conditions
  var conds = <Condition>[Condition.not(_isHit)];
  if (_useStop) conds.add(Condition.not(_isStopped));
  if (maxScore != null) {
    children.add(maxScore.add());
    conds.add(Condition(maxScore.matchesRange(Range.to(maxStep))));
  }

  children.add(
    Execute(
      If: Condition.and(conds),
      children: [File.recursive()],
    ).positioned(
      Location.local(z: step),
    ),
  );

  onhit.insert(
    0,
    Comment(
      'This is the raycast result from your raycast widget in ${context.file}',
    ),
  );
  children.addAll([
    If(Condition.and([_isHit, _useStop ? Condition.not(_isStopped) : null]),
        then: [
          File.execute(
            'objd/rayhit$id',
            child: For.of(onhit),
          ),
        ]),
    _isHit.removeIfExists()
  ]);
  if (_useStop) children.add(_isStopped.remove());

  var ex = Execute(children: [
    Group(filename: 'ray', children: children, groupMin: 0),
  ]);
  if (entity.selector != 's') ex = ex.asat(entity);
  ex = ex
      .anchored(Facing.eyes)
      .positioned(Location.local())
      .anchored(Facing.feet);

  if (maxScore != null) return For.of([maxScore.set(0), ex]);
  return ex;
}