Fix mailing units turning into disposal units while recharging. (#26383)

* Fix mailing units turning into disposal units while recharging.

The states were hardcoded.

* Fix error handling

* Make default states constants
This commit is contained in:
nikthechampiongr
2024-03-25 15:20:39 +02:00
committed by GitHub
parent aec1d6a02c
commit 94e4755a8d
2 changed files with 14 additions and 3 deletions

View File

@@ -22,6 +22,9 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
private const string AnimationKey = "disposal_unit_animation"; private const string AnimationKey = "disposal_unit_animation";
private const string DefaultFlushState = "disposal-flush";
private const string DefaultChargeState = "disposal-charging";
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -101,12 +104,18 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
sprite.LayerSetVisible(DisposalUnitVisualLayers.Base, state == VisualState.Anchored); sprite.LayerSetVisible(DisposalUnitVisualLayers.Base, state == VisualState.Anchored);
sprite.LayerSetVisible(DisposalUnitVisualLayers.BaseFlush, state is VisualState.Flushing or VisualState.Charging); sprite.LayerSetVisible(DisposalUnitVisualLayers.BaseFlush, state is VisualState.Flushing or VisualState.Charging);
var chargingState = sprite.LayerMapTryGet(DisposalUnitVisualLayers.BaseCharging, out var chargingLayer)
? sprite.LayerGetState(chargingLayer)
: new RSI.StateId(DefaultChargeState);
// This is a transient state so not too worried about replaying in range. // This is a transient state so not too worried about replaying in range.
if (state == VisualState.Flushing) if (state == VisualState.Flushing)
{ {
if (!_animationSystem.HasRunningAnimation(uid, AnimationKey)) if (!_animationSystem.HasRunningAnimation(uid, AnimationKey))
{ {
var flushState = new RSI.StateId("disposal-flush"); var flushState = sprite.LayerMapTryGet(DisposalUnitVisualLayers.BaseFlush, out var flushLayer)
? sprite.LayerGetState(flushLayer)
: new RSI.StateId(DefaultFlushState);
// Setup the flush animation to play // Setup the flush animation to play
var anim = new Animation var anim = new Animation
@@ -124,7 +133,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
// Return to base state (though, depending on how the unit is // Return to base state (though, depending on how the unit is
// configured we might get an appearance change event telling // configured we might get an appearance change event telling
// us to go to charging state) // us to go to charging state)
new AnimationTrackSpriteFlick.KeyFrame("disposal-charging", (float) unit.FlushDelay.TotalSeconds) new AnimationTrackSpriteFlick.KeyFrame(chargingState, (float) unit.FlushDelay.TotalSeconds)
} }
}, },
} }
@@ -147,7 +156,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
} }
else if (state == VisualState.Charging) else if (state == VisualState.Charging)
{ {
sprite.LayerSetState(DisposalUnitVisualLayers.BaseFlush, new RSI.StateId("disposal-charging")); sprite.LayerSetState(DisposalUnitVisualLayers.BaseFlush, chargingState);
} }
else else
{ {

View File

@@ -16,6 +16,8 @@
map: [ "enum.DisposalUnitVisualLayers.Unanchored" ] map: [ "enum.DisposalUnitVisualLayers.Unanchored" ]
- state: disposal - state: disposal
map: [ "enum.DisposalUnitVisualLayers.Base" ] map: [ "enum.DisposalUnitVisualLayers.Base" ]
- state: disposal-charging
map: [ "enum.DisposalUnitVisualLayers.BaseCharging" ]
- state: disposal-flush - state: disposal-flush
map: [ "enum.DisposalUnitVisualLayers.BaseFlush" ] map: [ "enum.DisposalUnitVisualLayers.BaseFlush" ]
- state: dispover-charge - state: dispover-charge