Skip to content

Commit

Permalink
fix some stuff for disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Oct 17, 2023
1 parent 05d84dc commit 65ff6e9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public bool SetConnection(Direction direction, AdjacencyData data)
return changed;
}

private List<Direction> GetAdjacencies(bool cardinal)
public List<Direction> GetAdjacencies(bool cardinal)
{
//Are we getting adjacencies for cardinal or diagonal directions?
List<int> directionIndexes = cardinal ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DisposalPipeAdjacencyConnector : NetworkActor, IAdjacencyConnector

protected TileObjectSpecificType _specificType;

private bool _isVertical = false;


private void Setup()
{
Expand Down Expand Up @@ -172,20 +174,37 @@ protected virtual void UpdateMeshAndDirection()
var info = _pipeAdjacency.GetMeshAndDirection(_adjacencyMap, _verticalConnection);
transform.localRotation = Quaternion.identity;

var pos = transform.position;
Vector3 pos = transform.position;
Quaternion localRotation = _filter.transform.localRotation;
Vector3 eulerRotation = localRotation.eulerAngles;
_filter.mesh = info.Mesh;

if (info.Mesh == _pipeAdjacency.verticalMesh)
{
_isVertical= true;
transform.position = new Vector3(pos.x, -0.67f, pos.z);
_filter.transform.localRotation = Quaternion.Euler(eulerRotation.x, TileHelper.GetRotationAngle(_placedObject.Direction), eulerRotation.z);

if (!_isVertical)
{
var directions = TileHelper.AllDirections();
directions.Remove(TileHelper.GetOpposite(_placedObject.Direction));
SetBlockedDirection(directions, false);

}

return;
}
else if (_filter.mesh == _pipeAdjacency.verticalMesh)
{
transform.position = new Vector3(pos.x, 0f, pos.z);
return;
}
_filter.mesh = info.Mesh;
Quaternion localRotation = _filter.transform.localRotation;
Vector3 eulerRotation = localRotation.eulerAngles;

if (info.Mesh != _pipeAdjacency.verticalMesh)
{
_isVertical = false;
}

localRotation = Quaternion.Euler(eulerRotation.x, info.Rotation, eulerRotation.z);
_filter.transform.localRotation = localRotation;
}
Expand Down Expand Up @@ -217,5 +236,19 @@ private void SyncVertical(bool oldValue, bool newValue, bool asServer)
UpdateMeshAndDirection();
}
}

/// <summary>
/// Sets a given direction blocked or unblocked.
/// If blocked, this means that it will no longer be allowed to connect on that direction (until further update).
/// </summary>
private void SetBlockedDirection(List<Direction> directions, bool value)
{
foreach(var dir in directions)
{
_adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, value));
}

UpdateMeshAndDirection();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public SavedPlacedTileObject Save()
};
}

public void SetDirection(Direction dir)
{
_dir = dir;
}

/// <summary>
/// Is this in front of the other object ?
/// </summary>
Expand Down
22 changes: 18 additions & 4 deletions Assets/Scripts/SS3D/Systems/Tile/TileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using SS3D.Utils;

namespace SS3D.Systems.Tile
{
Expand Down Expand Up @@ -57,6 +58,12 @@ public static TileLayer[] GetTileLayers()
return TileLayers;
}

public static Tuple<Direction,Direction> GetAdjacentDirections(Direction dir)
{
return new Tuple<Direction, Direction>( (Direction) MathUtility.mod((int) dir + 1, 8),
(Direction)MathUtility.mod((int)dir - 1, 8) );
}

/// <summary>
/// Get the offset in coordinates in a given direction.
/// </summary>
Expand All @@ -78,12 +85,10 @@ public static Vector3 GetClosestPosition(Vector3 worldPosition)

/// <summary>
/// Get the relative direction between two direction.
/// E.g : to = North-East, from = South-West, return South.
/// TODO : maybe swith name of to and from, currently it feels it's the inverse way around.
/// </summary>
public static Direction GetRelativeDirection(Direction to, Direction from)
public static Direction GetRelativeDirection(Direction from, Direction to)
{
return (Direction)((((int)to - (int)from) + 8) % 8);
return (Direction)((((int)from - (int)to) + 8) % 8);
}

/// <summary>
Expand All @@ -94,6 +99,15 @@ public static List<Direction> CardinalDirections()
return new List<Direction> { Direction.North, Direction.East, Direction.South, Direction.West };
}

/// <summary>
/// Return a list of the cardinal directions.
/// </summary>
public static List<Direction> AllDirections()
{
return new List<Direction> { Direction.North, Direction.NorthEast, Direction.East, Direction.SouthEast,
Direction.South, Direction.SouthWest, Direction.West, Direction.NorthWest };
}

/// <summary>
/// Return a list of the diagonal directions.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Systems/Tile/TileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public TileChunk GetChunk(Vector3 worldPosition)
}
}

private TileObject GetTileObject(TileLayer layer, Vector3 worldPosition)
public TileObject GetTileObject(TileLayer layer, Vector3 worldPosition)
{
TileChunk chunk = GetOrCreateChunk(worldPosition); // TODO: creates unnessary empty chunk when checking whether building can be done
return chunk.GetTileObject(layer, worldPosition);
Expand Down

0 comments on commit 65ff6e9

Please sign in to comment.