# SPDX-FileCopyrightText: 2025 GoobBot <uristmchands@proton.me>
# SPDX-FileCopyrightText: 2025 cheetah1984 <davidc71114@gmail.com>
# SPDX-FileCopyrightText: 2025 deltanedas <39013340+deltanedas@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 deltanedas <@deltanedas:kde.org>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

- type: entity
  parent: [ ConstructibleMachine, BaseMachinePowered, BaseAutomatedMachine ]
  id: Interactor
  name: interactor
  description: A robotic actuator specialized in interacting with objects using tools.
  components:
  # Visuals
  - type: Sprite
    sprite: _Goobstation/Structures/Machines/interactor.rsi
    layers:
    - state: base
    - state: empty
      map: [ enum.InteractorLayers.Hand ]
    - state: empty-powered
      shader: unshaded
      visible: false
      map: [ enum.InteractorLayers.Powered ]
  - type: Appearance
  - type: GenericVisualizer
    visuals:
      enum.PowerDeviceVisuals.Powered:
        enum.InteractorLayers.Powered:
          True: { visible: true }
          False: { visible: false }
      enum.InteractorVisuals.State:
        enum.InteractorLayers.Hand:
          Empty: { state: empty }
          Inactive: { state: inactive }
          Active: { state: active }
        enum.InteractorLayers.Powered:
          Empty: { state: empty-powered }
          Inactive: { state: inactive-powered }
          Active: { state: active-powered }
  # Physics
  - type: Transform
    noRot: false
  - type: Rotatable
    rotateWhileAnchored: true
  - type: Fixtures
    fixtures:
      fix1:
        shape: !type:PhysShapeCircle
          radius: 0.25
        density: 200
        mask:
        - MachineMask
        layer:
        - MachineLayer
  # Construction
  - type: Machine
    board: InteractorCircuitboard
  - type: Construction
    containers:
    - machine_board
    - machine_parts
    - interactor_tool
    - filter_slot
  - type: EmptyOnMachineDeconstruct
    containers:
    - interactor_tool
    - filter_slot
  - type: ContainerContainer
    containers:
      machine_board: !type:Container
      machine_parts: !type:Container
      interactor_tool: !type:ContainerSlot
      filter_slot: !type:ContainerSlot
  # Interactor
  - type: ItemSlots
    slots:
      filter_slot:
        whitelist:
          components:
          - AutomationFilter
  - type: Interactor
  - type: StartableMachine
  - type: FilterSlot
  - type: AutomationSlots
    slots:
    - !type:AutomatedHand
      input: AutomationSlotTool
      output: AutomationSlotTool
      handName: interactor_tool
    - !type:AutomatedItemSlot
      input: AutomationSlotFilter
      output: AutomationSlotFilter
      slotId: filter_slot
  - type: UseDelay
    delay: 0.5 # to avoid tps lag machines
  # Fake interaction stuff
  - type: DoAfter
    raiseEndedEvent: true # so Completed can be fired off
  - type: Hands
    showInHands: false
  - type: Strippable
    handDelay: 0.5
  - type: UserInterface # need stripping to be able to add/remove items without a robotic arm
    interfaces:
      enum.StrippingUiKey.Key:
        type: StrippableBoundUserInterface
  - type: HandsFill
    hands:
      interactor_tool: null # no tool by default
  - type: ComplexInteraction
  # Linking
  - type: DeviceLinkSink
    ports:
    - Start
    - AutoStart
    - AltInteract
  - type: DeviceLinkSource
    ports:
    - Started
    - Completed
    - Failed
  - type: DeviceNetwork
    deviceNetId: Wireless
    receiveFrequencyId: BasicDevice
  - type: WirelessNetworkConnection
    range: 5
  # Power
  - type: ApcPowerReceiver
    powerLoad: 750
  - type: PowerSwitch
