Merge remote-tracking branch 'upstream/master' into UPS
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using Content.Shared._White.Overlays;
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._Miracle.Systems;
|
||||
|
||||
public abstract class SharedEnhancedVisionSystem<TComp, TTempComp, TEvent> : EntitySystem
|
||||
where TComp : BaseEnhancedVisionComponent
|
||||
where TEvent : InstantActionEvent
|
||||
where TTempComp : Component
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TComp, TEvent>(OnToggle);
|
||||
SubscribeLocalEvent<TComp, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<TComp, ComponentRemove>(OnRemove);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, TComp component, ComponentRemove args)
|
||||
{
|
||||
_actions.RemoveAction(uid, component.ToggleActionEntity);
|
||||
|
||||
if (HasComp<TTempComp>(uid))
|
||||
return;
|
||||
|
||||
UpdateEnhancedVision(uid, false);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, TComp component, ComponentInit args)
|
||||
{
|
||||
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||
|
||||
if (!component.IsActive && HasComp<TTempComp>(uid))
|
||||
return;
|
||||
|
||||
UpdateEnhancedVision(uid, component.IsActive);
|
||||
}
|
||||
|
||||
protected virtual void UpdateEnhancedVision(EntityUid uid, bool active) { }
|
||||
|
||||
private void OnToggle(EntityUid uid, TComp component, TEvent args)
|
||||
{
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
component.IsActive = !component.IsActive;
|
||||
|
||||
_audio.PlayPredicted(component.IsActive ? component.ActivateSound : component.DeactivateSound, uid, uid);
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (!component.IsActive && HasComp<TTempComp>(uid))
|
||||
return;
|
||||
|
||||
UpdateEnhancedVision(uid, component.IsActive);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using Content.Shared._White.Overlays;
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._Miracle.Systems;
|
||||
|
||||
public abstract class SharedNightVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<NightVisionComponent, ToggleNightVisionEvent>(OnToggle);
|
||||
SubscribeLocalEvent<NightVisionComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<NightVisionComponent, ComponentRemove>(OnRemove);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, NightVisionComponent component, ComponentRemove args)
|
||||
{
|
||||
_actions.RemoveAction(uid, component.ToggleActionEntity);
|
||||
|
||||
if (HasComp<TemporaryNightVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateNightVision(uid, false);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, NightVisionComponent component, ComponentInit args)
|
||||
{
|
||||
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||
|
||||
if (!component.IsActive && HasComp<TemporaryNightVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateNightVision(uid, component.IsActive);
|
||||
}
|
||||
|
||||
protected virtual void UpdateNightVision(EntityUid uid, bool active) { }
|
||||
|
||||
private void OnToggle(EntityUid uid, NightVisionComponent component, ToggleNightVisionEvent args)
|
||||
{
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
component.IsActive = !component.IsActive;
|
||||
|
||||
if (component.IsActive && component.ActivateSound != null)
|
||||
_audio.PlayPredicted(component.ActivateSound, uid, uid);
|
||||
else if (component.DeactivateSound != null)
|
||||
_audio.PlayPredicted(component.DeactivateSound, uid, uid);
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (!component.IsActive && HasComp<TemporaryNightVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateNightVision(uid, component.IsActive);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using Content.Shared._White.Overlays;
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._Miracle.Systems;
|
||||
|
||||
public abstract class SharedThermalVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ThermalVisionComponent, ToggleThermalVisionEvent>(OnToggle);
|
||||
SubscribeLocalEvent<ThermalVisionComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<ThermalVisionComponent, ComponentRemove>(OnRemove);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, ThermalVisionComponent component, ComponentRemove args)
|
||||
{
|
||||
_actions.RemoveAction(uid, component.ToggleActionEntity);
|
||||
|
||||
if (HasComp<TemporaryThermalVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateThermalVision(uid, false);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, ThermalVisionComponent component, ComponentInit args)
|
||||
{
|
||||
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||
|
||||
if (!component.IsActive && HasComp<TemporaryThermalVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateThermalVision(uid, component.IsActive);
|
||||
}
|
||||
|
||||
protected virtual void UpdateThermalVision(EntityUid uid, bool active) { }
|
||||
|
||||
private void OnToggle(EntityUid uid, ThermalVisionComponent component, ToggleThermalVisionEvent args)
|
||||
{
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
component.IsActive = !component.IsActive;
|
||||
|
||||
if (component.IsActive && component.ActivateSound != null)
|
||||
_audio.PlayPredicted(component.ActivateSound, uid, uid);
|
||||
else if (component.DeactivateSound != null)
|
||||
_audio.PlayPredicted(component.DeactivateSound, uid, uid);
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (!component.IsActive && HasComp<TemporaryThermalVisionComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateThermalVision(uid, component.IsActive);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._White.Overlays;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public abstract partial class BaseEnhancedVisionComponent : BaseNvOverlayComponent
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool IsActive = true;
|
||||
|
||||
[DataField]
|
||||
public virtual SoundSpecifier? ActivateSound { get; set; }= new SoundPathSpecifier("/Audio/White/Items/Goggles/activate.ogg");
|
||||
|
||||
[DataField]
|
||||
public virtual SoundSpecifier? DeactivateSound { get; set; } = new SoundPathSpecifier("/Audio/White/Items/Goggles/deactivate.ogg");
|
||||
|
||||
[DataField]
|
||||
public virtual EntProtoId? ToggleAction { get; set; }
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? ToggleActionEntity;
|
||||
}
|
||||
@@ -6,25 +6,13 @@ using Robust.Shared.Prototypes;
|
||||
namespace Content.Shared._White.Overlays;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class NightVisionComponent : BaseNvOverlayComponent
|
||||
public sealed partial class NightVisionComponent : BaseEnhancedVisionComponent
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public override Color Color { get; set; } = Color.FromHex("#98FB98");
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool IsActive = true;
|
||||
|
||||
[DataField]
|
||||
public SoundSpecifier? ActivateSound = new SoundPathSpecifier("/Audio/White/Items/Goggles/activate.ogg");
|
||||
|
||||
[DataField]
|
||||
public SoundSpecifier? DeactivateSound = new SoundPathSpecifier("/Audio/White/Items/Goggles/deactivate.ogg");
|
||||
|
||||
[DataField]
|
||||
public EntProtoId? ToggleAction = "ToggleNightVision";
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? ToggleActionEntity;
|
||||
public override EntProtoId? ToggleAction { get; set; } = "ToggleNightVision";
|
||||
}
|
||||
|
||||
public sealed partial class ToggleNightVisionEvent : InstantActionEvent
|
||||
|
||||
@@ -6,25 +6,13 @@ using Robust.Shared.Prototypes;
|
||||
namespace Content.Shared._White.Overlays;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ThermalVisionComponent : BaseNvOverlayComponent
|
||||
public sealed partial class ThermalVisionComponent : BaseEnhancedVisionComponent
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public override Color Color { get; set; } = Color.FromHex("#F84742");
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool IsActive = true;
|
||||
|
||||
[DataField]
|
||||
public SoundSpecifier? ActivateSound = new SoundPathSpecifier("/Audio/White/Items/Goggles/activate.ogg");
|
||||
|
||||
[DataField]
|
||||
public SoundSpecifier? DeactivateSound = new SoundPathSpecifier("/Audio/White/Items/Goggles/deactivate.ogg");
|
||||
|
||||
[DataField]
|
||||
public EntProtoId? ToggleAction = "ToggleThermalVision";
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? ToggleActionEntity;
|
||||
public override EntProtoId? ToggleAction { get; set; } = "ToggleThermalVision";
|
||||
}
|
||||
|
||||
public sealed partial class ToggleThermalVisionEvent : InstantActionEvent
|
||||
|
||||
Reference in New Issue
Block a user