Skip to content

Commit

Permalink
Radiation collector sprite update (#20956)
Browse files Browse the repository at this point in the history
  • Loading branch information
chromiumboy authored Oct 13, 2023
1 parent dd6b7b3 commit 4c630d0
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Content.Shared.Examine;
using Content.Server.Atmos;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Atmos;

namespace Content.Server.Singularity.EntitySystems;

Expand All @@ -27,6 +28,9 @@ public override void Initialize()
SubscribeLocalEvent<RadiationCollectorComponent, OnIrradiatedEvent>(OnRadiation);
SubscribeLocalEvent<RadiationCollectorComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<RadiationCollectorComponent, GasAnalyzerScanEvent>(OnAnalyzed);
SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
}

private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
Expand All @@ -43,6 +47,18 @@ private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankC
return true;
}

private void OnMapInit(EntityUid uid, RadiationCollectorComponent component, MapInitEvent args)
{
TryGetLoadedGasTank(uid, out var gasTank);
UpdateTankAppearance(uid, component, gasTank);
}

private void OnTankChanged(EntityUid uid, RadiationCollectorComponent component, ContainerModifiedMessage args)
{
TryGetLoadedGasTank(uid, out var gasTank);
UpdateTankAppearance(uid, component, gasTank);
}

private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
{
var curTime = _gameTiming.CurTime;
Expand Down Expand Up @@ -97,22 +113,20 @@ private void OnRadiation(EntityUid uid, RadiationCollectorComponent component, O
{
batteryComponent.CurrentCharge += charge;
}

// Update appearance
UpdatePressureIndicatorAppearance(uid, component, gasTankComponent);
}

private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
{
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
if (!TryGetLoadedGasTank(uid, out var gasTank))
{
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-missing"));
return;
}

args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-present"));

if (gasTankComponent.IsLowPressure)
{
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-low-pressure"));
}
}

private void OnAnalyzed(EntityUid uid, RadiationCollectorComponent component, GasAnalyzerScanEvent args)
Expand All @@ -133,7 +147,7 @@ public void ToggleCollector(EntityUid uid, EntityUid? user = null, RadiationColl

public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = null, RadiationCollectorComponent? component = null)
{
if (!Resolve(uid, ref component))
if (!Resolve(uid, ref component, false))
return;

component.Enabled = enabled;
Expand All @@ -146,15 +160,43 @@ public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = n
}

// Update appearance
UpdateAppearance(uid, component);
UpdateMachineAppearance(uid, component);
}

private void UpdateAppearance(EntityUid uid, RadiationCollectorComponent? component, AppearanceComponent? appearance = null)
private void UpdateMachineAppearance(EntityUid uid, RadiationCollectorComponent component, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref component, ref appearance))
if (!Resolve(uid, ref appearance))
return;

var state = component.Enabled ? RadiationCollectorVisualState.Active : RadiationCollectorVisualState.Deactive;
_appearance.SetData(uid, RadiationCollectorVisuals.VisualState, state, appearance);
}

private void UpdatePressureIndicatorAppearance(EntityUid uid, RadiationCollectorComponent component, GasTankComponent? gasTank = null, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref appearance, false))
return;

if (gasTank == null || gasTank.Air.Pressure < 10)
_appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 0, appearance);

else if (gasTank.Air.Pressure < Atmospherics.OneAtmosphere)
_appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 1, appearance);

else if (gasTank.Air.Pressure < 3f * Atmospherics.OneAtmosphere)
_appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 2, appearance);

else
_appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 3, appearance);
}

private void UpdateTankAppearance(EntityUid uid, RadiationCollectorComponent component, GasTankComponent? gasTank = null, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref appearance, false))
return;

_appearance.SetData(uid, RadiationCollectorVisuals.TankInserted, gasTank != null, appearance);

UpdatePressureIndicatorAppearance(uid, component, gasTank, appearance);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Robust.Shared.Serialization;
using Robust.Shared.Serialization;

namespace Content.Shared.Singularity.Components
{
[NetSerializable, Serializable]
public enum RadiationCollectorVisuals
{
VisualState
VisualState,
TankInserted,
PressureState,
}

[NetSerializable, Serializable]
public enum RadiationCollectorVisualState
{
{
Active = (1<<0),
Activating = (1<<1) | Active,
Deactivating = (1<<1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
power-radiation-collector-gas-tank-missing = [color=red]No gas tank attached.[/color]
power-radiation-collector-gas-tank-present = A gas tank is [color=darkgreen]connected[/color].
power-radiation-collector-gas-tank-low-pressure = The gas tank [color=orange]low pressure[/color] light is on.
power-radiation-collector-gas-tank-missing = [color=darkred]No plasma tank attached.[/color]
power-radiation-collector-gas-tank-present = A plasma tank is [color=darkgreen]connected[/color].
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
- state: ca_off
map: ["enum.RadiationCollectorVisualLayers.Main"]
- type: Appearance
- type: GenericVisualizer
visuals:
enum.RadiationCollectorVisuals.TankInserted:
tankInserted:
False: { state: ca-tank, visible: false }
True: { state: ca-tank, visible: true }
enum.RadiationCollectorVisuals.PressureState:
pressureLight:
0: { state: ca-o0, shader: "unshaded" }
1: { state: ca-o1, shader: "unshaded" }
2: { state: ca-o2, shader: "unshaded" }
3: { state: ca-o3, shader: "unshaded" }
- type: AnimationPlayer
- type: NodeContainer
examinable: true
Expand All @@ -44,7 +56,6 @@
- reactantPrototype: Plasma
powerGenerationEfficiency: 1
reactantBreakdownRate: 0.0002
byproductPrototype: Tritium
# Note that this doesn't matter too much (see next comment)
# However it does act as a cap on power receivable via the collector.
- type: Battery
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from goonstation at https://github.com/goonstation/goonstation/commit/cbe076402ed43b1cd861295bbcb95608c453de7a",
"copyright": "Taken from goonstation at https://github.com/goonstation/goonstation/commit/cbe076402ed43b1cd861295bbcb95608c453de7a. Edited by chromiumboy",
"size": {
"x": 32,
"y": 32
Expand Down Expand Up @@ -39,6 +39,27 @@
},
{
"name": "cu"
},
{
"name": "ca-o0",
"delays": [
[
0.2,
0.2
]
]
},
{
"name": "ca-o1"
},
{
"name": "ca-o2"
},
{
"name": "ca-o3"
},
{
"name": "ca-tank"
}
]
}

0 comments on commit 4c630d0

Please sign in to comment.