Files
crystall-punk-14/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs

73 lines
2.4 KiB
C#
Raw Normal View History

Canisters [ Continuation of clement-or #2544 ] (#2628) * Added atmos sprites from CEV-Eris * Moved canister sprites to appropriate dir * Removed unnecessary sprites, edited canisters prototype * Created Gas Canister UI and release pressure buttons * Changed GasMixture's pressure calculation (convert liters to cube meters) * Added relabeling Canisters * Reverted changes on GasMixture * Changed my name in the credits * Added valve opening on canisters * Change canister visual state when connected to a port * Added nullable to SharedGasCanisterComponent * Replaced nullable contexts * Changed again nullable annotation context * Moved name in the credits to correct alphabetical order * Canisters: Fix the most blatant issues with this PR (the added project interdependencies for no reason whatsoever) * Canisters: Stop crashes when canisters leave atmosphere * Canisters: Gas released into no atmosphere gets transferred "into space" (deleted) * Atmos: Nullability annotations on TileAtmosphere, explaination of the states of TileAtmosphere.Air * Canisters: If in an airblocked tile, do NOT release gas * Scrubbers: Fix typo leading to them not connecting properly. * Revert manual changes to credits file (sorry!) (1/2) This reverts commit 94f3b0e5df8d9c2fa189866a17a231920f99bdaf. * Revert manual changes to credits file (sorry!) (2/2) This reverts commit 1986fb094dfaa44060f08d280f36b755258d17a6. * Canisters: Apply @Zumorica 's reviews * Canisters: Add missing localization as suggested by PJB Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com> * Canisters: Pressure lights! * Canisters: Light is now unshaded. * Canisters: Now using IActivate * Gas canisters (& air canister), now with their numbers properly calibrated (hopefully) * Canisters: Refactor how their layers are added to be more like ApcVisualizer * Canisters: Clean up of the tile invalidation/air release logic * Canisters: Some gas canister window improvements * Canisters: Clean up release pressure change button label code Co-authored-by: Clement-O <topy72.mine@gmail.com> Co-authored-by: Clément <clement.orlandini@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
2020-12-08 19:45:24 +00:00
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
public class GasCanisterVisualizer : AppearanceVisualizer
{
private string _stateConnected;
private string[] _statePressure = new string[] {"", "", "", ""};
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
_stateConnected = node.GetNode("stateConnected").AsString();
for (int i = 0; i < _statePressure.Length; i++)
_statePressure[i] = node.GetNode("stateO" + i).AsString();
}
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
var sprite = entity.GetComponent<ISpriteComponent>();
sprite.LayerMapSet(Layers.ConnectedToPort, sprite.AddLayerState(_stateConnected));
sprite.LayerSetVisible(Layers.ConnectedToPort, false);
sprite.LayerMapSet(Layers.PressureLight, sprite.AddLayerState(_stateConnected));
sprite.LayerSetShader(Layers.PressureLight, "unshaded");
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.Deleted)
{
return;
}
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
{
return;
}
// Update the visuals : Is the canister connected to a port or not
if (component.TryGetData(GasCanisterVisuals.ConnectedState, out bool isConnected))
{
sprite.LayerSetVisible(Layers.ConnectedToPort, isConnected);
}
// Update the visuals : Canister lights
if (component.TryGetData(GasCanisterVisuals.PressureState, out int pressureState))
if ((pressureState >= 0) && (pressureState < _statePressure.Length))
sprite.LayerSetState(Layers.PressureLight, _statePressure[pressureState]);
}
enum Layers
{
ConnectedToPort,
PressureLight
}
}
}