Skip to content

Commit

Permalink
Togglable tinted windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lzk228 committed Nov 18, 2024
1 parent 7c15f5d commit de25fd6
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Content.Server/_CorvaxNext/Light/ToggleableOccluderComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.DeviceLinking;
using Robust.Shared.Prototypes;

namespace Content.Server.Light.Components;

/// <summary>
/// Allows entities with OccluderComponent to toggle that component on and off.
/// </summary>
[RegisterComponent]
public sealed partial class ToggleableOccluderComponent : Component
{
/// <summary>
/// Port for toggling occluding on.
/// </summary>
[DataField]
public ProtoId<SinkPortPrototype> OnPort = "On";

/// <summary>
/// Port for toggling occluding off.
/// </summary>
[DataField]
public ProtoId<SinkPortPrototype> OffPort = "Off";

/// <summary>
/// Port for toggling occluding.
/// </summary>
[DataField]
public ProtoId<SinkPortPrototype> TogglePort = "Toggle";
}
56 changes: 56 additions & 0 deletions Content.Server/_CorvaxNext/Light/ToggleableOccluderSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Light.Components;

namespace Content.Server.Light.EntitySystems;

/// <summary>
/// Handles the logic between signals and toggling OccluderComponent
/// </summary>
public sealed class ToggleableOccluderSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
[Dependency] private readonly OccluderSystem _occluder = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ToggleableOccluderComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<ToggleableOccluderComponent, ComponentInit>(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<OccluderComponent>(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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ent-TintedWindowTransparent = { ent-TintedWindow }
.desc = { ent-TintedWindow.desc }
.suffix = Прозрачный
Original file line number Diff line number Diff line change
@@ -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 = направленное окно
Expand Down
8 changes: 8 additions & 0 deletions Resources/Prototypes/Entities/Structures/Windows/window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- type: entity
parent: TintedWindow
id: TintedWindowTransparent
suffix: Transparent
components:
- type: Occluder
enabled: false

0 comments on commit de25fd6

Please sign in to comment.