Skip to content

Commit

Permalink
Night vision toggling (#151)
Browse files Browse the repository at this point in the history
* nv toggling

* sound and fixes

* playsound parameter

* sound tweaks

* less variables
  • Loading branch information
pheenty authored Nov 1, 2024
1 parent 9f417bc commit 3526564
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Content.Server/Stories/Nightvision/NightvisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Actions;
using Content.Shared.GameTicking;
using Content.Shared.Inventory.Events;
using Robust.Shared.Player;
Expand All @@ -9,11 +10,14 @@ namespace Content.Server.Stories.Nightvision;
public sealed class NightvisionSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NightvisionClothingComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<NightvisionClothingComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<NightvisionComponent, ComponentStartup>(OnStartUp);
SubscribeLocalEvent<NightvisionComponent, ComponentShutdown>(OnShutdown);
}
private void OnUnequipped(EntityUid uid, NightvisionClothingComponent component, GotUnequippedEvent args)
{
Expand All @@ -28,4 +32,12 @@ private void OnEquipped(EntityUid uid, NightvisionClothingComponent component, G
if (component.Enabled && !HasComp<NightvisionComponent>(args.Equipee) && (args.Slot == "eyes"))
AddComp<NightvisionComponent>(args.Equipee);
}
private void OnStartUp(EntityUid uid, NightvisionComponent component, ComponentStartup args)
{
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
}
private void OnShutdown(EntityUid uid, NightvisionComponent component, ComponentShutdown args)
{
Del(component.ToggleActionEntity);
}
}
11 changes: 10 additions & 1 deletion Content.Shared/Stories/Nightvision/NightvisionComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Content.Shared.Actions;
using Content.Shared.Eye.Blinding.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;

namespace Content.Shared.Stories.Nightvision;
Expand All @@ -8,7 +10,13 @@ namespace Content.Shared.Stories.Nightvision;
public sealed partial class NightvisionComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("enabled"), AutoNetworkedField]
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
[DataField]
public string ToggleAction = "ToggleNightvisionAction";
[DataField, AutoNetworkedField]
public EntityUid? ToggleActionEntity;
[DataField("toggleOnSound")]
public SoundSpecifier? ToggleOnSound = new SoundPathSpecifier("/Audio/Stories/Misc/night_vision.ogg");
}

[RegisterComponent]
Expand All @@ -18,3 +26,4 @@ public sealed partial class NightvisionClothingComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
public bool Enabled { get; set; } = true;
}
public sealed partial class ToggleNightvisionEvent : InstantActionEvent { }
22 changes: 22 additions & 0 deletions Content.Shared/Stories/Nightvision/SharedNightvisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Robust.Shared.Audio.Systems;
using Robust.Shared.Timing;
namespace Content.Shared.Stories.Nightvision;

public sealed class SharedNightvisionSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NightvisionComponent, ToggleNightvisionEvent>(OnToggle);
}
private void OnToggle(EntityUid uid, NightvisionComponent component, ToggleNightvisionEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
component.Enabled = !component.Enabled;
if (component.Enabled && component.ToggleOnSound != null)
_audio.PlayLocal(component.ToggleOnSound, uid, uid);
}
}
5 changes: 5 additions & 0 deletions Resources/Audio/Stories/Misc/attributions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
license: "CC-BY-4.0"
copyright: "bobik-music"
source: "https://youtu.be/rhABoExfiEM?si=8RjBhIxZ4JqxOltX"

- files: ["night_vision.ogg"]
license: "CC-BY-4.0"
copyright: "NoahBangs"
source: "https://freesound.org/people/NoahBangs/sounds/636090/"
Binary file added Resources/Audio/Stories/Misc/night_vision.ogg
Binary file not shown.
9 changes: 9 additions & 0 deletions Resources/Prototypes/Stories/Actions/nightvision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- type: entity
id: ToggleNightvisionAction
name: Ночное зрение
description: Переключить своё ночное зрение.
components:
- type: InstantAction
useDelay: 5
icon: { sprite: Stories/Clothing/Eyes/Glasses/nvg.rsi, state: icon }
event: !type:ToggleNightvisionEvent

0 comments on commit 3526564

Please sign in to comment.