Projekt přejmenován. Neko nastaven na výchozí pozici
This commit is contained in:
parent
1a27dd6fab
commit
ceac37920b
104 changed files with 873 additions and 208 deletions
109
ONDClient/Map/ClientMapManager.cs
Normal file
109
ONDClient/Map/ClientMapManager.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using GlobalClassLib;
|
||||
using ONDClient.GUI;
|
||||
using PacketLib;
|
||||
|
||||
namespace ONDClient.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(int[] connectors, int[] yourTiles, int[] opponentTiles, int[] litTiles, bool upsideDown ) {
|
||||
|
||||
(int id1, int id2, ConnectorType type, ClientPlayer? owner)[] connectorsData = new (int, int , ConnectorType, ClientPlayer?)[connectors.Length / 4];
|
||||
for (int i = 0; i < connectors.Length / 4; i++){
|
||||
connectorsData[i] = (connectors[i * 4], connectors[i * 4 + 1], (ConnectorType)connectors[i * 4 + 2], connectors[i * 4 + 3] == -1 ? null : Client.GetPlayer(connectors[i * 4 + 3]));
|
||||
}
|
||||
// ClientMapManager.InitMap(upsideDown);
|
||||
|
||||
inverted = upsideDown;
|
||||
|
||||
IdToCoords = upsideDown ? _IdToCoordsInverse : _IdToCoords;
|
||||
CoordsToId = upsideDown ? _CoordsToIdInverse : _CoordsToId;
|
||||
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int j = 0; j < 2; j++){
|
||||
map[i, j] = new MapTileProjection(CoordsToId(i, j));
|
||||
}
|
||||
map[i, 2] = new MapTileProjection(CoordsToId(i, 2));
|
||||
for (int j = 3; j < 5; j++){
|
||||
map[i, j] = new MapTileProjection(CoordsToId(i, j));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var tileId in yourTiles){
|
||||
Get(tileId).Owner = Client.Player;
|
||||
}
|
||||
|
||||
foreach (var tileId in opponentTiles){
|
||||
Get(tileId).Owner = Client.Opponent;
|
||||
}
|
||||
|
||||
foreach (var tileId in litTiles){
|
||||
Get(tileId).Lit = true;
|
||||
}
|
||||
|
||||
|
||||
TileConnectorProjection[] connectorProjections = connectorsData.Select(c => new TileConnectorProjection(Get(c.id1), Get(c.id2), c.type){Owner = c.owner}).ToArray();
|
||||
InitConnectors(connectorProjections);
|
||||
|
||||
UIManager.SpawnMapElements(connectorProjections.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray());
|
||||
|
||||
|
||||
}
|
||||
|
||||
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 static TileConnectorProjection[] GetAllConnectors() {
|
||||
List<TileConnectorProjection> connectors = new();
|
||||
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int j = 0; j < 5; j++){
|
||||
MapTileProjection tile = map[i, j];
|
||||
Array.ForEach(tile.GetAllConnectors(), c => {
|
||||
if(tile.Id < c.OtherTile(tile).Id)
|
||||
connectors.Add(c);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return connectors.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public const int MAP_SIDE_LENGTH = 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 / MAP_SIDE_LENGTH, id % MAP_SIDE_LENGTH);
|
||||
private static Func<int, (int x, int y)> _IdToCoordsInverse = id => (MAP_SIDE_LENGTH - 1 - (id / MAP_SIDE_LENGTH), MAP_SIDE_LENGTH - 1 - (id % MAP_SIDE_LENGTH));
|
||||
private static Func<int, int, int> _CoordsToId = (x, y) => x * MAP_SIDE_LENGTH + y;
|
||||
private static Func<int, int, int> _CoordsToIdInverse = (x, y) => (MAP_SIDE_LENGTH - 1 - x) * MAP_SIDE_LENGTH + (MAP_SIDE_LENGTH - 1 - y);
|
||||
|
||||
public static MapTileProjection[] GetAllTiles() {
|
||||
List<MapTileProjection> tiles = new();
|
||||
foreach (var tile in map){
|
||||
tiles.Add(tile);
|
||||
}
|
||||
|
||||
return tiles.ToArray();
|
||||
}
|
||||
}
|
||||
11
ONDClient/Map/MapTileProjection.cs
Normal file
11
ONDClient/Map/MapTileProjection.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using GlobalClassLib;
|
||||
|
||||
namespace ONDClient.Map;
|
||||
|
||||
public class MapTileProjection : GlobalMapTile<TileConnectorProjection, MapTileProjection> {
|
||||
public ClientPlayer? Owner { get; set; }
|
||||
|
||||
public MapTileProjection(int id) : base(id, ClientMapManager.IdToCoords(id)) {
|
||||
Lit = false;
|
||||
}
|
||||
}
|
||||
14
ONDClient/Map/TileConnectorProjection.cs
Normal file
14
ONDClient/Map/TileConnectorProjection.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using GlobalClassLib;
|
||||
|
||||
namespace ONDClient.Map;
|
||||
|
||||
public class TileConnectorProjection : GlobalTileConnector<MapTileProjection, TileConnectorProjection> {
|
||||
public ClientPlayer? Owner { get; set; }
|
||||
public TileConnectorProjection(MapTileProjection tile1, MapTileProjection tile2, ConnectorType type) : base(tile1, tile2, type) {
|
||||
}
|
||||
|
||||
public TileConnectorProjection(MapTileProjection tile2, ConnectorType type) : base(tile2, type) {
|
||||
}
|
||||
|
||||
public override TileConnectorProjection Clone() => new(Tiles.tile1, Tiles.tile2, Type){Owner = Owner};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue