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

Night vision toggling #151

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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);
}
}
13 changes: 12 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,15 @@ 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;
[ViewVariables(VVAccess.ReadWrite), DataField("playSound"), AutoNetworkedField]
public bool PlaySound { get; set; } = true; // For dragon
[DataField("toggleOnSound")]
public SoundSpecifier ToggleOnSound = new SoundPathSpecifier("/Audio/Stories/Misc/night_vision.ogg");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[ViewVariables(VVAccess.ReadWrite), DataField("playSound"), AutoNetworkedField]
public bool PlaySound { get; set; } = true; // For dragon
[DataField("toggleOnSound")]
public SoundSpecifier ToggleOnSound = new SoundPathSpecifier("/Audio/Stories/Misc/night_vision.ogg");
[DataField("toggleOnSound")]
public SoundSpecifier? ToggleOnSound = new SoundPathSpecifier("/Audio/Stories/Misc/night_vision.ogg");

И проверку на null в коде, вместо еще одной переменной.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот так?

}

[RegisterComponent]
Expand All @@ -18,3 +28,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.PlaySound)
_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
Loading