Add pipe coloring (#4261)
This commit is contained in:
committed by
GitHub
parent
6bbcf305bd
commit
077f158dda
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public abstract class EnabledAtmosDeviceVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("enabledState")]
|
||||
private string _enabledState = string.Empty;
|
||||
protected abstract object LayerMap { get; }
|
||||
protected abstract Enum DataKey { get; }
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (!entity.TryGetComponent(out ISpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
sprite.LayerMapSet(LayerMap, sprite.AddLayerState(_enabledState));
|
||||
sprite.LayerSetVisible(LayerMap, false);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
if(component.TryGetData(DataKey, out bool enabled))
|
||||
sprite.LayerSetVisible(LayerMap, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Client/Atmos/Visualizers/OutletInjectorVisualizer.cs
Normal file
18
Content.Client/Atmos/Visualizers/OutletInjectorVisualizer.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class OutletInjectorVisualizer : EnabledAtmosDeviceVisualizer
|
||||
{
|
||||
protected override object LayerMap => Layers.Enabled;
|
||||
protected override Enum DataKey => OutletInjectorVisuals.Enabled;
|
||||
|
||||
enum Layers
|
||||
{
|
||||
Enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Client/Atmos/Visualizers/PassiveVentVisualizer.cs
Normal file
18
Content.Client/Atmos/Visualizers/PassiveVentVisualizer.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class PassiveVentVisualizer : EnabledAtmosDeviceVisualizer
|
||||
{
|
||||
protected override object LayerMap => Layers.Enabled;
|
||||
protected override Enum DataKey => PassiveVentVisuals.Enabled;
|
||||
|
||||
enum Layers
|
||||
{
|
||||
Enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Content.Client/Atmos/Visualizers/PipeColorVisualizer.cs
Normal file
30
Content.Client/Atmos/Visualizers/PipeColorVisualizer.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class PipeColorVisualizer : AppearanceVisualizer
|
||||
{
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
if (component.TryGetData(PipeColorVisuals.Color, out Color color))
|
||||
{
|
||||
sprite.LayerSetColor(Layers.Pipe, color);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Layers : byte
|
||||
{
|
||||
Pipe,
|
||||
}
|
||||
}
|
||||
}
|
||||
92
Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs
Normal file
92
Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class PipeConnectorVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||
{
|
||||
[DataField("rsi")]
|
||||
private string _rsi = "Constructible/Atmos/pipe.rsi";
|
||||
|
||||
[DataField("baseState")]
|
||||
private string _baseState = "pipeConnector";
|
||||
|
||||
private RSI? _connectorRsi;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
var rsiString = SharedSpriteComponent.TextureRoot / _rsi;
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
|
||||
if (resourceCache.TryGetResource(rsiString, out RSIResource? rsi))
|
||||
_connectorRsi = rsi.RSI;
|
||||
else
|
||||
Logger.Error($"{nameof(PipeConnectorVisualizer)} could not load to load RSI {rsiString}.");
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (!entity.TryGetComponent<ISpriteComponent>(out var sprite))
|
||||
return;
|
||||
|
||||
if (_connectorRsi == null)
|
||||
return;
|
||||
|
||||
foreach (Layer layerKey in Enum.GetValues(typeof(Layer)))
|
||||
{
|
||||
sprite.LayerMapReserveBlank(layerKey);
|
||||
var layer = sprite.LayerMapGet(layerKey);
|
||||
sprite.LayerSetRSI(layer, _connectorRsi);
|
||||
var layerState = _baseState + ((PipeDirection) layerKey).ToString();
|
||||
sprite.LayerSetState(layer, layerState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent<ISpriteComponent>(out var sprite))
|
||||
return;
|
||||
|
||||
if (!component.TryGetData(PipeColorVisuals.Color, out Color color))
|
||||
color = Color.White;
|
||||
|
||||
if (!component.TryGetData(PipeVisuals.VisualState, out PipeVisualState state))
|
||||
return;
|
||||
|
||||
foreach (Layer layerKey in Enum.GetValues(typeof(Layer)))
|
||||
{
|
||||
var dir = (PipeDirection) layerKey;
|
||||
var layerVisible = state.ConnectedDirections.HasDirection(dir);
|
||||
|
||||
var layer = sprite.LayerMapGet(layerKey);
|
||||
sprite.LayerSetVisible(layer, layerVisible);
|
||||
sprite.LayerSetColor(layer, color);
|
||||
}
|
||||
}
|
||||
|
||||
private enum Layer : byte
|
||||
{
|
||||
NorthConnection = PipeDirection.North,
|
||||
SouthConnection = PipeDirection.South,
|
||||
EastConnection = PipeDirection.East,
|
||||
WestConnection = PipeDirection.West,
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Client/Atmos/Visualizers/PressurePumpVisualizer.cs
Normal file
18
Content.Client/Atmos/Visualizers/PressurePumpVisualizer.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class PressurePumpVisualizer : EnabledAtmosDeviceVisualizer
|
||||
{
|
||||
protected override object LayerMap => Layers.Enabled;
|
||||
protected override Enum DataKey => PressurePumpVisuals.Enabled;
|
||||
|
||||
enum Layers
|
||||
{
|
||||
Enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs
Normal file
51
Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.Atmos.Piping.Unary.Visuals;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ScrubberVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private string _offState = "scrub_off";
|
||||
private string _scrubState = "scrub_on";
|
||||
private string _siphonState = "scrub_purge";
|
||||
private string _weldedState = "scrub_welded";
|
||||
private string _wideState = "scrub_wide";
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
if (!component.TryGetData(ScrubberVisuals.State, out ScrubberState state))
|
||||
return;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ScrubberState.Off:
|
||||
sprite.LayerSetState(ScrubberVisualLayers.Scrubber, _offState);
|
||||
break;
|
||||
case ScrubberState.Scrub:
|
||||
sprite.LayerSetState(ScrubberVisualLayers.Scrubber, _scrubState);
|
||||
break;
|
||||
case ScrubberState.Siphon:
|
||||
sprite.LayerSetState(ScrubberVisualLayers.Scrubber, _siphonState);
|
||||
break;
|
||||
case ScrubberState.Welded:
|
||||
sprite.LayerSetState(ScrubberVisualLayers.Scrubber, _weldedState);
|
||||
break;
|
||||
case ScrubberState.WideScrub:
|
||||
sprite.LayerSetState(ScrubberVisualLayers.Scrubber, _wideState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ScrubberVisualLayers
|
||||
{
|
||||
Scrubber,
|
||||
}
|
||||
}
|
||||
18
Content.Client/Atmos/Visualizers/ThermoMachineVisualizer.cs
Normal file
18
Content.Client/Atmos/Visualizers/ThermoMachineVisualizer.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ThermoMachineVisualizer : EnabledAtmosDeviceVisualizer
|
||||
{
|
||||
protected override object LayerMap => Layers.Enabled;
|
||||
protected override Enum DataKey => ThermoMachineVisuals.Enabled;
|
||||
|
||||
enum Layers
|
||||
{
|
||||
Enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs
Normal file
47
Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Content.Shared.Atmos.Visuals;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Atmos.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class VentPumpVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private string _offState = "vent_off";
|
||||
private string _inState = "vent_in";
|
||||
private string _outState = "vent_out";
|
||||
private string _weldedState = "vent_welded";
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
if (!component.TryGetData(VentPumpVisuals.State, out VentPumpState state))
|
||||
return;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case VentPumpState.Off:
|
||||
sprite.LayerSetState(VentVisualLayers.Vent, _offState);
|
||||
break;
|
||||
case VentPumpState.In:
|
||||
sprite.LayerSetState(VentVisualLayers.Vent, _inState);
|
||||
break;
|
||||
case VentPumpState.Out:
|
||||
sprite.LayerSetState(VentVisualLayers.Vent, _outState);
|
||||
break;
|
||||
case VentPumpState.Welded:
|
||||
sprite.LayerSetState(VentVisualLayers.Vent, _weldedState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VentVisualLayers
|
||||
{
|
||||
Vent,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user