light refactoring/rework (#19314)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-09-04 06:31:10 +01:00
committed by GitHub
parent 4e51fd4fff
commit 91cfabd6f6
44 changed files with 581 additions and 584 deletions

View File

@@ -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;

View File

@@ -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,
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Light.Component;
using Content.Shared.Light.Components;
using Robust.Client.GameObjects;
namespace Content.Client.Light.Visualizers;

View 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);
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,8 +1,8 @@
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>
@@ -49,14 +49,10 @@ namespace Content.Server.Light.Components
public sealed class EmergencyLightEvent : EntityEventArgs
{
public EmergencyLightComponent Component { get; }
public EmergencyLightState State { get; }
public EmergencyLightEvent(EmergencyLightComponent component, EmergencyLightState state)
public EmergencyLightEvent(EmergencyLightState state)
{
Component = component;
State = state;
}
}
}

View File

@@ -1,4 +1,4 @@
using Content.Shared.Light.Component;
using Content.Shared.Light.Components;
namespace Content.Server.Light.Components
{

View File

@@ -1,4 +1,4 @@
using Content.Shared.Light.Component;
using Content.Shared.Light.Components;
namespace Content.Server.Light.Components
{

View File

@@ -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;

View File

@@ -2,32 +2,32 @@ 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
{
[UsedImplicitly]
namespace Content.Server.Light.EntitySystems;
public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
{
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
[Dependency] private readonly StationSystem _station = 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()
{
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);
}
@@ -43,7 +43,7 @@ namespace Content.Server.Light.EntitySystems
return;
}
UpdateState(component);
UpdateState(uid, component);
}
private void OnEmergencyExamine(EntityUid uid, EmergencyLightComponent component, ExaminedEvent args)
@@ -72,20 +72,6 @@ namespace Content.Server.Light.EntitySystems
("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)
@@ -111,52 +97,54 @@ namespace Content.Server.Light.EntitySystems
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>())
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(appearance.Owner, EmergencyLightVisuals.Color, details.EmergencyLightColor, appearance);
_appearance.SetData(uid, EmergencyLightVisuals.Color, details.EmergencyLightColor, appearance);
if (details.ForceEnableEmergencyLights && !light.ForciblyEnabled)
{
light.ForciblyEnabled = true;
TurnOn(light);
TurnOn(uid, light);
}
else if (!details.ForceEnableEmergencyLights && light.ForciblyEnabled)
{
// Previously forcibly enabled, and we went down an alert level.
light.ForciblyEnabled = false;
UpdateState(light);
UpdateState(uid, light);
}
}
}
public void SetState(EmergencyLightComponent component, EmergencyLightState state)
public void SetState(EntityUid uid, EmergencyLightComponent component, EmergencyLightState state)
{
if (component.State == state) return;
component.State = state;
RaiseLocalEvent(component.Owner, new EmergencyLightEvent(component, state));
RaiseLocalEvent(uid, new EmergencyLightEvent(state));
}
public override void Update(float frameTime)
{
foreach (var (_, activeLight, battery) in EntityQuery<ActiveEmergencyLightComponent, EmergencyLightComponent, BatteryComponent>())
var query = EntityQueryEnumerator<ActiveEmergencyLightComponent, EmergencyLightComponent, BatteryComponent>();
while (query.MoveNext(out var uid, out _, out var emergencyLight, out var battery))
{
Update(activeLight, battery, frameTime);
Update(uid, emergencyLight, battery, frameTime);
}
}
private void Update(EmergencyLightComponent component, BatteryComponent battery, float frameTime)
private void Update(EntityUid uid, EmergencyLightComponent component, BatteryComponent battery, float frameTime)
{
if (component.State == EmergencyLightState.On)
{
if (!battery.TryUseCharge(component.Wattage * frameTime))
if (!_battery.TryUseCharge(uid, component.Wattage * frameTime, battery))
{
SetState(component, EmergencyLightState.Empty);
TurnOff(component);
SetState(uid, component, EmergencyLightState.Empty);
TurnOff(uid, component);
}
}
else
@@ -164,12 +152,12 @@ namespace Content.Server.Light.EntitySystems
battery.CurrentCharge += component.ChargingWattage * frameTime * component.ChargingEfficiency;
if (battery.IsFullyCharged)
{
if (TryComp(component.Owner, out ApcPowerReceiverComponent? receiver))
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
{
receiver.Load = 1;
}
SetState(component, EmergencyLightState.Full);
SetState(uid, component, EmergencyLightState.Full);
}
}
}
@@ -177,53 +165,35 @@ namespace Content.Server.Light.EntitySystems
/// <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))
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(component);
SetState(component, EmergencyLightState.Charging);
TurnOff(uid, component);
SetState(uid, component, EmergencyLightState.Charging);
}
else
{
TurnOn(component);
SetState(component, EmergencyLightState.On);
TurnOn(uid, component);
SetState(uid, component, EmergencyLightState.On);
}
}
private void TurnOff(EmergencyLightComponent component)
private void TurnOff(EntityUid uid, EmergencyLightComponent component)
{
if (TryComp(component.Owner, out PointLightComponent? light))
_pointLight.SetEnabled(uid, false);
_appearance.SetData(uid, EmergencyLightVisuals.On, false);
_ambient.SetAmbience(uid, false);
}
private void TurnOn(EntityUid uid, EmergencyLightComponent component)
{
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);
_pointLight.SetEnabled(uid, true);
_appearance.SetData(uid, EmergencyLightVisuals.On, true);
_ambient.SetAmbience(uid, true);
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View 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);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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,
}
}

View File

@@ -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
}
}

View File

@@ -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;
}
}

View File

@@ -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
{
}
}

View 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,
}

View File

@@ -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.

View File

@@ -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;

View 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;
}

View File

@@ -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,
}

View File

@@ -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
}

View File

@@ -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
{
}

View File

@@ -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");

View File

@@ -1,7 +1,5 @@
namespace Content.Shared.Light
{
namespace Content.Shared.Light;
public abstract class SharedEmergencyLightSystem : EntitySystem
{
}
}

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Light.Component;
using Content.Shared.Light.Components;
using Robust.Shared.GameStates;
namespace Content.Shared.Light;

View File

@@ -0,0 +1,5 @@
namespace Content.Shared.Light;
public abstract class SharedRotatingLightSystem : EntitySystem
{
}

View File

@@ -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;

View File

@@ -314,6 +314,7 @@
maxCharge: 30000
startingCharge: 0
- type: EmergencyLight
- type: RotatingLight
- type: Sprite
sprite: Structures/Wallmounts/Lighting/emergency_light.rsi
layers: