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

SignalSwitch refactor #93

Merged
merged 1 commit into from
Jul 2, 2023
Merged
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
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