diff --git a/Content.Server/_CorvaxNext/Light/ToggleableOccluderComponent.cs b/Content.Server/_CorvaxNext/Light/ToggleableOccluderComponent.cs new file mode 100644 index 00000000000..bf378f0408e --- /dev/null +++ b/Content.Server/_CorvaxNext/Light/ToggleableOccluderComponent.cs @@ -0,0 +1,29 @@ +using Content.Shared.DeviceLinking; +using Robust.Shared.Prototypes; + +namespace Content.Server.Light.Components; + +/// +/// Allows entities with OccluderComponent to toggle that component on and off. +/// +[RegisterComponent] +public sealed partial class ToggleableOccluderComponent : Component +{ + /// + /// Port for toggling occluding on. + /// + [DataField] + public ProtoId OnPort = "On"; + + /// + /// Port for toggling occluding off. + /// + [DataField] + public ProtoId OffPort = "Off"; + + /// + /// Port for toggling occluding. + /// + [DataField] + public ProtoId TogglePort = "Toggle"; +} diff --git a/Content.Server/_CorvaxNext/Light/ToggleableOccluderSystem.cs b/Content.Server/_CorvaxNext/Light/ToggleableOccluderSystem.cs new file mode 100644 index 00000000000..2bd3e0fd332 --- /dev/null +++ b/Content.Server/_CorvaxNext/Light/ToggleableOccluderSystem.cs @@ -0,0 +1,56 @@ +using Content.Server.DeviceLinking.Events; +using Content.Server.DeviceLinking.Systems; +using Content.Server.Light.Components; + +namespace Content.Server.Light.EntitySystems; + +/// +/// Handles the logic between signals and toggling OccluderComponent +/// +public sealed class ToggleableOccluderSystem : EntitySystem +{ + [Dependency] private readonly DeviceLinkSystem _signalSystem = default!; + [Dependency] private readonly OccluderSystem _occluder = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnSignalReceived); + SubscribeLocalEvent(OnInit); + } + + private void OnInit(EntityUid uid, ToggleableOccluderComponent comp, ComponentInit args) + { + _signalSystem.EnsureSinkPorts(uid, comp.OnPort, comp.OffPort, comp.TogglePort); + } + + private void OnSignalReceived(EntityUid uid, ToggleableOccluderComponent comp, ref SignalReceivedEvent args) + { + if (!TryComp(uid, out var occluder)) + return; + + if (args.Port == comp.OffPort) + SetState(uid, false, occluder); + else if (args.Port == comp.OnPort) + SetState(uid, true, occluder); + else if (args.Port == comp.TogglePort) + ToggleState(uid, occluder); + } + + public void ToggleState(EntityUid uid, OccluderComponent? occluder = null) + { + if (!Resolve(uid, ref occluder)) + return; + + _occluder.SetEnabled(uid, !occluder.Enabled); + } + + public void SetState(EntityUid uid, bool state, OccluderComponent? occluder = null) + { + if (!Resolve(uid, ref occluder)) + return; + + _occluder.SetEnabled(uid, state); + } + +} diff --git a/Resources/Locale/ru-RU/ss14-ru/prototypes/_corvaxnext/entities/structures/windows/window.ftl b/Resources/Locale/ru-RU/ss14-ru/prototypes/_corvaxnext/entities/structures/windows/window.ftl new file mode 100644 index 00000000000..4e1e1954485 --- /dev/null +++ b/Resources/Locale/ru-RU/ss14-ru/prototypes/_corvaxnext/entities/structures/windows/window.ftl @@ -0,0 +1,3 @@ +ent-TintedWindowTransparent = { ent-TintedWindow } + .desc = { ent-TintedWindow.desc } + .suffix = Прозрачный diff --git a/Resources/Locale/ru-RU/ss14-ru/prototypes/entities/structures/windows/window.ftl b/Resources/Locale/ru-RU/ss14-ru/prototypes/entities/structures/windows/window.ftl index f581123a6da..20060449021 100644 --- a/Resources/Locale/ru-RU/ss14-ru/prototypes/entities/structures/windows/window.ftl +++ b/Resources/Locale/ru-RU/ss14-ru/prototypes/entities/structures/windows/window.ftl @@ -1,7 +1,8 @@ ent-Window = окно .desc = Смотри не заляпай. ent-TintedWindow = матовое окно - .desc = { ent-Window.desc } +# Corvax-Next-Togglable-Tinted-Window Changed desc + .desc = Умное тонированое окно с функцией переключения состояния. ent-WindowRCDResistant = { ent-Window } .desc = { ent-Window.desc } ent-WindowDirectional = направленное окно diff --git a/Resources/Prototypes/Entities/Structures/Windows/window.yml b/Resources/Prototypes/Entities/Structures/Windows/window.yml index ce7fc5ea3cd..331810e37a9 100644 --- a/Resources/Prototypes/Entities/Structures/Windows/window.yml +++ b/Resources/Prototypes/Entities/Structures/Windows/window.yml @@ -111,6 +111,14 @@ - type: Occluder - type: StaticPrice price: 70 +# Corvax-Next-Togglable-Tinted-Window-Start + - type: ToggleableOccluder + - type: DeviceLinkSink + ports: + - On + - Off + - Toggle +# Corvax-Next-Togglable-Tinted-Window-End - type: entity id: WindowRCDResistant diff --git a/Resources/Prototypes/_CorvaxNext/Entities/Structures/Windows/window.yml b/Resources/Prototypes/_CorvaxNext/Entities/Structures/Windows/window.yml new file mode 100644 index 00000000000..1f38a259cd9 --- /dev/null +++ b/Resources/Prototypes/_CorvaxNext/Entities/Structures/Windows/window.yml @@ -0,0 +1,7 @@ +- type: entity + parent: TintedWindow + id: TintedWindowTransparent + suffix: Transparent + components: + - type: Occluder + enabled: false