Resolves SmesVisualizer is Obsolete (#13899)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
28
Content.Client/Power/SMES/SmesComponent.cs
Normal file
28
Content.Client/Power/SMES/SmesComponent.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace Content.Client.Power.SMES;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class SmesComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The prefix used for the RSI states of the sprite layers indicating the charge level of the SMES.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("chargeOverlayPrefix")]
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public string ChargeOverlayPrefix = "smes-og";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The prefix used for the RSI states of the sprite layers indicating the input state of the SMES.
|
||||||
|
/// Actually bundled together with the output indicator light.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("inputOverlayPrefix")]
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public string InputOverlayPrefix = "smes-oc";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The prefix used for the RSI states of the sprite layers indicating the output state of the SMES.
|
||||||
|
/// Actually bundled together with the input indicator light.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("outputOverlayPrefix")]
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public string OutputOverlayPrefix = "smes-op";
|
||||||
|
}
|
||||||
50
Content.Client/Power/SMES/SmesSystem.cs
Normal file
50
Content.Client/Power/SMES/SmesSystem.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using Content.Shared.Power;
|
||||||
|
using Content.Shared.SMES;
|
||||||
|
using Robust.Client.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Client.Power.SMES;
|
||||||
|
|
||||||
|
public sealed class SmesVisualizerSystem : VisualizerSystem<SmesComponent>
|
||||||
|
{
|
||||||
|
protected override void OnAppearanceChange(EntityUid uid, SmesComponent comp, ref AppearanceChangeEvent args)
|
||||||
|
{
|
||||||
|
if (args.Sprite == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!AppearanceSystem.TryGetData<int>(uid, SmesVisuals.LastChargeLevel, out var level, args.Component) || level == 0)
|
||||||
|
{
|
||||||
|
args.Sprite.LayerSetVisible(SmesVisualLayers.Charge, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
args.Sprite.LayerSetVisible(SmesVisualLayers.Charge, true);
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Charge, $"{comp.ChargeOverlayPrefix}{level}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AppearanceSystem.TryGetData<ChargeState>(uid, SmesVisuals.LastChargeState, out var state, args.Component))
|
||||||
|
state = ChargeState.Still;
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case ChargeState.Still:
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}0");
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}1");
|
||||||
|
break;
|
||||||
|
case ChargeState.Charging:
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}1");
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}1");
|
||||||
|
break;
|
||||||
|
case ChargeState.Discharging:
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}0");
|
||||||
|
args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}2");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SmesVisualLayers : byte
|
||||||
|
{
|
||||||
|
Input,
|
||||||
|
Charge,
|
||||||
|
Output,
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
using Content.Shared.Power;
|
|
||||||
using Content.Shared.SMES;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Robust.Client.GameObjects;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
|
|
||||||
namespace Content.Client.Power.SMES
|
|
||||||
{
|
|
||||||
[UsedImplicitly]
|
|
||||||
public sealed class SmesVisualizer : AppearanceVisualizer
|
|
||||||
{
|
|
||||||
[Obsolete("Subscribe to your component being initialised instead.")]
|
|
||||||
public override void InitializeEntity(EntityUid entity)
|
|
||||||
{
|
|
||||||
base.InitializeEntity(entity);
|
|
||||||
|
|
||||||
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(entity);
|
|
||||||
|
|
||||||
sprite.LayerMapSet(Layers.Input, sprite.AddLayerState("smes-oc0"));
|
|
||||||
sprite.LayerSetShader(Layers.Input, "unshaded");
|
|
||||||
sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState("smes-og1"));
|
|
||||||
sprite.LayerSetShader(Layers.Charge, "unshaded");
|
|
||||||
sprite.LayerSetVisible(Layers.Charge, false);
|
|
||||||
sprite.LayerMapSet(Layers.Output, sprite.AddLayerState("smes-op0"));
|
|
||||||
sprite.LayerSetShader(Layers.Output, "unshaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
|
||||||
public override void OnChangeData(AppearanceComponent component)
|
|
||||||
{
|
|
||||||
base.OnChangeData(component);
|
|
||||||
|
|
||||||
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(component.Owner);
|
|
||||||
if (!component.TryGetData<int>(SmesVisuals.LastChargeLevel, out var level) || level == 0)
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(Layers.Charge, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(Layers.Charge, true);
|
|
||||||
sprite.LayerSetState(Layers.Charge, $"smes-og{level}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<ChargeState>(SmesVisuals.LastChargeState, out var state))
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case ChargeState.Still:
|
|
||||||
sprite.LayerSetState(Layers.Input, "smes-oc0");
|
|
||||||
sprite.LayerSetState(Layers.Output, "smes-op1");
|
|
||||||
break;
|
|
||||||
case ChargeState.Charging:
|
|
||||||
sprite.LayerSetState(Layers.Input, "smes-oc1");
|
|
||||||
sprite.LayerSetState(Layers.Output, "smes-op1");
|
|
||||||
break;
|
|
||||||
case ChargeState.Discharging:
|
|
||||||
sprite.LayerSetState(Layers.Input, "smes-oc0");
|
|
||||||
sprite.LayerSetState(Layers.Output, "smes-op2");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite.LayerSetState(Layers.Input, "smes-oc0");
|
|
||||||
sprite.LayerSetState(Layers.Output, "smes-op1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Layers : byte
|
|
||||||
{
|
|
||||||
Input,
|
|
||||||
Charge,
|
|
||||||
Output,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,12 @@
|
|||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Shared.Power;
|
using Content.Shared.Power;
|
||||||
using Content.Shared.Rounding;
|
|
||||||
using Content.Shared.SMES;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.Timing;
|
|
||||||
|
|
||||||
namespace Content.Server.Power.SMES;
|
namespace Content.Server.Power.SMES;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the "user-facing" side of the actual SMES object.
|
/// Handles the "user-facing" side of the actual SMES object.
|
||||||
/// This is operations that are specific to the SMES, like UI and visuals.
|
/// This is operations that are specific to the SMES, like UI and visuals.
|
||||||
/// Logic is handled in <see cref="PowerSmesSystem"/>
|
/// Logic is handled in <see cref="SmesSystem"/>
|
||||||
/// Code interfacing with the powernet is handled in <see cref="BatteryStorageComponent"/> and <see cref="BatteryDischargerComponent"/>.
|
/// Code interfacing with the powernet is handled in <see cref="BatteryStorageComponent"/> and <see cref="BatteryDischargerComponent"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, Access(typeof(SmesSystem))]
|
[RegisterComponent, Access(typeof(SmesSystem))]
|
||||||
@@ -26,4 +22,23 @@ public sealed class SmesComponent : Component
|
|||||||
public TimeSpan LastChargeLevelTime;
|
public TimeSpan LastChargeLevelTime;
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
|
public TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of distinct charge levels a SMES has.
|
||||||
|
/// 0 is empty max is full.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("numChargeLevels")]
|
||||||
|
public int NumChargeLevels = 6;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The charge level of the SMES as of the most recent update.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public int ChargeLevel = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the SMES is being charged/discharged/neither.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public ChargeState ChargeState = ChargeState.Still;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ internal sealed class SmesSystem : EntitySystem
|
|||||||
|
|
||||||
private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null)
|
private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null)
|
||||||
{
|
{
|
||||||
if (!Resolve<BatteryComponent>(uid, ref battery))
|
if (!Resolve(uid, ref battery))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6);
|
return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6);
|
||||||
@@ -65,7 +65,7 @@ internal sealed class SmesSystem : EntitySystem
|
|||||||
|
|
||||||
private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null)
|
private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null)
|
||||||
{
|
{
|
||||||
if (!Resolve<PowerNetworkBatteryComponent>(uid, ref netBattery))
|
if (!Resolve(uid, ref netBattery))
|
||||||
return ChargeState.Still;
|
return ChargeState.Still;
|
||||||
|
|
||||||
return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch
|
return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
namespace Content.Shared.Power
|
namespace Content.Shared.Power
|
||||||
{
|
{
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum ChargeState
|
public enum ChargeState : byte
|
||||||
{
|
{
|
||||||
Still,
|
Still = 0,
|
||||||
Charging,
|
Charging = 1,
|
||||||
Discharging,
|
Discharging = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.SMES
|
namespace Content.Shared.SMES;
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum SmesVisuals
|
||||||
{
|
{
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public enum SmesVisuals
|
|
||||||
{
|
|
||||||
LastChargeState,
|
LastChargeState,
|
||||||
LastChargeLevel,
|
LastChargeLevel,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,21 @@
|
|||||||
snapCardinals: true
|
snapCardinals: true
|
||||||
layers:
|
layers:
|
||||||
- state: smes
|
- state: smes
|
||||||
|
- map: ["enum.SmesVisualLayers.Charge"]
|
||||||
|
state: "smes-og1" # -og0 does not exist
|
||||||
|
shader: unshaded
|
||||||
|
visible: false
|
||||||
|
- map: ["enum.SmesVisualLayers.Input"]
|
||||||
|
state: "smes-oc0"
|
||||||
|
shader: unshaded
|
||||||
|
- map: ["enum.SmesVisualLayers.Output"]
|
||||||
|
state: "smes-op1"
|
||||||
|
shader: unshaded
|
||||||
- type: Smes
|
- type: Smes
|
||||||
- type: UpgradeBattery
|
- type: UpgradeBattery
|
||||||
maxChargeMultiplier: 2
|
maxChargeMultiplier: 2
|
||||||
baseMaxCharge: 8000000
|
baseMaxCharge: 8000000
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
|
||||||
- type: SmesVisualizer
|
|
||||||
- type: Battery
|
- type: Battery
|
||||||
startingCharge: 0
|
startingCharge: 0
|
||||||
- type: ExaminableBattery
|
- type: ExaminableBattery
|
||||||
|
|||||||
Reference in New Issue
Block a user