Skip to content

Commit

Permalink
visually connect to different layers
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Jan 6, 2025
1 parent 4f823d2 commit a985b93
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4584c35d672b8a74797cc5efa123ce16, type: 3}
m_Name: AtmosFilterRSo
m_EditorClassIdentifier:
prefab: {fileID: 5199170345094387172, guid: 420c8757d9e32fa43bee79d6c980fd19, type: 3}
icon: {fileID: 0}
layer: 11
genericType: 1
specificType: 0
width: 1
height: 1
isLarge: 0
_prefab: {fileID: 5199170345094387172, guid: 420c8757d9e32fa43bee79d6c980fd19, type: 3}
_icon: {fileID: 0}
_layer: 1
_genericType: 1
_specificType: 0
_width: 1
_height: 1
_isLarge: 0
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ public class AtmosTrinaryDeviceAdjacencyConnector : NetworkActor, IAdjacencyConn
/// </summary>
private bool _initialized;

public AdjacencyMap Connections => _pipeLayerConnections;

public bool UpdateSingleConnection(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
{
Setup();

bool isConnected = IsConnected(neighbourObject);
bool isUpdated = _pipeLayerConnections.SetConnection(dir, isConnected);

if (isUpdated && neighbourObject)
if (isUpdated && neighbourObject && updateNeighbour)
{
neighbourObject.UpdateSingleAdjacency(TileHelper.GetOpposite(dir), _placedObject, false);
}
Expand Down Expand Up @@ -73,11 +75,9 @@ public bool IsConnected(PlacedTileObject neighbourObject)
|| neighbourObject.WorldOrigin == GetComponent<PlacedTileObject>().WorldOrigin - twoDForward
|| neighbourObject.WorldOrigin == GetComponent<PlacedTileObject>().WorldOrigin + twoDRight;

// Only connect to pipes of the same layer as the set up trinary device layer
if (neighbourObject.TryGetComponent(out PipeAdjacencyConnector neighbourConnector))
{
isConnected &= GetComponent<TrinaryAtmosDevice>().PipeLayer == neighbourObject.Layer;
}
// Only connect if not already connected to something else.
isConnected &= _placedObject.NeighbourAtDirectionOf(neighbourObject, out Direction neighbourDirection)
&& !_pipeLayerConnections.HasConnection(neighbourDirection);

return isConnected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public bool UpdateSingleConnection(Direction dir, PlacedTileObject neighbourObje

if (isUpdated)
{
if (neighbourObject)
if (neighbourObject && updateNeighbour)
{
neighbourObject.UpdateSingleAdjacency(TileHelper.GetOpposite(dir), _placedObject, false);
}
Expand Down Expand Up @@ -128,8 +128,9 @@ public bool IsConnected(PlacedTileObject neighbourObject)
isConnected &= valve.IsOpen;
}

if (neighbourObject.TryGetComponent(out TrinaryAtmosDevice filter))
if (neighbourObject.TryGetComponent(out AtmosTrinaryDeviceAdjacencyConnector filter))
{
// This pipe connects to TrinaryAtmosDevice only if it's placed behind, in front or on one of its side
isConnected &= tileObject.WorldOrigin == neighbourObject.WorldOrigin + neighbourObjectTwoDForward
|| tileObject.WorldOrigin == neighbourObject.WorldOrigin - neighbourObjectTwoDForward
|| tileObject.WorldOrigin == neighbourObject.WorldOrigin + neighbourObjectTwoDRight;
Expand All @@ -140,11 +141,14 @@ public bool IsConnected(PlacedTileObject neighbourObject)
// Can't connect if connected to more than one other pipe
isConnected &= _pipeLayerConnections.ConnectionCount <= 1;

// If connected to one pipe already, connect only if this pipe is opposite to the machinery.
// If connected to one pipe already, connect only if the neighbour pipe is opposite to the machinery.
if (_pipeLayerConnections.ConnectionCount == 1)
{
isConnected &= _pipeLayerConnections.GetSingleConnection() == TileHelper.GetOpposite(neighbourDirection);
}

// If the device is already connected does not connect
isConnected &= !filter.Connections.HasConnection(TileHelper.GetOpposite(neighbourDirection));
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public bool TryGetAtmosPipe(Vector3 worldPosition, TileLayer layer, out IAtmosPi
atmosPipe = null;
SingleTileLocation tileLocation = Subsystems.Get<TileSystem>().CurrentMap.GetTileLocation(layer, worldPosition) as SingleTileLocation;

if (!tileLocation.TryGetPlacedObject(out PlacedTileObject placedTileObject))
if (tileLocation == null || !tileLocation.TryGetPlacedObject(out PlacedTileObject placedTileObject))
{
return false;
}
Expand Down

0 comments on commit a985b93

Please sign in to comment.