Siphon and Vent Visualizers (#2062)

* scrubber sprites

* vent sprites

* Vent visualstate

* scrubber visual state

* Vent and siphon respect being disabled

* Vent and Siphon Visualizer

* Fix typo

Co-authored-by: py01 <pyronetics01@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
py01
2020-09-12 06:26:50 -06:00
committed by GitHub
parent 595ec5c034
commit b288975cb7
14 changed files with 320 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
using Content.Shared.GameObjects.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.Utility;
using System;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
[UsedImplicitly]
public class SiphonVisualizer : AppearanceVisualizer
{
private RSI _siphonRSI;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
var rsiString = node.GetNode("siphonRSI").ToString();
var rsiPath = SharedSpriteComponent.TextureRoot / rsiString;
try
{
var resourceCache = IoCManager.Resolve<IResourceCache>();
var resource = resourceCache.GetResource<RSIResource>(rsiPath);
_siphonRSI = resource.RSI;
}
catch (Exception e)
{
Logger.ErrorS("go.siphonvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
{
return;
}
if (!component.TryGetData(SiphonVisuals.VisualState, out SiphonVisualState siphonVisualState))
{
return;
}
var siphonBaseState = "scrub";
siphonBaseState += siphonVisualState.SiphonEnabled ? "On" : "Off";
sprite.LayerMapReserveBlank(Layer.SiphonBase);
var baseSiphonLayer = sprite.LayerMapGet(Layer.SiphonBase);
sprite.LayerSetRSI(baseSiphonLayer, _siphonRSI);
sprite.LayerSetState(baseSiphonLayer, siphonBaseState);
sprite.LayerSetVisible(baseSiphonLayer, true);
}
private enum Layer
{
SiphonBase,
}
}
}

View File

@@ -0,0 +1,68 @@
using Content.Shared.GameObjects.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.Utility;
using System;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
[UsedImplicitly]
public class VentVisualizer : AppearanceVisualizer
{
private RSI _ventRSI;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
var rsiString = node.GetNode("ventRSI").ToString();
var rsiPath = SharedSpriteComponent.TextureRoot / rsiString;
try
{
var resourceCache = IoCManager.Resolve<IResourceCache>();
var resource = resourceCache.GetResource<RSIResource>(rsiPath);
_ventRSI = resource.RSI;
}
catch (Exception e)
{
Logger.ErrorS("go.ventvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
{
return;
}
if (!component.TryGetData(VentVisuals.VisualState, out VentVisualState ventVisualState))
{
return;
}
var ventBaseState = "vent";
ventBaseState += ventVisualState.VentEnabled ? "On" : "Off";
sprite.LayerMapReserveBlank(Layer.VentBase);
var baseVentLayer = sprite.LayerMapGet(Layer.VentBase);
sprite.LayerSetRSI(baseVentLayer, _ventRSI);
sprite.LayerSetState(baseVentLayer, ventBaseState);
sprite.LayerSetVisible(baseVentLayer, true);
}
private enum Layer
{
VentBase,
}
}
}

View File

@@ -2,6 +2,8 @@
using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -23,6 +25,20 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
private AtmosphereSystem _atmosSystem; private AtmosphereSystem _atmosSystem;
[ViewVariables(VVAccess.ReadWrite)]
public bool SiphonEnabled
{
get => _siphonEnabled;
set
{
_siphonEnabled = value;
UpdateAppearance();
}
}
private bool _siphonEnabled = true;
private AppearanceComponent _appearance;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -40,10 +56,15 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
Logger.Error($"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{typeof(BaseSiphonComponent)} 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() public override void Update()
{ {
if (!SiphonEnabled)
return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(_entityManager); var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(_entityManager);
if (tileAtmos == null) if (tileAtmos == null)
return; return;
@@ -52,5 +73,10 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
} }
protected abstract void ScrubGas(GasMixture inletGas, GasMixture outletGas); protected abstract void ScrubGas(GasMixture inletGas, GasMixture outletGas);
private void UpdateAppearance()
{
_appearance?.SetData(SiphonVisuals.VisualState, new SiphonVisualState(SiphonEnabled));
}
} }
} }

View File

@@ -2,6 +2,8 @@
using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -23,6 +25,20 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
private AtmosphereSystem _atmosSystem; private AtmosphereSystem _atmosSystem;
[ViewVariables(VVAccess.ReadWrite)]
public bool VentEnabled
{
get => _ventEnabled;
set
{
_ventEnabled = value;
UpdateAppearance();
}
}
private bool _ventEnabled = true;
private AppearanceComponent _appearance;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -40,10 +56,15 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
Logger.Error($"{typeof(BaseVentComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{typeof(BaseVentComponent)} 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() public override void Update()
{ {
if (!VentEnabled)
return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(_entityManager); var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(_entityManager);
if (tileAtmos == null) if (tileAtmos == null)
return; return;
@@ -52,5 +73,10 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
} }
protected abstract void VentGas(GasMixture inletGas, GasMixture outletGas); protected abstract void VentGas(GasMixture inletGas, GasMixture outletGas);
private void UpdateAppearance()
{
_appearance?.SetData(VentVisuals.VisualState, new VentVisualState(VentEnabled));
}
} }
} }

View File

@@ -0,0 +1,22 @@
using Robust.Shared.Serialization;
using System;
namespace Content.Shared.GameObjects.Atmos
{
[Serializable, NetSerializable]
public enum SiphonVisuals
{
VisualState
}
[Serializable, NetSerializable]
public class SiphonVisualState
{
public readonly bool SiphonEnabled;
public SiphonVisualState(bool siphonEnabled)
{
SiphonEnabled = siphonEnabled;
}
}
}

View File

@@ -0,0 +1,22 @@
using Robust.Shared.Serialization;
using System;
namespace Content.Shared.GameObjects.Atmos
{
[Serializable, NetSerializable]
public enum VentVisuals
{
VisualState
}
[Serializable, NetSerializable]
public class VentVisualState
{
public readonly bool VentEnabled;
public VentVisualState(bool ventEnabled)
{
VentEnabled = ventEnabled;
}
}
}

View File

@@ -12,7 +12,12 @@
- type: Icon - type: Icon
texture: Constructible/Power/eightdirwire.png texture: Constructible/Power/eightdirwire.png
- type: Sprite - type: Sprite
texture: Constructible/Power/eightdirwire.png - type: Appearance
visuals:
- type: PipeVisualizer
pipeRSI: Constructible/Atmos/pipe.rsi
- type: SiphonVisualizer
siphonRSI: Constructible/Atmos/scrubber.rsi
- type: Destructible - type: Destructible
thresholdvalue: 100 thresholdvalue: 100

View File

@@ -12,7 +12,12 @@
- type: Icon - type: Icon
texture: Constructible/Power/eightdirwire.png texture: Constructible/Power/eightdirwire.png
- type: Sprite - type: Sprite
texture: Constructible/Power/eightdirwire.png - type: Appearance
visuals:
- type: PipeVisualizer
pipeRSI: Constructible/Atmos/pipe.rsi
- type: VentVisualizer
ventRSI: Constructible/Atmos/vent.rsi
- type: Destructible - type: Destructible
thresholdvalue: 100 thresholdvalue: 100

View File

@@ -0,0 +1,48 @@
{
"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":"scrubOff",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"scrubOn",
"directions":1,
"delays":[
[
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08,
0.08
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -0,0 +1,28 @@
{
"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":"ventOff",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"ventOn",
"directions":1,
"delays":[
[
0.08,
0.08,
0.08,
0.08
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB