# SPDX-FileCopyrightText: 2021 20kdc <asdd2808@gmail.com>
# SPDX-FileCopyrightText: 2021 Galactic Chimp <GalacticChimpanzee@gmail.com>
# SPDX-FileCopyrightText: 2021 SETh lafuente <cetaciocascarudo@gmail.com>
# SPDX-FileCopyrightText: 2021 SethLafuente <84478872+SethLafuente@users.noreply.github.com>
# SPDX-FileCopyrightText: 2021 ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
# SPDX-FileCopyrightText: 2021 Swept <sweptwastaken@protonmail.com>
# SPDX-FileCopyrightText: 2021 Vera Aguilera Puerto <gradientvera@outlook.com>
# SPDX-FileCopyrightText: 2021 cheesePizza2 <34486300+cheesePizza2@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Alex Evgrashin <aevgrashin@yandex.ru>
# SPDX-FileCopyrightText: 2022 BismarckShuffle <107375341+BismarckShuffle@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Delete69 <95458399+Delete69@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Flipp Syder <76629141+vulppine@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Júlio César Ueti <52474532+Mirino97@users.noreply.github.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: 2022 Visne <39844191+Visne@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Willhelm53 <97707302+Willhelm53@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 metalgearsloth <comedian_vs_clown@hotmail.com>
# SPDX-FileCopyrightText: 2022 metalgearsloth <metalgearsloth@gmail.com>
# SPDX-FileCopyrightText: 2022 mirrorcult <lunarautomaton6@gmail.com>
# SPDX-FileCopyrightText: 2023 Darkie <darksaiyanis@gmail.com>
# SPDX-FileCopyrightText: 2023 Emisse <99158783+Emisse@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Flareguy <78941145+Flareguy@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Vordenburg <114301317+Vordenburg@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 brainfood1183 <113240905+brainfood1183@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 lzk <124214523+lzk228@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Aiden <aiden@djkraz.com>
# SPDX-FileCopyrightText: 2024 Alzore <140123969+Blackern5000@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Ed <96445749+TheShuEd@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 FoxxoTrystan <45297731+FoxxoTrystan@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Ilya246 <57039557+Ilya246@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Kara <lunarautomaton6@gmail.com>
# SPDX-FileCopyrightText: 2024 MACMAN2003 <macman2003c@gmail.com>
# SPDX-FileCopyrightText: 2024 Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Pspritechologist <naaronn@gmail.com>
# SPDX-FileCopyrightText: 2024 VMSolidus <evilexecutive@gmail.com>
# SPDX-FileCopyrightText: 2024 Vigers Ray <60344369+VigersRay@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 chromiumboy <50505512+chromiumboy@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 cohanna <conornhanna@gmail.com>
# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Southbridge <7013162+southbridge-fur@users.noreply.github.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

- type: entity
  id: Window
  parent: BaseStructure
  name: window
  description: Don't smudge up the glass down there.
  placement:
    mode: SnapgridCenter
    snap:
    - Window
  components:
  - type: MeleeSound
    soundGroups:
      Brute:
        collection: GlassSmack
  - type: WallMount
    arc: 360 # interact despite grilles
  - type: Tag
    tags:
      - ForceFixRotations
      - Window
  - type: Sprite
    drawdepth: WallTops
    sprite: Structures/Windows/window.rsi
  - type: Icon
    sprite: Structures/Windows/window.rsi
    state: full
  - type: Physics
    bodyType: Static
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb {}
        mask:
        - FullTileMask
        layer:
        - GlassLayer
  - type: Damageable
    damageContainer: StructuralInorganic
    damageModifierSet: Glass
  - type: ExaminableDamage
    messages: WindowMessages
  - type: Repairable
  - type: RCDDeconstructable
    cost: 6
    delay: 4
    fx: EffectRCDDeconstruct4
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 150 #excess damage (nuke?). avoid computational cost of spawning entities.
      behaviors:
      - !type:PlaySoundBehavior
        sound:
          collection: WindowShatter
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:PlaySoundBehavior
        sound:
          collection: WindowShatter
      - !type:SpawnEntitiesBehavior
        spawn:
          ShardGlass:
            min: 1
            max: 2
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: Airtight
  - type: IconSmooth
    key: walls
    base: window
  - type: InteractionPopup
    interactSuccessString: comp-window-knock
    messagePerceivedByOthers: comp-window-knock
    interactSuccessSound:
      path: /Audio/Effects/glass_knock.ogg
  - type: Construction
    graph: Window
    node: window
  - type: Appearance
  - type: DamageVisuals
    thresholds: [5, 10, 20]
    damageDivisor: 2
    trackAllDamage: true
    damageOverlay:
      sprite: Structures/Windows/cracks.rsi
  - type: StaticPrice
    price: 100
  - type: BlockWeather

- type: entity
  parent: Window
  id: TintedWindow
  name: tinted window
  description: Smart tinted window with state switching option.
  components:
  - type: Sprite
    drawdepth: WallTops
    sprite: Structures/Windows/tinted_window.rsi
  - type: Icon
    sprite: Structures/Windows/tinted_window.rsi
  - type: IconSmooth
    base: twindow
  - type: Construction
    graph: Window
    node: tintedWindow
  - type: Occluder
  - type: StaticPrice
    price: 70
  - type: CosmicCorruptible # DeltaV - Cosmic Cult
    convertTo: WindowCosmicCult
  - type: ToggleableOccluder # Goob
  - type: DeviceLinkSink # Goob
    ports:
    - On
    - Off
    - Toggle

- type: entity # Goob
  parent: TintedWindow
  id: TintedWindowTransparent
  suffix: Transparent
  components:
  - type: Occluder
    enabled: false

- type: entity
  id: WindowRCDResistant
  parent: Window
  abstract: true
  components:
  - type: RCDDeconstructable
    deconstructable: false

- type: entity
  id: WindowDirectional
  parent: BaseStructure
  name: directional window
  description: Don't smudge up the glass down there.
  placement:
    mode: SnapgridCenter
    snap:
    - Window
  components:
  - type: WallMount
    arc: 360 # interact despite grilles
  - type: Tag
    tags:
      - Window
  - type: MeleeSound
    soundGroups:
      Brute:
        collection: GlassSmack
  - type: Sprite
    drawdepth: Mobs
    sprite: Structures/Windows/directional.rsi
    state: window
  - type: Icon
    sprite: Structures/Windows/directional.rsi
    state: window
  - type: InteractionPopup
    interactSuccessString: comp-window-knock
    messagePerceivedByOthers: comp-window-knock
    interactSuccessSound:
      path: /Audio/Effects/glass_knock.ogg
  - type: Physics
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-0.5,-0.5,0.5,-0.28125"
        density: 1500
        mask:
        - FullTileMask
        layer:
        - GlassLayer
  - type: Repairable
  - type: Damageable
    damageContainer: StructuralInorganic
    damageModifierSet: Glass
  - type: ExaminableDamage
    messages: WindowMessages
  - type: RCDDeconstructable
    cost: 4
    delay: 2
    fx: EffectRCDDeconstruct2
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 50 #excess damage (nuke?). avoid computational cost of spawning entities.
      behaviors:
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
      - !type:PlaySoundBehavior
        sound:
          collection: WindowShatter
    - trigger:
        !type:DamageTrigger
        damage: 25
      behaviors:
      - !type:PlaySoundBehavior
        sound:
          collection: WindowShatter
      - !type:SpawnEntitiesBehavior
        spawn:
          ShardGlass:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: Airtight
    noAirWhenFullyAirBlocked: false
    airBlockedDirection:
    - South
  - type: Construction
    graph: WindowDirectional
    node: windowDirectional
  - type: Appearance
  - type: DamageVisuals
    thresholds: [5, 10, 20]
    trackAllDamage: true
    damageOverlay:
      sprite: Structures/Windows/cracks_directional.rsi
  - type: StaticPrice
    price: 10

- type: entity
  id: WindowDirectionalRCDResistant
  parent: WindowDirectional
  abstract: true
  components:
  - type: RCDDeconstructable
    deconstructable: false

- type: entity
  id: WindowFrostedDirectional
  parent: WindowDirectional
  name: directional frosted window
  description: Don't smudge up the glass down there.
  placement:
    mode: SnapgridCenter
    snap:
    - Window
  components:
  - type: Sprite
    sprite: Structures/Windows/directional.rsi
    state: frosted_window
  - type: Icon
    sprite: Structures/Windows/directional.rsi
    state: frosted_window
  - type: StaticPrice
    price: 35

- type: entity
  parent: Window
  id: WindowDiagonal
  suffix: diagonal
  placement:
    mode: SnapgridCenter
    snap:
    - Window
  components:
  - type: Sprite
    drawdepth: WallTops
    sprite: Structures/Windows/window_diagonal.rsi
    state: state0
  - type: Tag
    tags:
    - Diagonal
    - Window
  - type: IconSmooth
    mode: Diagonal
    key: windows
    base: state
  - type: Icon
    sprite: Structures/Windows/window_diagonal.rsi
    state: state0
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PolygonShape
            vertices:
            - "-0.5,-0.5"
            - "0.5,0.5"
            - "0.5,-0.5"
        mask:
        - FullTileMask
        layer:
        - GlassLayer
  - type: Airtight
    noAirWhenFullyAirBlocked: false
    airBlockedDirection:
    - South
    - East
  - type: DamageVisuals
    damageOverlay:
      sprite: Structures/Windows/cracks_diagonal.rsi
  - type: Construction
    graph: WindowDiagonal
    node: windowDiagonal
