Files
tbd-station-14/Content.Server/GameObjects/Components/Atmos/Piping/GasCanisterPortComponent.cs
20kdc 58af9003e7 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 20:45:24 +01:00

79 lines
2.7 KiB
C#

using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
[RegisterComponent]
public class GasCanisterPortComponent : PipeNetDeviceComponent
{
public override string Name => "GasCanisterPort";
[ViewVariables]
public GasCanisterComponent ConnectedCanister { get; private set; }
[ViewVariables]
public bool ConnectedToCanister => ConnectedCanister != null;
[ViewVariables]
private PipeNode _gasPort;
public override void Initialize()
{
base.Initialize();
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(GasCanisterPortComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
_gasPort = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_gasPort == null)
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(GasCanisterPortComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
if (Owner.TryGetComponent<SnapGridComponent>(out var snapGrid))
{
var anchoredCanister = snapGrid.GetLocal()
.Select(entity => entity.TryGetComponent<GasCanisterComponent>(out var canister) ? canister : null)
.Where(canister => canister != null)
.Where(canister => canister.Anchored)
.Where(canister => !canister.ConnectedToPort)
.FirstOrDefault();
if (anchoredCanister != null)
{
anchoredCanister.TryConnectToPort();
}
}
}
public override void OnRemove()
{
base.OnRemove();
ConnectedCanister?.DisconnectFromPort();
}
public override void Update()
{
ConnectedCanister?.Air.Share(_gasPort.Air, 1);
ConnectedCanister?.AirWasUpdated();
}
public void ConnectGasCanister(GasCanisterComponent gasCanister)
{
ConnectedCanister = gasCanister;
}
public void DisconnectGasCanister()
{
ConnectedCanister = null;
}
}
}