diff --git a/Content.Client/GameObjects/Components/Atmos/PumpVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/PumpVisualizer.cs index 26e86403e5..04247bdae6 100644 --- a/Content.Client/GameObjects/Components/Atmos/PumpVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/PumpVisualizer.cs @@ -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 - { - var resourceCache = IoCManager.Resolve(); - var resource = resourceCache.GetResource(rsiPath); - _pumpRSI = resource.RSI; - } - catch (Exception e) - { - Logger.ErrorS("go.pumpvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e); - } + public override void InitializeEntity(IEntity entity) + { + 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, } } diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs index 37e08ad5e0..d3521e9c8a 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs @@ -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; /// /// Needs to be same as that of a 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(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(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)); } } } diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs index e2c3aa4f32..f1063a01da 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs @@ -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 GetReachableNodes() diff --git a/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs b/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs index b8e3955d69..4d0b5ffce8 100644 --- a/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs +++ b/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs @@ -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; + } } } diff --git a/Resources/Prototypes/Entities/Constructible/Ground/pumps.yml b/Resources/Prototypes/Entities/Constructible/Ground/pumps.yml index 921f9d0263..047ad284fb 100644 --- a/Resources/Prototypes/Entities/Constructible/Ground/pumps.yml +++ b/Resources/Prototypes/Entities/Constructible/Ground/pumps.yml @@ -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 diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/meta.json b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/meta.json deleted file mode 100644 index d8390a7ef9..0000000000 --- a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/meta.json +++ /dev/null @@ -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 ] ] - } - ] -} \ No newline at end of file diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEast2West2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEast2West2.png deleted file mode 100644 index dc07973864..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEast2West2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledEast2West2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledEast2West2.png deleted file mode 100644 index 4e2d4e1a78..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledEast2West2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledNorth2South2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledNorth2South2.png deleted file mode 100644 index 6e33ce9160..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledNorth2South2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledSouth2North2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledSouth2North2.png deleted file mode 100644 index fffb200483..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledSouth2North2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledWest2East2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledWest2East2.png deleted file mode 100644 index ddcd2cd54d..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpEnabledWest2East2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpNorth2South2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpNorth2South2.png deleted file mode 100644 index 3f26d407ea..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpNorth2South2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpSouth2North2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpSouth2North2.png deleted file mode 100644 index d805b9df59..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpSouth2North2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpWest2East2.png b/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpWest2East2.png deleted file mode 100644 index 789ad70f39..0000000000 Binary files a/Resources/Textures/Constructible/Atmos/pressurepump.rsi/pumpWest2East2.png and /dev/null differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/meta.json b/Resources/Textures/Constructible/Atmos/pump.rsi/meta.json new file mode 100644 index 0000000000..eafa97cacb --- /dev/null +++ b/Resources/Textures/Constructible/Atmos/pump.rsi/meta.json @@ -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]]}]} \ No newline at end of file diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpDigitalValve2.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpDigitalValve2.png new file mode 100644 index 0000000000..c589a32521 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpDigitalValve2.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpManualValve2.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpManualValve2.png new file mode 100644 index 0000000000..b1093f7547 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpManualValve2.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2.png new file mode 100644 index 0000000000..92f782a56b Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2On.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2On.png new file mode 100644 index 0000000000..88023ac083 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPassiveGate2On.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2.png new file mode 100644 index 0000000000..7401c6bfd2 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2On.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2On.png new file mode 100644 index 0000000000..bd880ff51f Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpPressure2On.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2.png new file mode 100644 index 0000000000..9612cc03b3 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2.png differ diff --git a/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2On.png b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2On.png new file mode 100644 index 0000000000..46f58e2e65 Binary files /dev/null and b/Resources/Textures/Constructible/Atmos/pump.rsi/pumpVolume2On.png differ