Rotatable Pumps (#2223)
* Pump textures * PumpVisualizer enabled state * Pump rotation * Pump tests fix Co-authored-by: py01 <pyronetics01@gmail.com>
@@ -1,14 +1,8 @@
|
|||||||
using System;
|
using Content.Shared.GameObjects.Components.Atmos;
|
||||||
using Content.Shared.GameObjects.Components.Atmos;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.Graphics;
|
|
||||||
using Robust.Client.Interfaces.GameObjects.Components;
|
using Robust.Client.Interfaces.GameObjects.Components;
|
||||||
using Robust.Client.Interfaces.ResourceManagement;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Client.ResourceManagement;
|
|
||||||
using Robust.Shared.GameObjects.Components.Renderable;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Log;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using YamlDotNet.RepresentationModel;
|
using YamlDotNet.RepresentationModel;
|
||||||
|
|
||||||
@@ -17,68 +11,38 @@ namespace Content.Client.GameObjects.Components.Atmos
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class PumpVisualizer : AppearanceVisualizer
|
public class PumpVisualizer : AppearanceVisualizer
|
||||||
{
|
{
|
||||||
private RSI _pumpRSI;
|
private string _pumpEnabledState;
|
||||||
|
|
||||||
public override void LoadData(YamlMappingNode node)
|
public override void LoadData(YamlMappingNode node)
|
||||||
{
|
{
|
||||||
base.LoadData(node);
|
base.LoadData(node);
|
||||||
|
_pumpEnabledState = node.GetNode("pumpEnabledState").ToString();
|
||||||
|
}
|
||||||
|
|
||||||
var rsiString = node.GetNode("pumpRSI").ToString();
|
public override void InitializeEntity(IEntity entity)
|
||||||
var rsiPath = SharedSpriteComponent.TextureRoot / rsiString;
|
{
|
||||||
try
|
base.InitializeEntity(entity);
|
||||||
{
|
|
||||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
if (!entity.TryGetComponent(out ISpriteComponent sprite)) return;
|
||||||
var resource = resourceCache.GetResource<RSIResource>(rsiPath);
|
|
||||||
_pumpRSI = resource.RSI;
|
sprite.LayerMapReserveBlank(Layer.PumpEnabled);
|
||||||
}
|
var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled);
|
||||||
catch (Exception e)
|
sprite.LayerSetState(pumpEnabledLayer, _pumpEnabledState);
|
||||||
{
|
|
||||||
Logger.ErrorS("go.pumpvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnChangeData(AppearanceComponent component)
|
public override void OnChangeData(AppearanceComponent component)
|
||||||
{
|
{
|
||||||
base.OnChangeData(component);
|
base.OnChangeData(component);
|
||||||
|
|
||||||
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
|
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return;
|
||||||
{
|
if (!component.TryGetData(PumpVisuals.VisualState, out PumpVisualState pumpVisualState)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!component.TryGetData(PumpVisuals.VisualState, out PumpVisualState pumpVisualState))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var pumpBaseState = "pump";
|
|
||||||
pumpBaseState += pumpVisualState.InletDirection.ToString();
|
|
||||||
pumpBaseState += ((int) pumpVisualState.InletConduitLayer).ToString();
|
|
||||||
pumpBaseState += pumpVisualState.OutletDirection.ToString();
|
|
||||||
pumpBaseState += ((int) pumpVisualState.OutletConduitLayer).ToString();
|
|
||||||
|
|
||||||
sprite.LayerMapReserveBlank(Layer.PumpBase);
|
var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled);
|
||||||
var basePumpLayer = sprite.LayerMapGet(Layer.PumpBase);
|
sprite.LayerSetVisible(pumpEnabledLayer, pumpVisualState.PumpEnabled);
|
||||||
sprite.LayerSetRSI(basePumpLayer, _pumpRSI);
|
|
||||||
sprite.LayerSetState(basePumpLayer, pumpBaseState);
|
|
||||||
sprite.LayerSetVisible(basePumpLayer, true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pumpEnabledAnimationState = "pumpEnabled";
|
|
||||||
pumpEnabledAnimationState += pumpVisualState.InletDirection.ToString();
|
|
||||||
pumpEnabledAnimationState += ((int) pumpVisualState.InletConduitLayer).ToString();
|
|
||||||
pumpEnabledAnimationState += pumpVisualState.OutletDirection.ToString();
|
|
||||||
pumpEnabledAnimationState += ((int) pumpVisualState.OutletConduitLayer).ToString();
|
|
||||||
|
|
||||||
sprite.LayerMapReserveBlank(Layer.PumpEnabled);
|
|
||||||
var pumpEnabledAnimationLayer = sprite.LayerMapGet(Layer.PumpEnabled);
|
|
||||||
sprite.LayerSetRSI(pumpEnabledAnimationLayer, _pumpRSI);
|
|
||||||
sprite.LayerSetState(pumpEnabledAnimationLayer, pumpEnabledAnimationState);
|
|
||||||
sprite.LayerSetVisible(pumpEnabledAnimationLayer, pumpVisualState.PumpEnabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Layer
|
public enum Layer
|
||||||
{
|
{
|
||||||
PumpBase,
|
|
||||||
PumpEnabled,
|
PumpEnabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.NodeContainer;
|
|||||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||||
using Content.Shared.GameObjects.Components.Atmos;
|
using Content.Shared.GameObjects.Components.Atmos;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.Components.Transform;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
@@ -28,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
|
|||||||
UpdateAppearance();
|
UpdateAppearance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private bool _pumpEnabled = true;
|
private bool _pumpEnabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
|
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
|
||||||
@@ -55,11 +57,50 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
|
|||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
serializer.DataField(ref _inletDirection, "inletDirection", PipeDirection.None);
|
serializer.DataField(ref _inletDirection, "inletDirection", PipeDirection.None);
|
||||||
serializer.DataField(ref _outletDirection, "outletDirection", PipeDirection.None);
|
serializer.DataField(ref _outletDirection, "outletDirection", PipeDirection.None);
|
||||||
|
serializer.DataField(ref _pumpEnabled, "pumpEnabled", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
UpdatePipes();
|
||||||
|
Owner.EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
|
||||||
|
Owner.TryGetComponent(out _appearance);
|
||||||
|
UpdateAppearance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
if (!PumpEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PumpGas(_inletPipe.Air, _outletPipe.Air);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void PumpGas(GasMixture inletGas, GasMixture outletGas);
|
||||||
|
|
||||||
|
private void RotateEvent(RotateEvent ev)
|
||||||
|
{
|
||||||
|
if (ev.Sender != Owner || ev.NewRotation == ev.OldRotation)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var diff = ev.NewRotation - ev.OldRotation;
|
||||||
|
_inletDirection = _inletDirection.RotatePipeDirection(diff);
|
||||||
|
_outletDirection = _outletDirection.RotatePipeDirection(diff);
|
||||||
|
UpdatePipes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateAppearance()
|
||||||
|
{
|
||||||
|
if (_inletPipe == null || _outletPipe == null) return;
|
||||||
|
_appearance?.SetData(PumpVisuals.VisualState, new PumpVisualState(_inletDirection, _outletDirection, _inletPipe.ConduitLayer, _outletPipe.ConduitLayer, PumpEnabled));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePipes()
|
||||||
|
{
|
||||||
|
_inletPipe = null;
|
||||||
|
_outletPipe = null;
|
||||||
|
|
||||||
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
||||||
{
|
{
|
||||||
JoinedGridAtmos?.RemovePipeNetDevice(this);
|
JoinedGridAtmos?.RemovePipeNetDevice(this);
|
||||||
@@ -75,23 +116,6 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
|
|||||||
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
|
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Owner.TryGetComponent(out _appearance);
|
|
||||||
UpdateAppearance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Update()
|
|
||||||
{
|
|
||||||
if (!PumpEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PumpGas(_inletPipe.Air, _outletPipe.Air);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void PumpGas(GasMixture inletGas, GasMixture outletGas);
|
|
||||||
|
|
||||||
private void UpdateAppearance()
|
|
||||||
{
|
|
||||||
_appearance?.SetData(PumpVisuals.VisualState, new PumpVisualState(_inletDirection, _outletDirection, _inletPipe.ConduitLayer, _outletPipe.ConduitLayer, PumpEnabled));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,16 +96,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
|||||||
void IRotatableNode.RotateEvent(RotateEvent ev)
|
void IRotatableNode.RotateEvent(RotateEvent ev)
|
||||||
{
|
{
|
||||||
var diff = ev.NewRotation - ev.OldRotation;
|
var diff = ev.NewRotation - ev.OldRotation;
|
||||||
var newPipeDir = PipeDirection.None;
|
PipeDirection = PipeDirection.RotatePipeDirection(diff);
|
||||||
for (var i = 0; i < PipeDirectionHelpers.PipeDirections; i++)
|
|
||||||
{
|
|
||||||
var pipeDirection = (PipeDirection) (1 << i);
|
|
||||||
if (!PipeDirection.HasFlag(pipeDirection)) continue;
|
|
||||||
var angle = pipeDirection.ToAngle();
|
|
||||||
angle += diff;
|
|
||||||
newPipeDir |= angle.GetCardinalDir().ToPipeDirection();
|
|
||||||
}
|
|
||||||
PipeDirection = newPipeDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<Node> GetReachableNodes()
|
protected override IEnumerable<Node> GetReachableNodes()
|
||||||
|
|||||||
@@ -144,5 +144,19 @@ namespace Content.Shared.GameObjects.Components.Atmos
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
|
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PipeDirection RotatePipeDirection(this PipeDirection pipeDirection, double diff)
|
||||||
|
{
|
||||||
|
var newPipeDir = PipeDirection.None;
|
||||||
|
for (var i = 0; i < PipeDirections; i++)
|
||||||
|
{
|
||||||
|
var currentPipeDirection = (PipeDirection) (1 << i);
|
||||||
|
if (!pipeDirection.HasFlag(currentPipeDirection)) continue;
|
||||||
|
var angle = currentPipeDirection.ToAngle();
|
||||||
|
angle += diff;
|
||||||
|
newPipeDir |= angle.GetCardinalDir().ToPipeDirection();
|
||||||
|
}
|
||||||
|
return newPipeDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,48 +9,35 @@
|
|||||||
- type: Collidable
|
- type: Collidable
|
||||||
- type: SnapGrid
|
- type: SnapGrid
|
||||||
offset: Center
|
offset: Center
|
||||||
- type: Sprite
|
|
||||||
- type: Icon
|
|
||||||
sprite: Constructible/Atmos/pressurepump.rsi
|
|
||||||
state: pumpEnabledSouth2North2
|
|
||||||
- type: Appearance
|
|
||||||
visuals:
|
|
||||||
- type: PipeVisualizer
|
|
||||||
pipeRSI: Constructible/Atmos/pipe.rsi
|
|
||||||
- type: PumpVisualizer
|
|
||||||
pumpRSI: Constructible/Atmos/pressurepump.rsi
|
|
||||||
- type: Destructible
|
- type: Destructible
|
||||||
thresholdvalue: 100
|
thresholdvalue: 100
|
||||||
resistances: metallicResistances
|
resistances: metallicResistances
|
||||||
|
- type: Sprite
|
||||||
|
sprite: Constructible/Atmos/pump.rsi
|
||||||
|
- type: Icon
|
||||||
|
sprite: Constructible/Atmos/pump.rsi
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
abstract: true
|
|
||||||
parent: PumpBase
|
parent: PumpBase
|
||||||
id: NorthwardLongitudinalPump
|
id: DebugPressurePump
|
||||||
|
name: Debug Pressure Pump
|
||||||
components:
|
components:
|
||||||
- type: NodeContainer
|
- type: NodeContainer
|
||||||
nodes:
|
nodes:
|
||||||
- !type:PipeNode
|
- !type:PipeNode
|
||||||
nodeGroupID: Pipe
|
nodeGroupID: Pipe
|
||||||
pipeDirection: South
|
pipeDirection: West
|
||||||
- !type:PipeNode
|
- !type:PipeNode
|
||||||
nodeGroupID: Pipe
|
nodeGroupID: Pipe
|
||||||
pipeDirection: North
|
pipeDirection: East
|
||||||
|
|
||||||
- type: entity
|
|
||||||
parent: NorthwardLongitudinalPump
|
|
||||||
id: NorthwardLongitudinalVolumePump
|
|
||||||
name: Northward Longitudinal Volume Pump
|
|
||||||
components:
|
|
||||||
- type: VolumePump
|
|
||||||
inletDirection: South
|
|
||||||
outletDirection: North
|
|
||||||
|
|
||||||
- type: entity
|
|
||||||
parent: NorthwardLongitudinalPump
|
|
||||||
id: NorthwardLongitudinalPressurePump
|
|
||||||
name: Northward Longitudinal Pressure Pump
|
|
||||||
components:
|
|
||||||
- type: PressurePump
|
- type: PressurePump
|
||||||
inletDirection: South
|
inletDirection: West
|
||||||
outletDirection: North
|
outletDirection: East
|
||||||
|
- type: Sprite
|
||||||
|
state: pumpPressure2
|
||||||
|
- type: Icon
|
||||||
|
state: pumpPressure2
|
||||||
|
- type: Appearance
|
||||||
|
visuals:
|
||||||
|
- type: PumpVisualizer
|
||||||
|
pumpEnabledState: pumpPressure2On
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
{
|
|
||||||
"version":1,
|
|
||||||
"size":{
|
|
||||||
"x":32,
|
|
||||||
"y":32
|
|
||||||
},
|
|
||||||
"license":"CC-BY-SA-3.0",
|
|
||||||
"copyright":"Taken from https://github.com/tgstation/tgstation at commit 57cd1d59ca019dd0e7811ac451f295f818e573da",
|
|
||||||
"states":[
|
|
||||||
{
|
|
||||||
"name":"pumpEast2West2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 1.0 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpNorth2South2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 1.0 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpSouth2North2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 1.0 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpWest2East2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 1.0 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpEnabledEast2West2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 0.1, 0.1, 0.1, 0.1, 0.1 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpEnabledNorth2South2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 0.1, 0.1, 0.1, 0.1, 0.1 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpEnabledSouth2North2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 0.1, 0.1, 0.1, 0.1, 0.1 ] ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"pumpEnabledWest2East2",
|
|
||||||
"directions":1,
|
|
||||||
"delays":[ [ 0.1, 0.1, 0.1, 0.1, 0.1 ] ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 281 B |
|
Before Width: | Height: | Size: 386 B |
|
Before Width: | Height: | Size: 896 B |
|
Before Width: | Height: | Size: 823 B |
|
Before Width: | Height: | Size: 408 B |
|
Before Width: | Height: | Size: 332 B |
|
Before Width: | Height: | Size: 320 B |
|
Before Width: | Height: | Size: 272 B |
@@ -0,0 +1 @@
|
|||||||
|
{"version": 1, "size": {"x": 32, "y": 32}, "license": "CC-BY-SA-3.0", "copyright": "Taken from https://github.com/tgstation/tgstation at commit 57cd1d59ca019dd0e7811ac451f295f818e573da", "states": [{"name": "pumpDigitalValve2", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpManualValve2", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPassiveGate2", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPassiveGate2On", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPressure2", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPressure2On", "directions": 4, "delays": [[0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1]]}, {"name": "pumpVolume2", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpVolume2On", "directions": 4, "delays": [[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]]}]}
|
||||||
|
After Width: | Height: | Size: 982 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
BIN
Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |