light refactoring/rework (#19314)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -3,7 +3,7 @@ using Content.Client.Guidebook.Components;
|
||||
using Content.Client.Light;
|
||||
using Content.Client.Verbs;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
using Content.Shared.Light.Component;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.Light.Components;
|
||||
|
||||
namespace Content.Client.Light.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
public sealed partial class EmergencyLightComponent : SharedEmergencyLightComponent
|
||||
{
|
||||
}
|
||||
|
||||
public enum EmergencyLightVisualLayers
|
||||
{
|
||||
Base,
|
||||
LightOff,
|
||||
LightOn,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Client.Light.EntitySystems;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Client.Light.Components;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
using System;
|
||||
using Content.Client.Light.Components;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Light
|
||||
{
|
||||
public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
|
||||
{
|
||||
private const float DegreesPerSecond = 90;
|
||||
private static Animation Animation =>
|
||||
new()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(360f/ DegreesPerSecond),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(PointLightComponent),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
Property = nameof(PointLightComponent.Rotation),
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(120), 120f/DegreesPerSecond),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(240), 120f/DegreesPerSecond),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(360), 120f/DegreesPerSecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private const string AnimKey = "emergency";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ComponentStartup>(HandleStartup);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, AnimationCompletedEvent>(HandleAnimationComplete);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ComponentHandleState>(HandleCompState);
|
||||
}
|
||||
|
||||
private void HandleCompState(EntityUid uid, EmergencyLightComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not EmergencyLightComponentState state) return;
|
||||
|
||||
if (component.Enabled == state.Enabled) return;
|
||||
|
||||
var playerComponent = component.Owner.EnsureComponent<AnimationPlayerComponent>();
|
||||
|
||||
component.Enabled = state.Enabled;
|
||||
|
||||
if (component.Enabled && !playerComponent.HasRunningAnimation(AnimKey))
|
||||
playerComponent.Play(Animation, AnimKey);
|
||||
|
||||
if (!component.Enabled)
|
||||
playerComponent.Stop(AnimKey);
|
||||
}
|
||||
|
||||
private void HandleAnimationComplete(EntityUid uid, EmergencyLightComponent component, AnimationCompletedEvent args)
|
||||
{
|
||||
if (!component.Enabled ||
|
||||
!EntityManager.TryGetComponent<AnimationPlayerComponent>(uid, out var playerComponent)) return;
|
||||
|
||||
playerComponent.Play(Animation, AnimKey);
|
||||
}
|
||||
|
||||
private void HandleStartup(EntityUid uid, EmergencyLightComponent component, ComponentStartup args)
|
||||
{
|
||||
PlayAnimation(component);
|
||||
}
|
||||
|
||||
private void PlayAnimation(EmergencyLightComponent component)
|
||||
{
|
||||
if (!component.Enabled) return;
|
||||
|
||||
var playerComponent = component.Owner.EnsureComponent<AnimationPlayerComponent>();
|
||||
|
||||
if (!playerComponent.HasRunningAnimation(AnimKey))
|
||||
playerComponent.Play(Animation, AnimKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Client.Light.Components;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Light.EntitySystems;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Client.Light.Components;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Light.Visualizers;
|
||||
|
||||
89
Content.Client/Light/EntitySystems/RotatingLightSystem.cs
Normal file
89
Content.Client/Light/EntitySystems/RotatingLightSystem.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Light.Systems;
|
||||
|
||||
public sealed class RotatingLightSystem : SharedRotatingLightSystem
|
||||
{
|
||||
private Animation GetAnimation(float speed)
|
||||
{
|
||||
var third = 120f / speed;
|
||||
return new Animation()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(360f / speed),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(PointLightComponent),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
Property = nameof(PointLightComponent.Rotation),
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(120), third),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(240), third),
|
||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(360), third)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private const string AnimKey = "rotating_light";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RotatingLightComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<RotatingLightComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
|
||||
SubscribeLocalEvent<RotatingLightComponent, AnimationCompletedEvent>(OnAnimationComplete);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, RotatingLightComponent comp, ComponentStartup args)
|
||||
{
|
||||
var player = EnsureComp<AnimationPlayerComponent>(uid);
|
||||
PlayAnimation(uid, comp, player);
|
||||
}
|
||||
|
||||
private void OnAfterAutoHandleState(EntityUid uid, RotatingLightComponent comp, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
if (!TryComp<AnimationPlayerComponent>(uid, out var player))
|
||||
return;
|
||||
|
||||
if (comp.Enabled)
|
||||
{
|
||||
PlayAnimation(uid, comp, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Stop(AnimKey);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimationComplete(EntityUid uid, RotatingLightComponent comp, AnimationCompletedEvent args)
|
||||
{
|
||||
PlayAnimation(uid, comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play the light rotation animation.
|
||||
/// </summary>
|
||||
public void PlayAnimation(EntityUid uid, RotatingLightComponent? comp = null, AnimationPlayerComponent? player = null)
|
||||
{
|
||||
if (!Resolve(uid, ref comp, ref player) || !comp.Enabled)
|
||||
return;
|
||||
|
||||
if (!player.HasRunningAnimation(AnimKey))
|
||||
{
|
||||
player.Play(GetAnimation(comp.Speed), AnimKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Client.Items;
|
||||
using Content.Client.Light.Components;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Toggleable;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
@@ -4,7 +4,7 @@ using Content.Shared.Clothing;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
@@ -1,62 +1,58 @@
|
||||
using Content.Server.Light.EntitySystems;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
|
||||
namespace Content.Server.Light.Components
|
||||
namespace Content.Server.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Component that represents an emergency light, it has an internal battery that charges when the power is on.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(EmergencyLightSystem))]
|
||||
public sealed partial class EmergencyLightComponent : SharedEmergencyLightComponent
|
||||
{
|
||||
[ViewVariables]
|
||||
public EmergencyLightState State;
|
||||
|
||||
/// <summary>
|
||||
/// Component that represents an emergency light, it has an internal battery that charges when the power is on.
|
||||
/// Is this emergency light forced on for some reason and cannot be disabled through normal means
|
||||
/// (i.e. delta alert level?)
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(EmergencyLightSystem))]
|
||||
public sealed partial class EmergencyLightComponent : SharedEmergencyLightComponent
|
||||
public bool ForciblyEnabled = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("wattage")]
|
||||
public float Wattage = 5;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chargingWattage")]
|
||||
public float ChargingWattage = 60;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chargingEfficiency")]
|
||||
public float ChargingEfficiency = 0.85f;
|
||||
|
||||
public Dictionary<EmergencyLightState, string> BatteryStateText = new()
|
||||
{
|
||||
[ViewVariables]
|
||||
public EmergencyLightState State;
|
||||
{ EmergencyLightState.Full, "emergency-light-component-light-state-full" },
|
||||
{ EmergencyLightState.Empty, "emergency-light-component-light-state-empty" },
|
||||
{ EmergencyLightState.Charging, "emergency-light-component-light-state-charging" },
|
||||
{ EmergencyLightState.On, "emergency-light-component-light-state-on" }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this emergency light forced on for some reason and cannot be disabled through normal means
|
||||
/// (i.e. delta alert level?)
|
||||
/// </summary>
|
||||
public bool ForciblyEnabled = false;
|
||||
public enum EmergencyLightState : byte
|
||||
{
|
||||
Charging,
|
||||
Full,
|
||||
Empty,
|
||||
On
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("wattage")]
|
||||
public float Wattage = 5;
|
||||
public sealed class EmergencyLightEvent : EntityEventArgs
|
||||
{
|
||||
public EmergencyLightState State { get; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chargingWattage")]
|
||||
public float ChargingWattage = 60;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chargingEfficiency")]
|
||||
public float ChargingEfficiency = 0.85f;
|
||||
|
||||
public Dictionary<EmergencyLightState, string> BatteryStateText = new()
|
||||
{
|
||||
{ EmergencyLightState.Full, "emergency-light-component-light-state-full" },
|
||||
{ EmergencyLightState.Empty, "emergency-light-component-light-state-empty" },
|
||||
{ EmergencyLightState.Charging, "emergency-light-component-light-state-charging" },
|
||||
{ EmergencyLightState.On, "emergency-light-component-light-state-on" }
|
||||
};
|
||||
}
|
||||
|
||||
public enum EmergencyLightState : byte
|
||||
public EmergencyLightEvent(EmergencyLightState state)
|
||||
{
|
||||
Charging,
|
||||
Full,
|
||||
Empty,
|
||||
On
|
||||
}
|
||||
|
||||
public sealed class EmergencyLightEvent : EntityEventArgs
|
||||
{
|
||||
public EmergencyLightComponent Component { get; }
|
||||
|
||||
public EmergencyLightState State { get; }
|
||||
|
||||
public EmergencyLightEvent(EmergencyLightComponent component, EmergencyLightState state)
|
||||
{
|
||||
Component = component;
|
||||
State = state;
|
||||
}
|
||||
State = state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
|
||||
namespace Content.Server.Light.Components
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
|
||||
namespace Content.Server.Light.Components
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Light.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -2,228 +2,198 @@ using Content.Server.AlertLevel;
|
||||
using Content.Server.Audio;
|
||||
using Content.Server.Light.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using JetBrains.Annotations;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Color = Robust.Shared.Maths.Color;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems
|
||||
namespace Content.Server.Light.EntitySystems;
|
||||
|
||||
public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
|
||||
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
|
||||
[Dependency] private readonly BatterySystem _battery = default!;
|
||||
[Dependency] private readonly PointLightSystem _pointLight = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
base.Initialize();
|
||||
|
||||
public override void Initialize()
|
||||
SubscribeLocalEvent<EmergencyLightComponent, EmergencyLightEvent>(OnEmergencyLightEvent);
|
||||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ExaminedEvent>(OnEmergencyExamine);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, PowerChangedEvent>(OnEmergencyPower);
|
||||
}
|
||||
|
||||
private void OnEmergencyPower(EntityUid uid, EmergencyLightComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
var meta = MetaData(uid);
|
||||
|
||||
// TODO: PowerChangedEvent shouldn't be issued for paused ents but this is the world we live in.
|
||||
if (meta.EntityLifeStage >= EntityLifeStage.Terminating ||
|
||||
meta.EntityPaused)
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EmergencyLightComponent, EmergencyLightEvent>(OnEmergencyLightEvent);
|
||||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ComponentGetState>(GetCompState);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, PointLightToggleEvent>(HandleLightToggle);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ExaminedEvent>(OnEmergencyExamine);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, PowerChangedEvent>(OnEmergencyPower);
|
||||
return;
|
||||
}
|
||||
|
||||
private void OnEmergencyPower(EntityUid uid, EmergencyLightComponent component, ref PowerChangedEvent args)
|
||||
UpdateState(uid, component);
|
||||
}
|
||||
|
||||
private void OnEmergencyExamine(EntityUid uid, EmergencyLightComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(
|
||||
Loc.GetString("emergency-light-component-on-examine",
|
||||
("batteryStateText",
|
||||
Loc.GetString(component.BatteryStateText[component.State]))));
|
||||
|
||||
// Show alert level on the light itself.
|
||||
if (!TryComp<AlertLevelComponent>(_station.GetOwningStation(uid), out var alerts))
|
||||
return;
|
||||
|
||||
if (alerts.AlertLevels == null)
|
||||
return;
|
||||
|
||||
var name = alerts.CurrentLevel;
|
||||
|
||||
var color = Color.White;
|
||||
if (alerts.AlertLevels.Levels.TryGetValue(alerts.CurrentLevel, out var details))
|
||||
color = details.Color;
|
||||
|
||||
args.PushMarkup(
|
||||
Loc.GetString("emergency-light-component-on-examine-alert",
|
||||
("color", color.ToHex()),
|
||||
("level", name)));
|
||||
}
|
||||
|
||||
private void OnEmergencyLightEvent(EntityUid uid, EmergencyLightComponent component, EmergencyLightEvent args)
|
||||
{
|
||||
switch (args.State)
|
||||
{
|
||||
var meta = MetaData(uid);
|
||||
|
||||
// TODO: PowerChangedEvent shouldn't be issued for paused ents but this is the world we live in.
|
||||
if (meta.EntityLifeStage >= EntityLifeStage.Terminating ||
|
||||
meta.EntityPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateState(component);
|
||||
}
|
||||
|
||||
private void OnEmergencyExamine(EntityUid uid, EmergencyLightComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(
|
||||
Loc.GetString("emergency-light-component-on-examine",
|
||||
("batteryStateText",
|
||||
Loc.GetString(component.BatteryStateText[component.State]))));
|
||||
|
||||
// Show alert level on the light itself.
|
||||
if (!TryComp<AlertLevelComponent>(_station.GetOwningStation(uid), out var alerts))
|
||||
return;
|
||||
|
||||
if (alerts.AlertLevels == null)
|
||||
return;
|
||||
|
||||
var name = alerts.CurrentLevel;
|
||||
|
||||
var color = Color.White;
|
||||
if (alerts.AlertLevels.Levels.TryGetValue(alerts.CurrentLevel, out var details))
|
||||
color = details.Color;
|
||||
|
||||
args.PushMarkup(
|
||||
Loc.GetString("emergency-light-component-on-examine-alert",
|
||||
("color", color.ToHex()),
|
||||
("level", name)));
|
||||
}
|
||||
|
||||
private void HandleLightToggle(EntityUid uid, EmergencyLightComponent component, PointLightToggleEvent args)
|
||||
{
|
||||
if (component.Enabled == args.Enabled)
|
||||
return;
|
||||
|
||||
component.Enabled = args.Enabled;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private void GetCompState(EntityUid uid, EmergencyLightComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new EmergencyLightComponentState(component.Enabled);
|
||||
}
|
||||
|
||||
private void OnEmergencyLightEvent(EntityUid uid, EmergencyLightComponent component, EmergencyLightEvent args)
|
||||
{
|
||||
switch (args.State)
|
||||
{
|
||||
case EmergencyLightState.On:
|
||||
case EmergencyLightState.Charging:
|
||||
EnsureComp<ActiveEmergencyLightComponent>(uid);
|
||||
break;
|
||||
case EmergencyLightState.Full:
|
||||
case EmergencyLightState.Empty:
|
||||
RemComp<ActiveEmergencyLightComponent>(uid);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
|
||||
{
|
||||
if (!TryComp<AlertLevelComponent>(ev.Station, out var alert))
|
||||
return;
|
||||
|
||||
if (alert.AlertLevels == null || !alert.AlertLevels.Levels.TryGetValue(ev.AlertLevel, out var details))
|
||||
return;
|
||||
|
||||
foreach (var (light, pointLight, appearance, xform) in EntityQuery<EmergencyLightComponent, PointLightComponent, AppearanceComponent, TransformComponent>())
|
||||
{
|
||||
if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != ev.Station)
|
||||
continue;
|
||||
|
||||
pointLight.Color = details.EmergencyLightColor;
|
||||
_appearance.SetData(appearance.Owner, EmergencyLightVisuals.Color, details.EmergencyLightColor, appearance);
|
||||
|
||||
if (details.ForceEnableEmergencyLights && !light.ForciblyEnabled)
|
||||
{
|
||||
light.ForciblyEnabled = true;
|
||||
TurnOn(light);
|
||||
}
|
||||
else if (!details.ForceEnableEmergencyLights && light.ForciblyEnabled)
|
||||
{
|
||||
// Previously forcibly enabled, and we went down an alert level.
|
||||
light.ForciblyEnabled = false;
|
||||
UpdateState(light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(EmergencyLightComponent component, EmergencyLightState state)
|
||||
{
|
||||
if (component.State == state) return;
|
||||
|
||||
component.State = state;
|
||||
RaiseLocalEvent(component.Owner, new EmergencyLightEvent(component, state));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var (_, activeLight, battery) in EntityQuery<ActiveEmergencyLightComponent, EmergencyLightComponent, BatteryComponent>())
|
||||
{
|
||||
Update(activeLight, battery, frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(EmergencyLightComponent component, BatteryComponent battery, float frameTime)
|
||||
{
|
||||
if (component.State == EmergencyLightState.On)
|
||||
{
|
||||
if (!battery.TryUseCharge(component.Wattage * frameTime))
|
||||
{
|
||||
SetState(component, EmergencyLightState.Empty);
|
||||
TurnOff(component);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
battery.CurrentCharge += component.ChargingWattage * frameTime * component.ChargingEfficiency;
|
||||
if (battery.IsFullyCharged)
|
||||
{
|
||||
if (TryComp(component.Owner, out ApcPowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.Load = 1;
|
||||
}
|
||||
|
||||
SetState(component, EmergencyLightState.Full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the light's power drain, battery drain, sprite and actual light state.
|
||||
/// </summary>
|
||||
public void UpdateState(EmergencyLightComponent component)
|
||||
{
|
||||
if (!TryComp(component.Owner, out ApcPowerReceiverComponent? receiver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (receiver.Powered && !component.ForciblyEnabled)
|
||||
{
|
||||
receiver.Load = (int) Math.Abs(component.Wattage);
|
||||
TurnOff(component);
|
||||
SetState(component, EmergencyLightState.Charging);
|
||||
}
|
||||
else
|
||||
{
|
||||
TurnOn(component);
|
||||
SetState(component, EmergencyLightState.On);
|
||||
}
|
||||
}
|
||||
|
||||
private void TurnOff(EmergencyLightComponent component)
|
||||
{
|
||||
if (TryComp(component.Owner, out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = false;
|
||||
}
|
||||
|
||||
if (TryComp(component.Owner, out AppearanceComponent? appearance))
|
||||
_appearance.SetData(appearance.Owner, EmergencyLightVisuals.On, false, appearance);
|
||||
|
||||
_ambient.SetAmbience(component.Owner, false);
|
||||
}
|
||||
|
||||
private void TurnOn(EmergencyLightComponent component)
|
||||
{
|
||||
if (TryComp(component.Owner, out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = true;
|
||||
}
|
||||
|
||||
if (TryComp(component.Owner, out AppearanceComponent? appearance))
|
||||
{
|
||||
_appearance.SetData(appearance.Owner, EmergencyLightVisuals.On, true, appearance);
|
||||
}
|
||||
|
||||
_ambient.SetAmbience(component.Owner, true);
|
||||
case EmergencyLightState.On:
|
||||
case EmergencyLightState.Charging:
|
||||
EnsureComp<ActiveEmergencyLightComponent>(uid);
|
||||
break;
|
||||
case EmergencyLightState.Full:
|
||||
case EmergencyLightState.Empty:
|
||||
RemComp<ActiveEmergencyLightComponent>(uid);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
|
||||
{
|
||||
if (!TryComp<AlertLevelComponent>(ev.Station, out var alert))
|
||||
return;
|
||||
|
||||
if (alert.AlertLevels == null || !alert.AlertLevels.Levels.TryGetValue(ev.AlertLevel, out var details))
|
||||
return;
|
||||
|
||||
var query = EntityQueryEnumerator<EmergencyLightComponent, PointLightComponent, AppearanceComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out var light, out var pointLight, out var appearance, out var xform))
|
||||
{
|
||||
if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != ev.Station)
|
||||
continue;
|
||||
|
||||
pointLight.Color = details.EmergencyLightColor;
|
||||
_appearance.SetData(uid, EmergencyLightVisuals.Color, details.EmergencyLightColor, appearance);
|
||||
|
||||
if (details.ForceEnableEmergencyLights && !light.ForciblyEnabled)
|
||||
{
|
||||
light.ForciblyEnabled = true;
|
||||
TurnOn(uid, light);
|
||||
}
|
||||
else if (!details.ForceEnableEmergencyLights && light.ForciblyEnabled)
|
||||
{
|
||||
// Previously forcibly enabled, and we went down an alert level.
|
||||
light.ForciblyEnabled = false;
|
||||
UpdateState(uid, light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(EntityUid uid, EmergencyLightComponent component, EmergencyLightState state)
|
||||
{
|
||||
if (component.State == state) return;
|
||||
|
||||
component.State = state;
|
||||
RaiseLocalEvent(uid, new EmergencyLightEvent(state));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ActiveEmergencyLightComponent, EmergencyLightComponent, BatteryComponent>();
|
||||
while (query.MoveNext(out var uid, out _, out var emergencyLight, out var battery))
|
||||
{
|
||||
Update(uid, emergencyLight, battery, frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(EntityUid uid, EmergencyLightComponent component, BatteryComponent battery, float frameTime)
|
||||
{
|
||||
if (component.State == EmergencyLightState.On)
|
||||
{
|
||||
if (!_battery.TryUseCharge(uid, component.Wattage * frameTime, battery))
|
||||
{
|
||||
SetState(uid, component, EmergencyLightState.Empty);
|
||||
TurnOff(uid, component);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
battery.CurrentCharge += component.ChargingWattage * frameTime * component.ChargingEfficiency;
|
||||
if (battery.IsFullyCharged)
|
||||
{
|
||||
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
|
||||
{
|
||||
receiver.Load = 1;
|
||||
}
|
||||
|
||||
SetState(uid, component, EmergencyLightState.Full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the light's power drain, battery drain, sprite and actual light state.
|
||||
/// </summary>
|
||||
public void UpdateState(EntityUid uid, EmergencyLightComponent component)
|
||||
{
|
||||
if (!TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
|
||||
return;
|
||||
|
||||
if (receiver.Powered && !component.ForciblyEnabled)
|
||||
{
|
||||
receiver.Load = (int) Math.Abs(component.Wattage);
|
||||
TurnOff(uid, component);
|
||||
SetState(uid, component, EmergencyLightState.Charging);
|
||||
}
|
||||
else
|
||||
{
|
||||
TurnOn(uid, component);
|
||||
SetState(uid, component, EmergencyLightState.On);
|
||||
}
|
||||
}
|
||||
|
||||
private void TurnOff(EntityUid uid, EmergencyLightComponent component)
|
||||
{
|
||||
_pointLight.SetEnabled(uid, false);
|
||||
_appearance.SetData(uid, EmergencyLightVisuals.On, false);
|
||||
_ambient.SetAmbience(uid, false);
|
||||
}
|
||||
|
||||
private void TurnOn(EntityUid uid, EmergencyLightComponent component)
|
||||
{
|
||||
_pointLight.SetEnabled(uid, true);
|
||||
_appearance.SetData(uid, EmergencyLightVisuals.On, true);
|
||||
_ambient.SetAmbience(uid, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.Light.Components;
|
||||
using Content.Shared.Destructible;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
@@ -3,7 +3,7 @@ using Content.Server.Light.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
@@ -11,7 +11,7 @@ using Content.Shared.Database;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
24
Content.Server/Light/EntitySystems/RotatingLightSystem.cs
Normal file
24
Content.Server/Light/EntitySystems/RotatingLightSystem.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems;
|
||||
|
||||
public sealed class RotatingLightSystem : SharedRotatingLightSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RotatingLightComponent, PointLightToggleEvent>(OnLightToggle);
|
||||
}
|
||||
|
||||
private void OnLightToggle(EntityUid uid, RotatingLightComponent comp, PointLightToggleEvent args)
|
||||
{
|
||||
if (comp.Enabled == args.Enabled)
|
||||
return;
|
||||
|
||||
comp.Enabled = args.Enabled;
|
||||
Dirty(comp);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Content.Shared.Actions;
|
||||
using Content.Shared.Decals;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
@@ -12,7 +12,7 @@ using Content.Server.Station.Systems;
|
||||
using Content.Server.Store.Components;
|
||||
using Content.Server.Store.Systems;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.PDA;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
|
||||
@@ -4,7 +4,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Tools.Components;
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Light
|
||||
{
|
||||
[NetworkedComponent]
|
||||
[RegisterComponent]
|
||||
[Access(typeof(SharedHandheldLightSystem))]
|
||||
public sealed partial class HandheldLightComponent : Robust.Shared.GameObjects.Component
|
||||
{
|
||||
public byte? Level;
|
||||
public bool Activated;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("wattage")]
|
||||
public float Wattage { get; set; } = .8f;
|
||||
|
||||
[DataField("turnOnSound")]
|
||||
public SoundSpecifier TurnOnSound = new SoundPathSpecifier("/Audio/Items/flashlight_on.ogg");
|
||||
|
||||
[DataField("turnOnFailSound")]
|
||||
public SoundSpecifier TurnOnFailSound = new SoundPathSpecifier("/Audio/Machines/button.ogg");
|
||||
|
||||
[DataField("turnOffSound")]
|
||||
public SoundSpecifier TurnOffSound = new SoundPathSpecifier("/Audio/Items/flashlight_off.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Whether to automatically set item-prefixes when toggling the flashlight.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Flashlights should probably be using explicit unshaded sprite, in-hand and clothing layers, this is
|
||||
/// mostly here for backwards compatibility.
|
||||
/// </remarks>
|
||||
[DataField("addPrefix")]
|
||||
public bool AddPrefix = false;
|
||||
|
||||
[DataField("toggleActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public string ToggleActionId = "ToggleLight";
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the light can be toggled via standard interactions
|
||||
/// (alt verbs, using in hand, etc)
|
||||
/// </summary>
|
||||
[DataField("toggleOnInteract")]
|
||||
public bool ToggleOnInteract = true;
|
||||
|
||||
[DataField("toggleAction")]
|
||||
public InstantAction? ToggleAction;
|
||||
|
||||
public const int StatusLevels = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Specify the ID of the light behaviour to use when the state of the light is Dying
|
||||
/// </summary>
|
||||
[DataField("blinkingBehaviourId")]
|
||||
public string BlinkingBehaviourId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Specify the ID of the light behaviour to use when the state of the light is LowPower
|
||||
/// </summary>
|
||||
[DataField("radiatingBehaviourId")]
|
||||
public string RadiatingBehaviourId { get; set; } = string.Empty;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class HandheldLightComponentState : ComponentState
|
||||
{
|
||||
public byte? Charge { get; }
|
||||
|
||||
public bool Activated { get; }
|
||||
|
||||
public HandheldLightComponentState(bool activated, byte? charge)
|
||||
{
|
||||
Activated = activated;
|
||||
Charge = charge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandheldLightVisuals
|
||||
{
|
||||
Power
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandheldLightPowerStates
|
||||
{
|
||||
FullPower,
|
||||
LowPower,
|
||||
Dying,
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Component
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract partial class SharedEmergencyLightComponent : Robust.Shared.GameObjects.Component
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class EmergencyLightComponentState : ComponentState
|
||||
{
|
||||
public bool Enabled;
|
||||
|
||||
public EmergencyLightComponentState(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum EmergencyLightVisuals
|
||||
{
|
||||
On,
|
||||
Color
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Component
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum ExpendableLightVisuals
|
||||
{
|
||||
State,
|
||||
Behavior
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum ExpendableLightState
|
||||
{
|
||||
BrandNew,
|
||||
Lit,
|
||||
Fading,
|
||||
Dead
|
||||
}
|
||||
|
||||
[NetworkedComponent]
|
||||
public abstract partial class SharedExpendableLightComponent: Robust.Shared.GameObjects.Component
|
||||
{
|
||||
public static readonly AudioParams LoopedSoundParams = new(0, 1, "Master", 62.5f, 1, 1, true, 0.3f);
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public ExpendableLightState CurrentState { get; set; }
|
||||
|
||||
[DataField("turnOnBehaviourID")]
|
||||
public string TurnOnBehaviourID { get; set; } = string.Empty;
|
||||
|
||||
[DataField("fadeOutBehaviourID")]
|
||||
public string FadeOutBehaviourID { get; set; } = string.Empty;
|
||||
|
||||
[DataField("glowDuration")]
|
||||
public float GlowDuration { get; set; } = 60 * 15f;
|
||||
|
||||
[DataField("fadeOutDuration")]
|
||||
public float FadeOutDuration { get; set; } = 60 * 5f;
|
||||
|
||||
[DataField("spentDesc")]
|
||||
public string SpentDesc { get; set; } = string.Empty;
|
||||
|
||||
[DataField("spentName")]
|
||||
public string SpentName { get; set; } = string.Empty;
|
||||
|
||||
[DataField("litSound")]
|
||||
public SoundSpecifier? LitSound { get; set; }
|
||||
|
||||
[DataField("loopedSound")]
|
||||
public SoundSpecifier? LoopedSound { get; set; }
|
||||
|
||||
[DataField("dieSound")]
|
||||
public SoundSpecifier? DieSound { get; set; } = null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Content.Shared.Light.Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A component which applies a specific behaviour to a PointLightComponent on its owner.
|
||||
/// </summary>
|
||||
public abstract partial class SharedLightBehaviourComponent : Robust.Shared.GameObjects.Component
|
||||
{
|
||||
}
|
||||
}
|
||||
92
Content.Shared/Light/Components/HandheldLightComponent.cs
Normal file
92
Content.Shared/Light/Components/HandheldLightComponent.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(SharedHandheldLightSystem))]
|
||||
public sealed partial class HandheldLightComponent : Component
|
||||
{
|
||||
public byte? Level;
|
||||
public bool Activated;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("wattage")]
|
||||
public float Wattage { get; set; } = .8f;
|
||||
|
||||
[DataField("turnOnSound")]
|
||||
public SoundSpecifier TurnOnSound = new SoundPathSpecifier("/Audio/Items/flashlight_on.ogg");
|
||||
|
||||
[DataField("turnOnFailSound")]
|
||||
public SoundSpecifier TurnOnFailSound = new SoundPathSpecifier("/Audio/Machines/button.ogg");
|
||||
|
||||
[DataField("turnOffSound")]
|
||||
public SoundSpecifier TurnOffSound = new SoundPathSpecifier("/Audio/Items/flashlight_off.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Whether to automatically set item-prefixes when toggling the flashlight.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Flashlights should probably be using explicit unshaded sprite, in-hand and clothing layers, this is
|
||||
/// mostly here for backwards compatibility.
|
||||
/// </remarks>
|
||||
[DataField("addPrefix")]
|
||||
public bool AddPrefix = false;
|
||||
|
||||
[DataField("toggleActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public string ToggleActionId = "ToggleLight";
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the light can be toggled via standard interactions
|
||||
/// (alt verbs, using in hand, etc)
|
||||
/// </summary>
|
||||
[DataField("toggleOnInteract")]
|
||||
public bool ToggleOnInteract = true;
|
||||
|
||||
[DataField("toggleAction")]
|
||||
public InstantAction? ToggleAction;
|
||||
|
||||
public const int StatusLevels = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Specify the ID of the light behaviour to use when the state of the light is Dying
|
||||
/// </summary>
|
||||
[DataField("blinkingBehaviourId")]
|
||||
public string BlinkingBehaviourId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Specify the ID of the light behaviour to use when the state of the light is LowPower
|
||||
/// </summary>
|
||||
[DataField("radiatingBehaviourId")]
|
||||
public string RadiatingBehaviourId { get; set; } = string.Empty;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class HandheldLightComponentState : ComponentState
|
||||
{
|
||||
public byte? Charge { get; }
|
||||
|
||||
public bool Activated { get; }
|
||||
|
||||
public HandheldLightComponentState(bool activated, byte? charge)
|
||||
{
|
||||
Activated = activated;
|
||||
Charge = charge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandheldLightVisuals
|
||||
{
|
||||
Power
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandheldLightPowerStates
|
||||
{
|
||||
FullPower,
|
||||
LowPower,
|
||||
Dying,
|
||||
}
|
||||
@@ -2,15 +2,14 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Component;
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
|
||||
/// TODO: Breaking and burning should probably be moved to another component eventually.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
public sealed partial class LightBulbComponent : Robust.Shared.GameObjects.Component
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class LightBulbComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The color of the lightbulb and the light it produces.
|
||||
@@ -1,7 +1,7 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Component;
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Makes the color of lights on an entity fluctuate. Will update point-light color and modulate some or all of the
|
||||
@@ -10,10 +10,8 @@ namespace Content.Shared.Light.Component;
|
||||
/// <remarks>
|
||||
/// Networked ~~solely for admemes~~ for completely legitimate reasons, like hacked energy swords.
|
||||
/// </remarks>
|
||||
[NetworkedComponent]
|
||||
[RegisterComponent]
|
||||
[Access(typeof(SharedRgbLightControllerSystem))]
|
||||
public sealed partial class RgbLightControllerComponent : Robust.Shared.GameObjects.Component
|
||||
[NetworkedComponent, RegisterComponent, Access(typeof(SharedRgbLightControllerSystem))]
|
||||
public sealed partial class RgbLightControllerComponent : Component
|
||||
{
|
||||
[DataField("cycleRate")]
|
||||
public float CycleRate { get; set; } = 0.1f;
|
||||
21
Content.Shared/Light/Components/RotatingLightComponent.cs
Normal file
21
Content.Shared/Light/Components/RotatingLightComponent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Animates a point light's rotation while enabled.
|
||||
/// All animation is done in the client system.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
[Access(typeof(SharedRotatingLightSystem))]
|
||||
public sealed partial class RotatingLightComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Speed to rotate at, in degrees per second
|
||||
/// </summary>
|
||||
[DataField("speed")]
|
||||
public float Speed = 90f;
|
||||
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public bool Enabled = true;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Handles station alert level and power changes for emergency lights.
|
||||
/// All logic is serverside, animation is handled by <see cref="RotatingLightComponent"/>.
|
||||
/// </summary>
|
||||
[Access(typeof(SharedEmergencyLightSystem))]
|
||||
public abstract partial class SharedEmergencyLightComponent : Component
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum EmergencyLightVisuals
|
||||
{
|
||||
On,
|
||||
Color
|
||||
}
|
||||
|
||||
public enum EmergencyLightVisualLayers
|
||||
{
|
||||
Base,
|
||||
LightOff,
|
||||
LightOn,
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
public abstract partial class SharedExpendableLightComponent : Component
|
||||
{
|
||||
public static readonly AudioParams LoopedSoundParams = new(0, 1, "Master", 62.5f, 1, 1, true, 0.3f);
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public ExpendableLightState CurrentState { get; set; }
|
||||
|
||||
[DataField("turnOnBehaviourID")]
|
||||
public string TurnOnBehaviourID { get; set; } = string.Empty;
|
||||
|
||||
[DataField("fadeOutBehaviourID")]
|
||||
public string FadeOutBehaviourID { get; set; } = string.Empty;
|
||||
|
||||
[DataField("glowDuration")]
|
||||
public float GlowDuration { get; set; } = 60 * 15f;
|
||||
|
||||
[DataField("fadeOutDuration")]
|
||||
public float FadeOutDuration { get; set; } = 60 * 5f;
|
||||
|
||||
[DataField("spentDesc")]
|
||||
public string SpentDesc { get; set; } = string.Empty;
|
||||
|
||||
[DataField("spentName")]
|
||||
public string SpentName { get; set; } = string.Empty;
|
||||
|
||||
[DataField("litSound")]
|
||||
public SoundSpecifier? LitSound { get; set; }
|
||||
|
||||
[DataField("loopedSound")]
|
||||
public SoundSpecifier? LoopedSound { get; set; }
|
||||
|
||||
[DataField("dieSound")]
|
||||
public SoundSpecifier? DieSound { get; set; } = null;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum ExpendableLightVisuals
|
||||
{
|
||||
State,
|
||||
Behavior
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum ExpendableLightState
|
||||
{
|
||||
BrandNew,
|
||||
Lit,
|
||||
Fading,
|
||||
Dead
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// A component which applies a specific behaviour to a PointLightComponent on its owner.
|
||||
/// </summary>
|
||||
public abstract partial class SharedLightBehaviourComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -2,14 +2,14 @@ using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Decals;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Shared.Light.Component;
|
||||
namespace Content.Shared.Light.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is simplified version of <see cref="HandheldLightComponent"/>.
|
||||
/// It doesn't consume any power and can be toggle only by verb.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class UnpoweredFlashlightComponent : Robust.Shared.GameObjects.Component
|
||||
public sealed partial class UnpoweredFlashlightComponent : Component
|
||||
{
|
||||
[DataField("toggleFlashlightSound")]
|
||||
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Items/flashlight_pda.ogg");
|
||||
@@ -1,7 +1,5 @@
|
||||
namespace Content.Shared.Light
|
||||
{
|
||||
public abstract class SharedEmergencyLightSystem : EntitySystem
|
||||
{
|
||||
namespace Content.Shared.Light;
|
||||
|
||||
}
|
||||
public abstract class SharedEmergencyLightSystem : EntitySystem
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Toggleable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Light;
|
||||
|
||||
5
Content.Shared/Light/SharedRotatingLightSystem.cs
Normal file
5
Content.Shared/Light/SharedRotatingLightSystem.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Content.Shared.Light;
|
||||
|
||||
public abstract class SharedRotatingLightSystem : EntitySystem
|
||||
{
|
||||
}
|
||||
@@ -13,7 +13,7 @@ using Content.Shared.Tag;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Buckle;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
|
||||
@@ -314,6 +314,7 @@
|
||||
maxCharge: 30000
|
||||
startingCharge: 0
|
||||
- type: EmergencyLight
|
||||
- type: RotatingLight
|
||||
- type: Sprite
|
||||
sprite: Structures/Wallmounts/Lighting/emergency_light.rsi
|
||||
layers:
|
||||
|
||||
Reference in New Issue
Block a user