2026-02-14 14:35:29 +01:00
|
|
|
namespace GlobalClassLib;
|
|
|
|
|
|
|
|
|
|
public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon,TTile> where TCon : GlobalTileConnector<TTile, TCon> {
|
|
|
|
|
// private readonly TTile _tile1;
|
|
|
|
|
// private readonly TTile _tile2;
|
|
|
|
|
|
|
|
|
|
public GlobalTileConnector(TTile tile1, TTile tile2, ConnectorType type) {
|
|
|
|
|
Tiles.tile1 = tile1;
|
|
|
|
|
Tiles.tile2 = tile2;
|
|
|
|
|
Type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GlobalTileConnector(TTile tile2, ConnectorType type) {
|
|
|
|
|
Tiles.tile2 = tile2;
|
|
|
|
|
Type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public (TTile tile1, TTile tile2) Tiles;
|
2026-02-21 18:42:44 +01:00
|
|
|
public bool Blocked { get; set; }
|
|
|
|
|
|
2026-02-14 14:35:29 +01:00
|
|
|
public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id);
|
|
|
|
|
|
|
|
|
|
public ConnectorType Type { get; set; }
|
|
|
|
|
|
|
|
|
|
public TTile OtherTile(TTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1;
|
2026-02-21 18:42:44 +01:00
|
|
|
|
|
|
|
|
public Direction GetDirection(TTile tile) {
|
|
|
|
|
if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE;
|
|
|
|
|
|
|
|
|
|
TTile other = OtherTile(tile);
|
|
|
|
|
(int, int) dpos = (other.GridPosition.x - tile.GridPosition.x, other.GridPosition.y - tile.GridPosition.y);
|
|
|
|
|
|
|
|
|
|
switch (dpos){
|
|
|
|
|
case (0, 1): return Direction.NORTH;
|
|
|
|
|
case (1, 0): return Direction.EAST;
|
|
|
|
|
case (0, -1): return Direction.SOUTH;
|
|
|
|
|
case (-1, 0): return Direction.WEST;
|
|
|
|
|
default: return Direction.NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-14 14:35:29 +01:00
|
|
|
|
|
|
|
|
public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";
|
|
|
|
|
|
|
|
|
|
public abstract TCon Clone();
|
|
|
|
|
}
|