Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tinted windows toggleable #30743

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Content.Server/Light/Components/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/Light/EntitySystems/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);
}

}
15 changes: 15 additions & 0 deletions Resources/Prototypes/Entities/Structures/Windows/window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
parent: Window
id: TintedWindow
name: tinted window
description: Smart tinted window with state switching option.
components:
- type: Sprite
drawdepth: WallTops
Expand All @@ -111,6 +112,20 @@
- type: Occluder
- type: StaticPrice
price: 70
- type: ToggleableOccluder
- type: DeviceLinkSink
ports:
- On
- Off
- Toggle

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

- type: entity
id: WindowRCDResistant
Expand Down
Loading