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 Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects.Components.Renderable;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
@@ -17,68 +11,38 @@ namespace Content.Client.GameObjects.Components.Atmos
|
||||
[UsedImplicitly]
|
||||
public class PumpVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private RSI _pumpRSI;
|
||||
private string _pumpEnabledState;
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
_pumpEnabledState = node.GetNode("pumpEnabledState").ToString();
|
||||
}
|
||||
|
||||
var rsiString = node.GetNode("pumpRSI").ToString();
|
||||
var rsiPath = SharedSpriteComponent.TextureRoot / rsiString;
|
||||
try
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
var resource = resourceCache.GetResource<RSIResource>(rsiPath);
|
||||
_pumpRSI = resource.RSI;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("go.pumpvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
|
||||
}
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (!entity.TryGetComponent(out ISpriteComponent sprite)) return;
|
||||
|
||||
sprite.LayerMapReserveBlank(Layer.PumpEnabled);
|
||||
var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled);
|
||||
sprite.LayerSetState(pumpEnabledLayer, _pumpEnabledState);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
|
||||
{
|
||||
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();
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return;
|
||||
if (!component.TryGetData(PumpVisuals.VisualState, out PumpVisualState pumpVisualState)) return;
|
||||
|
||||
sprite.LayerMapReserveBlank(Layer.PumpBase);
|
||||
var basePumpLayer = sprite.LayerMapGet(Layer.PumpBase);
|
||||
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);
|
||||
var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled);
|
||||
sprite.LayerSetVisible(pumpEnabledLayer, pumpVisualState.PumpEnabled);
|
||||
}
|
||||
|
||||
private enum Layer
|
||||
public enum Layer
|
||||
{
|
||||
PumpBase,
|
||||
PumpEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.NodeContainer;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||
using Content.Shared.GameObjects.Components.Atmos;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -28,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
|
||||
UpdateAppearance();
|
||||
}
|
||||
}
|
||||
private bool _pumpEnabled = true;
|
||||
private bool _pumpEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
serializer.DataField(ref _inletDirection, "inletDirection", PipeDirection.None);
|
||||
serializer.DataField(ref _outletDirection, "outletDirection", PipeDirection.None);
|
||||
serializer.DataField(ref _pumpEnabled, "pumpEnabled", false);
|
||||
}
|
||||
|
||||
public override void 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))
|
||||
{
|
||||
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)}.");
|
||||
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)
|
||||
{
|
||||
var diff = ev.NewRotation - ev.OldRotation;
|
||||
var newPipeDir = PipeDirection.None;
|
||||
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;
|
||||
PipeDirection = PipeDirection.RotatePipeDirection(diff);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Node> GetReachableNodes()
|
||||
|
||||
@@ -144,5 +144,19 @@ namespace Content.Shared.GameObjects.Components.Atmos
|
||||
_ => 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: SnapGrid
|
||||
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
|
||||
thresholdvalue: 100
|
||||
resistances: metallicResistances
|
||||
- type: Sprite
|
||||
sprite: Constructible/Atmos/pump.rsi
|
||||
- type: Icon
|
||||
sprite: Constructible/Atmos/pump.rsi
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
parent: PumpBase
|
||||
id: NorthwardLongitudinalPump
|
||||
id: DebugPressurePump
|
||||
name: Debug Pressure Pump
|
||||
components:
|
||||
- type: NodeContainer
|
||||
nodes:
|
||||
- !type:PipeNode
|
||||
nodeGroupID: Pipe
|
||||
pipeDirection: South
|
||||
pipeDirection: West
|
||||
- !type:PipeNode
|
||||
nodeGroupID: Pipe
|
||||
pipeDirection: North
|
||||
|
||||
- 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:
|
||||
pipeDirection: East
|
||||
- type: PressurePump
|
||||
inletDirection: South
|
||||
outletDirection: North
|
||||
inletDirection: West
|
||||
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 |