# SPDX-FileCopyrightText: 2025 GoobBot <uristmchands@proton.me>
# 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 ]
  id: RoboticArm
  name: robotic arm
  description: A high-tech robotic arm capable of moving items to and from machines that have automation upgrades.
  components:
  # Visuals
  - type: Sprite
    sprite: _Goobstation/Structures/Machines/robotic_arm.rsi
    layers:
    - state: base
    - state: arm-long
      map: [ "enum.RoboticArmLayers.Arm" ]
    - state: powered
      shader: unshaded
      visible: false
      map: [ "enum.RoboticArmLayers.Powered" ]
  - type: Appearance
  - type: GenericVisualizer
    visuals:
      enum.RoboticArmVisuals.HasItem:
        enum.RoboticArmLayers.Arm:
          # extended when waiting for items like factorio
          True: { state: arm-short }
          False: { state: arm-long }
      enum.PowerDeviceVisuals.Powered:
        enum.RoboticArmLayers.Powered:
          True: { visible: true }
          False: { visible: false }
  # 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
      robotic_arm_input:
        shape: !type:PhysShapeAabb
          bounds: "0.55,-0.45,1.45,0.45"
        density: 100
        hard: false
        layer:
        - Impassable
  # Construction
  - type: Machine
    board: RoboticArmCircuitboard
  - type: Construction
    containers:
    - machine_board
    - machine_parts
    - robotic_arm_item
    - filter_slot
  - type: EmptyOnMachineDeconstruct
    containers:
    - robotic_arm_item
    - filter_slot
  - type: ContainerContainer
    containers:
      machine_board: !type:Container
      machine_parts: !type:Container
      robotic_arm_item: !type:ContainerSlot
      filter_slot: !type:ContainerSlot
  # Arm
  - type: ItemSlots
    slots:
      robotic_arm_item:
        insertOnInteract: false
        insertSound: null # it plays twice because theres no user to pass to PlayPredicted
        whitelist:
          components:
          - Item
      filter_slot:
        whitelist:
          components:
          - AutomationFilter
  - type: RoboticArm
  # ports are exclusive, you can't have it pull from multiple machines / push to multiple machines
  # use storage bins or conveyors to work around this, probably using filters too
  - type: ExclusiveInputSlot
    port: RoboticArmInput
  - type: ExclusiveOutputSlot
    port: RoboticArmOutput
  - type: FilterSlot
  - type: AutomationSlots
    slots:
    - !type:AutomatedItemSlot
      input: AutomationSlotFilter
      output: AutomationSlotFilter
      slotId: filter_slot
  # Linking
  - type: DeviceLinkSink
    ports:
    - RoboticArmInput
    - Toggle
    - On
    - Off
  - type: DeviceLinkSource
    ports:
    - RoboticArmOutput
    - RoboticArmMoved
    - Powered
  - type: DeviceNetwork
    deviceNetId: Wireless
    receiveFrequencyId: BasicDevice
  - type: WirelessNetworkConnection
    range: 5
  # Power
  - type: ApcPowerReceiver
    powerLoad: 100 # Idle power usage, increases when active
  - type: PowerSwitch
  - type: SignalPowerSwitch
  # Guide
  - type: GuideHelp
    guides:
    - Automation
