Skip to content

Commit

Permalink
SignalSwitch refactor (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh authored Jul 2, 2023
1 parent add0ff2 commit f130678
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public sealed class SignalSwitchComponent : Component
public bool State;

[DataField("clickSound")]
public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg")
{
Params = new AudioParams()
{
Volume = 8f,
Variation = 0.125f
}
};
}
}
17 changes: 11 additions & 6 deletions Content.Server/DeviceLinking/Systems/SignalSwitchSystem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using Content.Server.DeviceLinking.Components;
using Content.Server.MachineLinking.System;
using Content.Shared.Audio;
using Content.Shared.DeviceLinking;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;

namespace Content.Server.DeviceLinking.Systems
{
public sealed class SignalSwitchSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly DeviceLinkSystem _signal = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;

public override void Initialize()
{
Expand All @@ -21,7 +24,8 @@ public override void Initialize()

private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
{
_signalSystem.EnsureSourcePorts(uid, component.OnPort, component.OffPort);
_signal.EnsureSourcePorts(uid, component.OnPort, component.OffPort);
_appearance.SetData(uid, SignalSwitchVisuals.State, component.State);
}

private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
Expand All @@ -30,9 +34,10 @@ private void OnActivated(EntityUid uid, SignalSwitchComponent component, Activat
return;

component.State = !component.State;
_signalSystem.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
SoundSystem.Play(component.ClickSound.GetSound(), Filter.Pvs(component.Owner), component.Owner,
AudioHelpers.WithVariation(0.125f).WithVolume(8f));

_appearance.SetData(uid, SignalSwitchVisuals.State, component.State);
_signal.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
_audio.PlayPvs(component.ClickSound, uid);

args.Handled = true;
}
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/DeviceLinking/SignalSwitchShared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.Serialization;

namespace Content.Shared.DeviceLinking;

[Serializable, NetSerializable]
public enum SignalSwitchVisuals
{
State
}
11 changes: 10 additions & 1 deletion Resources/Prototypes/Entities/Structures/Wallmounts/switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
canCollide: false
- type: Sprite
sprite: Structures/Wallmounts/switch.rsi
state: on
layers:
- state: off
map: [ "indicator" ]
- type: SignalSwitch
- type: UseDelay
delay: 0.5 # prevent light-toggling auto-clickers.
Expand All @@ -32,6 +34,13 @@
ports:
- On
- Off
- type: Appearance
- type: GenericVisualizer
visuals:
enum.SignalSwitchVisuals.State:
indicator:
True: {state: on}
False: {state: off}

- type: entity
id: SignalButton
Expand Down

0 comments on commit f130678

Please sign in to comment.