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

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

@@ -0,0 +1,128 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
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 : Component
{
/// <summary>
/// The color of the lightbulb and the light it produces.
/// </summary>
[DataField("color")]
[ViewVariables(VVAccess.ReadWrite)]
public Color Color = Color.White;
/// <summary>
/// The type of lightbulb. Tube/bulb/etc...
/// </summary>
[DataField("bulb")]
[ViewVariables(VVAccess.ReadWrite)]
public LightBulbType Type = LightBulbType.Tube;
/// <summary>
/// The initial state of the lightbulb.
/// </summary>
[DataField("startingState")]
public LightBulbState State = LightBulbState.Normal;
/// <summary>
/// The temperature the air around the lightbulb is exposed to when the lightbulb burns out.
/// </summary>
[DataField("BurningTemperature")]
[ViewVariables(VVAccess.ReadWrite)]
public int BurningTemperature = 1400;
/// <summary>
/// Relates to how bright the light produced by the lightbulb is.
/// </summary>
[DataField("lightEnergy")]
[ViewVariables(VVAccess.ReadWrite)]
public float LightEnergy = 0.8f;
/// <summary>
/// The maximum radius of the point light source this light produces.
/// </summary>
[DataField("lightRadius")]
[ViewVariables(VVAccess.ReadWrite)]
public float LightRadius = 10;
/// <summary>
/// Relates to the falloff constant of the light produced by the lightbulb.
/// </summary>
[DataField("lightSoftness")]
[ViewVariables(VVAccess.ReadWrite)]
public float LightSoftness = 1;
/// <summary>
/// The amount of power used by the lightbulb when it's active.
/// </summary>
[DataField("PowerUse")]
[ViewVariables(VVAccess.ReadWrite)]
public int PowerUse = 60;
/// <summary>
/// The sound produced when the lightbulb breaks.
/// </summary>
[DataField("breakSound")]
[ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier BreakSound = new SoundCollectionSpecifier("GlassBreak");
#region Appearance
/// <summary>
/// The sprite state used when the lightbulb is intact.
/// </summary>
[DataField("normalSpriteState")]
[ViewVariables(VVAccess.ReadWrite)]
public string NormalSpriteState = "normal";
/// <summary>
/// The sprite state used when the lightbulb is broken.
/// </summary>
[DataField("brokenSpriteState")]
[ViewVariables(VVAccess.ReadWrite)]
public string BrokenSpriteState = "broken";
/// <summary>
/// The sprite state used when the lightbulb is burned.
/// </summary>
[DataField("burnedSpriteState")]
[ViewVariables(VVAccess.ReadWrite)]
public string BurnedSpriteState = "burned";
#endregion Appearance
}
[Serializable, NetSerializable]
public enum LightBulbState : byte
{
Normal,
Broken,
Burned,
}
[Serializable, NetSerializable]
public enum LightBulbVisuals : byte
{
State,
Color
}
[Serializable, NetSerializable]
public enum LightBulbType : byte
{
Bulb,
Tube,
}
[Serializable, NetSerializable]
public enum LightBulbVisualLayers : byte
{
Base,
}

View File

@@ -0,0 +1,57 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
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
/// sprite layers. Will also modulate the color of any unshaded layers that this entity contributes to a wearer or holder.
/// </summary>
/// <remarks>
/// Networked ~~solely for admemes~~ for completely legitimate reasons, like hacked energy swords.
/// </remarks>
[NetworkedComponent, RegisterComponent, Access(typeof(SharedRgbLightControllerSystem))]
public sealed partial class RgbLightControllerComponent : Component
{
[DataField("cycleRate")]
public float CycleRate { get; set; } = 0.1f;
/// <summary>
/// What layers of the sprite to modulate? If null, will affect only unshaded layers.
/// </summary>
[DataField("layers")]
public List<int>? Layers;
/// <summary>
/// Original light color from befor the rgb was aded. Used to revert colors when removed.
/// </summary>
public Color OriginalLightColor;
/// <summary>
/// Original colors of the sprite layersfrom before the rgb was added. Used to revert colors when removed.
/// </summary>
public Dictionary<int, Color>? OriginalLayerColors;
/// <summary>
/// User that is holding or wearing this entity
/// </summary>
public EntityUid? Holder;
/// <summary>
/// List of unshaded layers on the holder/wearer that are being modulated.
/// </summary>
public List<string>? HolderLayers;
}
[Serializable, NetSerializable]
public sealed class RgbLightControllerState : ComponentState
{
public readonly float CycleRate;
public List<int>? Layers;
public RgbLightControllerState(float cycleRate, List<int>? layers)
{
CycleRate = cycleRate;
Layers = layers;
}
}

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

@@ -0,0 +1,29 @@
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Decals;
using Robust.Shared.Audio;
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 : Component
{
[DataField("toggleFlashlightSound")]
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Items/flashlight_pda.ogg");
[ViewVariables] public bool LightOn = false;
[DataField("toggleAction", required: true)]
public InstantAction ToggleAction = new();
/// <summary>
/// <see cref="ColorPalettePrototype"/> ID that determines the list
/// of colors to select from when we get emagged
/// </summary>
[DataField("emaggedColorsPrototype")]
[ViewVariables(VVAccess.ReadWrite)]
public string EmaggedColorsPrototype = "Emagged";
}