diff --git a/Assets/Scripts/SS3D/Systems/Tile/Connections/AdvancedAdjacencyConnector.cs b/Assets/Scripts/SS3D/Systems/Tile/Connections/AdvancedAdjacencyConnector.cs
index fa74ce242d..7af9443c62 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/Connections/AdvancedAdjacencyConnector.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/Connections/AdvancedAdjacencyConnector.cs
@@ -64,22 +64,15 @@ private void Setup()
}
}
- public bool UpdateSingle(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
+ public bool UpdateSingleConnection(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
{
Setup();
- bool isConnected = false;
- bool isUpdated = false;
+ bool isConnected = IsConnected(dir, neighbourObject);
+ bool isUpdated;
- if (neighbourObject)
- {
- isConnected = (neighbourObject && neighbourObject.HasAdjacencyConnector);
- isConnected &= neighbourObject.GenericType == _genericType || _genericType == TileObjectGenericType.None;
- isConnected &= neighbourObject.SpecificType == _specificType || _specificType == TileObjectSpecificType.None;
-
- // Update our neighbour as well
- if (isConnected && updateNeighbour)
- neighbourObject.UpdateSingleAdjacency(_placedObject, TileHelper.GetOpposite(dir));
- }
+ // Update our neighbour as well
+ if (isConnected && updateNeighbour)
+ neighbourObject.UpdateSingleAdjacency(_placedObject, TileHelper.GetOpposite(dir));
isUpdated = _adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
if (isUpdated)
@@ -91,14 +84,26 @@ public bool UpdateSingle(Direction dir, PlacedTileObject neighbourObject, bool u
return isUpdated;
}
- public void UpdateAll(PlacedTileObject[] neighbourObjects)
+ public bool IsConnected(Direction dir, PlacedTileObject neighbourObject)
+ {
+ bool isConnected = false;
+ if (neighbourObject)
+ {
+ isConnected = (neighbourObject && neighbourObject.HasAdjacencyConnector);
+ isConnected &= neighbourObject.GenericType == _genericType || _genericType == TileObjectGenericType.None;
+ isConnected &= neighbourObject.SpecificType == _specificType || _specificType == TileObjectSpecificType.None;
+ }
+ return isConnected;
+ }
+
+ public void UpdateAllConnections(PlacedTileObject[] neighbourObjects)
{
Setup();
bool changed = false;
for (int i = 0; i < neighbourObjects.Length; i++)
{
- changed |= UpdateSingle((Direction)i, neighbourObjects[i], true);
+ changed |= UpdateSingleConnection((Direction)i, neighbourObjects[i], true);
}
if (changed)
diff --git a/Assets/Scripts/SS3D/Systems/Tile/Connections/DoorAdjacencyConnector.cs b/Assets/Scripts/SS3D/Systems/Tile/Connections/DoorAdjacencyConnector.cs
index 05899e16b5..540a0b2171 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/Connections/DoorAdjacencyConnector.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/Connections/DoorAdjacencyConnector.cs
@@ -65,17 +65,20 @@ public void CleanAdjacencies()
}
}
- public bool UpdateSingle(Direction direction, PlacedTileObject placedObject, bool updateNeighbours)
+ public bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject, bool updateNeighbours)
{
Setup();
- if (UpdateSingleConnection(direction, placedObject))
+
+ bool isConnected = IsConnected(direction, placedObject);
+ bool update = adjacencyMap.SetConnection(direction, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
+
+ if (update)
UpdateWallCaps();
- // TODO should check if connection was actually updated.
return true;
}
- public void UpdateAll(PlacedTileObject[] neighbourObjects)
+ public void UpdateAllConnections(PlacedTileObject[] neighbourObjects)
{
Setup();
if (!map)
@@ -88,7 +91,7 @@ public void UpdateAll(PlacedTileObject[] neighbourObjects)
for (int i = 0; i < neighbourObjects.Length; i++)
{
bool updatedSingle = false;
- updatedSingle = UpdateSingleConnection((Direction)i, neighbourObjects[i]);
+ updatedSingle = UpdateSingleConnection((Direction)i, neighbourObjects[i], true);
if (updatedSingle && neighbourObjects[i])
neighbourObjects[i].UpdateSingleAdjacency(currentObject, TileHelper.GetOpposite((Direction)i));
@@ -101,18 +104,6 @@ public void UpdateAll(PlacedTileObject[] neighbourObjects)
}
}
- ///
- /// Adjusts the connections value based on the given new tile.
- ///
- /// Returns whether value changed.
- private bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject)
- {
- bool isConnected = (placedObject && placedObject.HasAdjacencyConnector &&
- placedObject.GenericType == TileObjectGenericType.Wall);
-
- return adjacencyMap.SetConnection(direction, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
- }
-
private void CreateWallCaps(bool isPresent, Direction direction)
{
int capIndex = TileHelper.GetDirectionIndex(direction);
@@ -172,6 +163,12 @@ private Direction GetDoorDirection()
return placedTileObject.Direction;
}
+
+ public bool IsConnected(Direction dir, PlacedTileObject neighbourObject)
+ {
+ return (neighbourObject && neighbourObject.HasAdjacencyConnector &&
+ neighbourObject.GenericType == TileObjectGenericType.Wall);
+ }
}
}
diff --git a/Assets/Scripts/SS3D/Systems/Tile/Connections/IAdjacencyConnector.cs b/Assets/Scripts/SS3D/Systems/Tile/Connections/IAdjacencyConnector.cs
index 6087d291f4..2e98df709e 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/Connections/IAdjacencyConnector.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/Connections/IAdjacencyConnector.cs
@@ -5,7 +5,8 @@
///
public interface IAdjacencyConnector
{
- bool UpdateSingle(Direction direction, PlacedTileObject neighbourObject, bool updateNeighbour);
- void UpdateAll(PlacedTileObject[] neighbourObjects);
+ bool UpdateSingleConnection(Direction direction, PlacedTileObject neighbourObject, bool updateNeighbour);
+ void UpdateAllConnections(PlacedTileObject[] neighbourObjects);
+ bool IsConnected(Direction dir, PlacedTileObject neighbourObject);
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/SS3D/Systems/Tile/Connections/SimpleAdjacencyConnector.cs b/Assets/Scripts/SS3D/Systems/Tile/Connections/SimpleAdjacencyConnector.cs
index 7695dc4438..8e3fb31a6d 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/Connections/SimpleAdjacencyConnector.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/Connections/SimpleAdjacencyConnector.cs
@@ -78,20 +78,15 @@ private void SyncAdjacencies(byte oldValue, byte newValue, bool asServer)
}
}
- public bool UpdateSingle(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
+ public bool UpdateSingleConnection(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
{
- bool isConnected = false;
+ Setup();
- if (neighbourObject != null)
- {
- isConnected = (neighbourObject && neighbourObject.HasAdjacencyConnector);
- isConnected &= neighbourObject.GenericType == _genericType || _genericType == TileObjectGenericType.None;
- isConnected &= neighbourObject.SpecificType == _specificType || _specificType == TileObjectSpecificType.None;
+ bool isConnected = IsConnected(dir, neighbourObject);
- // Update our neighbour as well
- if (isConnected && updateNeighbour)
- neighbourObject.UpdateSingleAdjacency(_placedObject, TileHelper.GetOpposite(dir));
- }
+ // Update our neighbour as well
+ if (isConnected && updateNeighbour)
+ neighbourObject.UpdateSingleAdjacency(_placedObject, TileHelper.GetOpposite(dir));
bool isUpdated = _adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
@@ -123,14 +118,14 @@ private void UpdateMeshAndDirection()
transform.localRotation = localRotation;
}
- public void UpdateAll(PlacedTileObject[] neighbourObjects)
+ public void UpdateAllConnections(PlacedTileObject[] neighbourObjects)
{
Setup();
bool changed = false;
for (int i = 0; i < neighbourObjects.Length; i++)
{
- changed |= UpdateSingle((Direction)i, neighbourObjects[i], true);
+ changed |= UpdateSingleConnection((Direction)i, neighbourObjects[i], true);
}
if (changed)
@@ -138,5 +133,17 @@ public void UpdateAll(PlacedTileObject[] neighbourObjects)
UpdateMeshAndDirection();
}
}
+
+ public bool IsConnected(Direction dir, PlacedTileObject neighbourObject)
+ {
+ bool isConnected = false;
+ if (neighbourObject != null)
+ {
+ isConnected = (neighbourObject && neighbourObject.HasAdjacencyConnector);
+ isConnected &= neighbourObject.GenericType == _genericType || _genericType == TileObjectGenericType.None;
+ isConnected &= neighbourObject.SpecificType == _specificType || _specificType == TileObjectSpecificType.None;
+ }
+ return isConnected;
+ }
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/SS3D/Systems/Tile/Connections/WallAdjacencyConnector.cs b/Assets/Scripts/SS3D/Systems/Tile/Connections/WallAdjacencyConnector.cs
index b31e774f01..2801732ee1 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/Connections/WallAdjacencyConnector.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/Connections/WallAdjacencyConnector.cs
@@ -65,10 +65,10 @@ private void Setup()
}
}
- public bool UpdateSingle(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
+ public bool UpdateSingleConnection(Direction dir, PlacedTileObject neighbourObject, bool updateNeighbour)
{
Setup();
- bool isConnected = false;
+ bool isConnected = IsConnected(dir, neighbourObject);
bool isUpdated = false;
if (neighbourObject != null)
@@ -98,14 +98,14 @@ public bool UpdateSingle(Direction dir, PlacedTileObject neighbourObject, bool u
return isUpdated;
}
- public void UpdateAll(PlacedTileObject[] neighbourObjects)
+ public void UpdateAllConnections(PlacedTileObject[] neighbourObjects)
{
Setup();
bool changed = false;
for (int i = 0; i < neighbourObjects.Length; i++)
{
- changed |= UpdateSingle((Direction)i, neighbourObjects[i], true);
+ changed |= UpdateSingleConnection((Direction)i, neighbourObjects[i], true);
}
if (changed)
@@ -157,7 +157,6 @@ public void SetBlockedDirection(Direction dir, bool value)
private bool IsConnectedToDoor(PlacedTileObject neighbourObject)
{
- bool isConnected = false;
var doorConnector = neighbourObject.GetComponent();
var door = doorConnector.placedTileObject;
if (door != null)
@@ -168,5 +167,22 @@ private bool IsConnectedToDoor(PlacedTileObject neighbourObject)
return false;
}
+
+ public bool IsConnected(Direction dir, PlacedTileObject neighbourObject)
+ {
+ if(neighbourObject == null) return false;
+
+ bool isConnected = (neighbourObject.HasAdjacencyConnector);
+
+ isConnected &= neighbourObject.GenericType == TileObjectGenericType.Wall ||
+ neighbourObject.GenericType == TileObjectGenericType.Door;
+
+ if (neighbourObject.GetComponent() != null)
+ {
+ isConnected &= IsConnectedToDoor(neighbourObject);
+ }
+
+ return isConnected;
+ }
}
}
diff --git a/Assets/Scripts/SS3D/Systems/Tile/PlacedObjects/PlacedTileObject.cs b/Assets/Scripts/SS3D/Systems/Tile/PlacedObjects/PlacedTileObject.cs
index 6b5c4435da..3576e32f46 100644
--- a/Assets/Scripts/SS3D/Systems/Tile/PlacedObjects/PlacedTileObject.cs
+++ b/Assets/Scripts/SS3D/Systems/Tile/PlacedObjects/PlacedTileObject.cs
@@ -103,13 +103,13 @@ public void DestroySelf()
public void UpdateAdjacencies(PlacedTileObject[] neighbourObjects)
{
if (HasAdjacencyConnector)
- _connector.UpdateAll(neighbourObjects);
+ _connector.UpdateAllConnections(neighbourObjects);
}
public void UpdateSingleAdjacency(PlacedTileObject neighbourObject, Direction dir)
{
if (HasAdjacencyConnector)
- _connector.UpdateSingle(dir, neighbourObject, false);
+ _connector.UpdateSingleConnection(dir, neighbourObject, false);
}
public SavedPlacedTileObject Save()