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

Togglable tinted windows #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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/_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)
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
{
_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)
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
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)
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
{
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 = Умное тонированое окно с функцией переключения состояния.
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading