# SPDX-FileCopyrightText: 2021 20kdc <asdd2808@gmail.com>
# SPDX-FileCopyrightText: 2021 DrSmugleaf <DrSmugleaf@users.noreply.github.com>
# SPDX-FileCopyrightText: 2021 Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
# SPDX-FileCopyrightText: 2021 Vera Aguilera Puerto <gradientvera@outlook.com>
# SPDX-FileCopyrightText: 2021 Vera Aguilera Puerto <zddm@outlook.es>
# SPDX-FileCopyrightText: 2021 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
# SPDX-FileCopyrightText: 2021 metalgearsloth <comedian_vs_clown@hotmail.com>
# SPDX-FileCopyrightText: 2022 Moony <moonheart08@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Peptide90 <78795277+Peptide90@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Rane <60792108+Elijahrane@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 iacore <74560659+iacore@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
#
# SPDX-License-Identifier: MIT

- type: constructionGraph
  id: Machine
  start: start
  graph:
    - node: start
      actions:
        - !type:SpawnPrototype
          prototype: SheetSteel1
        - !type:DeleteEntity
      edges:
        - to: missingWires
          completed:
            - !type:SetAnchor
              value: false
          steps:
            - material: Steel
              amount: 5
              doAfter: 2.5
        - to: destroyedMachineFrame
          steps:
            - material: Steel
              amount: 5
              doAfter: 2.5

    - node: missingWires
      entity: UnfinishedMachineFrame
      actions:
        - !type:EmptyAllContainers
      edges:
        - to: machineFrame
          conditions:
            - !type:EntityAnchored
          steps:
            - material: Cable
        - to: start
          completed:
            - !type:SpawnPrototype
              prototype: SheetSteel1
              amount: 5
            - !type:DeleteEntity
          steps:
            - tool: Screwing
              doAfter: 2

    - node: machineFrame
      entity: MachineFrame
      actions:
        - !type:AddContainer
          container: machine_parts
        - !type:AddContainer
          container: machine_board
        - !type:MachineFrameRegenerateProgress
      edges:
        - to: machine
          conditions:
            - !type:EntityAnchored
            - !type:MachineFrameComplete
              guideIconBoard:
                sprite: Objects/Misc/module.rsi
                state: id_mod
              guideIconParts:
                sprite: Objects/Misc/stock_parts.rsi
                state: scan_module
          steps:
            - tool: Screwing
              doAfter: 0.5

        - to: machineFrame
          conditions:
            - !type:EntityAnchored
            - !type:ContainerNotEmpty
              container: machine_board
          steps:
            - tool: Prying
              doAfter: 2
              completed:
                - !type:EmptyAllContainers
                - !type:MachineFrameRegenerateProgress

        - to: missingWires
          conditions:
            - !type:EntityAnchored
            - !type:ContainerEmpty
              container: machine_board
              examineText: construction-condition-machine-container-empty
          completed:
            - !type:SpawnPrototype
              prototype: CableApcStack1
          steps:
            - tool: Cutting
              doAfter: 0.25

    - node: machine
      entity: !type:BoardNodeEntity { container: machine_board }
      edges:
        - to: machineFrame
          completed:
            - !type:RaiseEvent
              event: !type:MachineDeconstructedEvent
              broadcast: false
          conditions:
            - !type:EntityAnchored
            - !type:WirePanel
          steps:
            - tool: Prying
              doAfter: 2

    - node: destroyedMachineFrame
      entity: MachineFrameDestroyed
      edges:
        - to: start
          steps:
            - tool: Welding
              doAfter: 5
          completed:
            - !type:SpawnPrototype
              prototype: SheetSteel1
              amount: 3
            - !type:DeleteEntity {}