Filter sprites & visualizer (#3008)

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-17 09:10:22 -06:00
committed by GitHub
parent 9d5e85ba1e
commit e759a8aec9
17 changed files with 72 additions and 12 deletions

View File

@@ -0,0 +1,52 @@
#nullable enable
using Content.Shared.GameObjects.Components.Atmos;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
[UsedImplicitly]
public class GasFilterVisualizer : AppearanceVisualizer
{
private string _filterEnabledState = default!;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
var serializer = YamlObjectSerializer.NewReader(node);
serializer.DataField(ref _filterEnabledState, "filterEnabledState", "gasFilterOn");
}
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
if (!entity.TryGetComponent<ISpriteComponent>(out var sprite)) return;
sprite.LayerMapReserveBlank(Layer.FilterEnabled);
var filterEnabledLayer = sprite.LayerMapGet(Layer.FilterEnabled);
sprite.LayerSetState(filterEnabledLayer, _filterEnabledState);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent<ISpriteComponent>(out var sprite)) return;
if (!component.TryGetData(FilterVisuals.VisualState, out FilterVisualState filterVisualState)) return;
var filterEnabledLayer = sprite.LayerMapGet(Layer.FilterEnabled);
sprite.LayerSetVisible(filterEnabledLayer, filterVisualState.Enabled);
}
public enum Layer : byte
{
FilterEnabled,
}
}
}

View File

@@ -148,7 +148,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters
private void UpdateAppearance() private void UpdateAppearance()
{ {
_appearance?.SetData(FilterVisuals.VisualState, new FilterVisualState()); _appearance?.SetData(FilterVisuals.VisualState, new FilterVisualState(FilterEnabled));
} }
private void SetPipes() private void SetPipes()

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -12,6 +13,11 @@ namespace Content.Shared.GameObjects.Components.Atmos
[Serializable, NetSerializable] [Serializable, NetSerializable]
public class FilterVisualState public class FilterVisualState
{ {
public bool Enabled { get; }
public FilterVisualState(bool enabled)
{
Enabled = enabled;
}
} }
} }

View File

@@ -9,9 +9,6 @@
- type: Physics - type: Physics
- type: SnapGrid - type: SnapGrid
offset: Center offset: Center
- type: Sprite
sprite: Constructible/Atmos/pipeitems.rsi
state: scrubber
- type: Damageable - type: Damageable
resistances: metallicResistances resistances: metallicResistances
- type: Destructible - type: Destructible
@@ -28,11 +25,11 @@
description: It filters gases. description: It filters gases.
components: components:
- type: Sprite - type: Sprite
sprite: Constructible/Atmos/pipe.rsi sprite: Constructible/Atmos/gasfilter.rsi
state: pipeTJunction2 state: gasFilter
- type: Icon - type: Icon
sprite: Constructible/Atmos/pipe.rsi sprite: Constructible/Atmos/gasfilter.rsi
state: pipeTJunction2 state: gasFilter
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode - !type:PipeNode
@@ -48,3 +45,7 @@
inletDirection: South inletDirection: South
filterOutletDirection: East filterOutletDirection: East
outletDirection: North outletDirection: North
- type: Appearance
visuals:
- type: GasFilterVisualizer
filerEnabledState: gasFilterOn

View File

@@ -39,10 +39,10 @@
inletDirection: West inletDirection: West
outletDirection: East outletDirection: East
- type: Sprite - type: Sprite
state: pumpPressure2 state: pumpPressure
- type: Icon - type: Icon
state: pumpPressure2 state: pumpPressure
- type: Appearance - type: Appearance
visuals: visuals:
- type: PumpVisualizer - type: PumpVisualizer
pumpEnabledState: pumpPressure2On pumpEnabledState: pumpPressureOn

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -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": "gasFilter", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "gasFilterOn", "directions": 4, "delays": [[0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2]]}]}

View File

@@ -1 +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]]}]} {"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": "pumpDigitalValve", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpManualValve", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPassiveGate", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPassiveGateOn", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPressure", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpPressureOn", "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": "pumpVolume", "directions": 4, "delays": [[1.0], [1.0], [1.0], [1.0]]}, {"name": "pumpVolumeOn", "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]]}]}

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB