55 lines
No EOL
2.3 KiB
C#
55 lines
No EOL
2.3 KiB
C#
using System;
|
|
using System.Runtime.InteropServices.JavaScript;
|
|
using GlobalClassLib;
|
|
|
|
namespace FNAF_Clone.Map;
|
|
|
|
public class ClientMapManager {
|
|
private static MapTileProjection[,] map = new MapTileProjection[5, 5];
|
|
public static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y];
|
|
public static MapTileProjection Get(int tileId) => Get(IdToCoords(tileId));
|
|
|
|
private static bool inverted;
|
|
public static void InitMap(bool invert = false) {
|
|
inverted = invert;
|
|
|
|
IdToCoords = invert ? _IdToCoordsInverse : _IdToCoords;
|
|
CoordsToId = invert ? _CoordsToIdInverse : _CoordsToId;
|
|
|
|
for (int i = 0; i < 5; i++){
|
|
for (int j = 0; j < 2; j++){
|
|
map[i, j] = new MapTileProjection(CoordsToId(i, j)); // TODO: implement ownership
|
|
}
|
|
map[i, 2] = new MapTileProjection(CoordsToId(i, 2));
|
|
for (int j = 3; j < 5; j++){
|
|
map[i, j] = new MapTileProjection(CoordsToId(i, j));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static void InitConnectors(TileConnectorProjection[] connectors) {
|
|
foreach (var con in connectors){
|
|
// (int x, int y) coords1 = MapTileProjection.IdToCoords(con.Tiles.tile1.Id);
|
|
// (int x, int y) coords2 = MapTileProjection.IdToCoords(con.Tiles.tile2.Id);
|
|
map[con.Tiles.tile1.GridPosition.x, con.Tiles.tile1.GridPosition.y].AddConnector(con);
|
|
}
|
|
}
|
|
|
|
public static TileConnectorProjection GetConnector((int, int) id) => Get(id.Item1).GetConnector(id.Item2);
|
|
|
|
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(IdToCoords(tileId)).GetAllConnectors();
|
|
|
|
|
|
|
|
public const int ID_X_OFFSET = 5; // map grid height
|
|
public static Func<int, int, int> CoordsToId{ get; private set; }
|
|
public static Func<int, (int x, int y)> IdToCoords{ get; private set; }
|
|
|
|
private static Func<int, (int x, int y)> _IdToCoords = id => (id / ID_X_OFFSET, id % ID_X_OFFSET);
|
|
private static Func<int, (int x, int y)> _IdToCoordsInverse = id => (ID_X_OFFSET - 1 - (id / ID_X_OFFSET), ID_X_OFFSET - 1 - (id % ID_X_OFFSET));
|
|
private static Func<int, int, int> _CoordsToId = (x, y) => x * ID_X_OFFSET + y;
|
|
private static Func<int, int, int> _CoordsToIdInverse = (x, y) => (ID_X_OFFSET - 1 - x) * ID_X_OFFSET + (ID_X_OFFSET - 1 - y);
|
|
} |