<commit_before>// ignore_for_file: avoid_renaming_method_parameters

import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_components/src/components/sparky_computer/behaviors/behaviors.dart';
import 'package:pinball_flame/pinball_flame.dart';

export 'cubit/sparky_computer_cubit.dart';

/// {@template sparky_computer}
/// A computer owned by Sparky.
/// {@endtemplate}
class SparkyComputer extends BodyComponent {
  /// {@macro sparky_computer}
  SparkyComputer({Iterable<Component>? children})
      : bloc = SparkyComputerCubit(),
        super(
          renderBody: false,
          children: [
            SparkyComputerSensorBallContactBehavior()
              ..applyTo(['turbo_charge_sensor']),
            _ComputerBaseSpriteComponent(),
            _ComputerTopSpriteComponent(),
            _ComputerGlowSpriteComponent(),
            ...?children,
          ],
        );

  /// Creates a [SparkyComputer] without any children.
  ///
  /// This can be used for testing [SparkyComputer]'s behaviors in isolation.
  @visibleForTesting
  SparkyComputer.test({
    required this.bloc,
    Iterable<Component>? children,
  }) : super(children: children);

  final SparkyComputerCubit bloc;

  @override
  void onRemove() {
    bloc.close();
    super.onRemove();
  }

  List<FixtureDef> _createFixtureDefs() {
    final leftEdge = EdgeShape()
      ..set(
        Vector2(-15.3, -45.9),
        Vector2(-15.7, -49.5),
      );
    final topEdge = EdgeShape()
      ..set(
        leftEdge.vertex2,
        Vector2(-11.1, -50.5),
      );
    final rightEdge = EdgeShape()
      ..set(
        topEdge.vertex2,
        Vector2(-9.4, -47.1),
      );
    final turboChargeSensor = PolygonShape()
      ..setAsBox(
        1,
        0.1,
        Vector2(-13.2, -49.9),
        -0.18,
      );

    return [
      FixtureDef(leftEdge),
      FixtureDef(topEdge),
      FixtureDef(rightEdge),
      FixtureDef(
        turboChargeSensor,
        isSensor: true,
        userData: 'turbo_charge_sensor',
      ),
    ];
  }

  @override
  Body createBody() {
    final body = world.createBody(BodyDef());
    _createFixtureDefs().forEach(body.createFixture);

    return body;
  }
}

class _ComputerBaseSpriteComponent extends SpriteComponent
    with HasGameRef, ZIndex {
  _ComputerBaseSpriteComponent()
      : super(
          anchor: Anchor.center,
          position: Vector2(-12.44, -48.15),<commit_msg>fix: move `SparkyComputer` sensor (#386)<commit_after>// ignore_for_file: avoid_renaming_method_parameters

import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_components/src/components/sparky_computer/behaviors/behaviors.dart';
import 'package:pinball_flame/pinball_flame.dart';

export 'cubit/sparky_computer_cubit.dart';

/// {@template sparky_computer}
/// A computer owned by Sparky.
/// {@endtemplate}
class SparkyComputer extends BodyComponent {
  /// {@macro sparky_computer}
  SparkyComputer({Iterable<Component>? children})
      : bloc = SparkyComputerCubit(),
        super(
          renderBody: false,
          children: [
            SparkyComputerSensorBallContactBehavior()
              ..applyTo(['turbo_charge_sensor']),
            _ComputerBaseSpriteComponent(),
            _ComputerTopSpriteComponent(),
            _ComputerGlowSpriteComponent(),
            ...?children,
          ],
        );

  /// Creates a [SparkyComputer] without any children.
  ///
  /// This can be used for testing [SparkyComputer]'s behaviors in isolation.
  @visibleForTesting
  SparkyComputer.test({
    required this.bloc,
    Iterable<Component>? children,
  }) : super(children: children);

  final SparkyComputerCubit bloc;

  @override
  void onRemove() {
    bloc.close();
    super.onRemove();
  }

  List<FixtureDef> _createFixtureDefs() {
    final leftEdge = EdgeShape()
      ..set(
        Vector2(-15.3, -45.9),
        Vector2(-15.7, -49.5),
      );
    final topEdge = EdgeShape()
      ..set(
        leftEdge.vertex2,
        Vector2(-11.1, -50.5),
      );
    final rightEdge = EdgeShape()
      ..set(
        topEdge.vertex2,
        Vector2(-9.4, -47.1),
      );
    final turboChargeSensor = PolygonShape()
      ..setAsBox(
        1,
        0.1,
        Vector2(-13.1, -49.7),
        -0.18,
      );

    return [
      FixtureDef(leftEdge),
      FixtureDef(topEdge),
      FixtureDef(rightEdge),
      FixtureDef(
        turboChargeSensor,
        isSensor: true,
        userData: 'turbo_charge_sensor',
      ),
    ];
  }

  @override
  Body createBody() {
    final body = world.createBody(BodyDef());
    _createFixtureDefs().forEach(body.createFixture);

    return body;
  }
}

class _ComputerBaseSpriteComponent extends SpriteComponent
    with HasGameRef, ZIndex {
  _ComputerBaseSpriteComponent()
      : super(
          anchor: Anchor.center,
          position: Vector2(-12.44, -48.15),
{'fraction_non_alphanumeric': 0.12318980498165669, 'fraction_numerical': 0.02104653407993821, 'mean_word_length': 2.640196767392832, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4827493', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1641, 'n_words': 289}