- type: entity
  parent: BaseItem
  id: LogicEmptyCircuit
  name: empty circuit
  description: Something seems to be missing.
  components:
  - type: Sprite
    drawdepth: ThinPipe
    sprite: Objects/Devices/gates.rsi
    layers:
    - state: base
  - type: Anchorable
  - type: Rotatable
  - type: Construction
    graph: LogicGate
    node: empty

- type: entity
  abstract: true
  parent: LogicEmptyCircuit
  id: BaseLogicItem
  components:
  - type: DeviceNetwork
    deviceNetId: Wireless
    receiveFrequencyId: BasicDevice
  - type: WirelessNetworkConnection
    range: 200

- type: entity
  parent: BaseLogicItem
  id: LogicGateOr
  name: logic gate
  description: A logic gate with two inputs and one output. Technicians can change its mode of operation using a screwdriver.
  suffix: Or
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: or
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
  - type: UseDelay
    delay: 0.5
  - type: DeviceLinkSink
    ports:
    - InputA
    - InputB
  - type: DeviceLinkSource
    ports:
    - Output
    lastSignals:
      Output: false
  - type: Construction
    node: logic_gate
  - type: Appearance
  - type: GenericVisualizer
    visuals:
      enum.LogicGateVisuals.Gate:
        enum.LogicGateLayers.Gate:
          Or: { state: or }
          And: { state: and }
          Xor: { state: xor }
          Nor: { state: nor }
          Nand: { state: nand }
          Xnor: { state: xnor }
      enum.LogicGateVisuals.InputA:
        enum.LogicGateLayers.InputA:
          True: { visible: true }
          False: { visible: false }
      enum.LogicGateVisuals.InputB:
        enum.LogicGateLayers.InputB:
          True: { visible: true }
          False: { visible: false }
      enum.LogicGateVisuals.Output:
        enum.LogicGateLayers.Output:
          True: { visible: true }
          False: { visible: false }
- type: entity
  parent: LogicGateOr
  id: LogicGateAnd
  suffix: And
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: and
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
    gate: And

- type: entity
  parent: LogicGateOr
  id: LogicGateXor
  suffix: Xor
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: xor
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
    gate: Xor

- type: entity
  parent: LogicGateOr
  id: LogicGateNor
  suffix: Nor
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: nor
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
    gate: Nor

- type: entity
  parent: LogicGateOr
  id: LogicGateNand
  suffix: Nand
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: nand
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
    gate: Nand

- type: entity
  parent: LogicGateOr
  id: LogicGateXnor
  suffix: Xnor
  components:
  - type: Sprite
    layers:
    - state: base
    - state: logic
    - state: logic_a
      visible: false
      map: [ "enum.LogicGateLayers.InputA" ]
    - state: logic_b
      visible: false
      map: [ "enum.LogicGateLayers.InputB" ]
    - state: logic_o
      visible: false
      map: [ "enum.LogicGateLayers.Output" ]
    - state: xnor
      map: [ "enum.LogicGateLayers.Gate" ]
  - type: LogicGate
    gate: Xnor

- type: entity
  parent: BaseLogicItem
  id: EdgeDetector
  name: edge detector
  description: Splits rising and falling edges into unique pulses and detects how edgy you are.
  components:
  - type: Sprite
    layers:
    - state: base
    - state: edge_detector
  - type: EdgeDetector
  - type: DeviceLinkSink
    ports:
    - Input
  - type: DeviceLinkSource
    ports:
    - OutputHigh
    - OutputLow
    lastSignals:
      OutputHigh: false
      OutputLow: false
  - type: Construction
    node: edge_detector

- type: entity
  parent: BaseLogicItem
  id: PowerSensor
  name: power sensor
  description: Generates signals in response to powernet changes. Can be cycled between cable voltages.
  components:
  - type: Sprite
    layers:
    - state: base
    - state: power_sensor
  - type: PowerSensor
  - type: PowerSwitchable
    examineText: power-sensor-voltage-examine
    switchText: power-sensor-voltage-switch
    cables:
    - voltage: HV
      node: hv
    - voltage: MV
      node: mv
    - voltage: LV
      node: lv
  - type: UseDelay
    delay: 1
  - type: NodeContainer
    examinable: true
    nodes:
      hv:
        !type:CableDeviceNode
        nodeGroupID: HVPower
      mv:
        !type:CableDeviceNode
        nodeGroupID: MVPower
        enabled: false
      lv:
        !type:CableDeviceNode
        nodeGroupID: Apc
        enabled: false
  - type: DeviceLinkSource
    ports:
    - PowerCharging
    - PowerDischarging
    lastSignals:
      PowerCharging: false
      PowerDischarging: false
  - type: Construction
    node: power_sensor

- type: entity
  parent: BaseLogicItem
  id: MemoryCell
  name: memory cell
  description: A D-Latch circuit that stores a signal which can be changed depending on input and enable ports.
  components:
  - type: Sprite
    layers:
    - state: base
    - state: memory_cell
  - type: MemoryCell
  - type: DeviceLinkSink
    ports:
    - MemoryInput
    - MemoryEnable
  - type: DeviceLinkSource
    ports:
    - Output
  - type: Construction
    node: memory_cell
    
- type: entity
  parent: BaseLogicItem
  id: RandomGate
  name: random gate
  description: A logic gate that outputs a random signal when input changes.
  components:
  - type: Sprite
    layers:
    - state: base
    - state: random_gate
  - type: RandomGate
  - type: DeviceLinkSink
    ports:
    - RandomGateInput
  - type: DeviceLinkSource
    ports:
    - Output
  - type: UserInterface
    interfaces:
      enum.RandomGateUiKey.Key:
        type: RandomGateBoundUserInterface
  - type: ActivatableUI
    key: enum.RandomGateUiKey.Key
  - type: Construction
    node: random_gate
