Oprava spawnování monster, optimalizace v CommandProcessor a EventProcessor. Přesunutí některých tříd do vlastních namespaců, pročištění kódu, úpravy formátování, odstranění nepoužívaných souborů a zakomentovaného kódu

This commit is contained in:
Perry 2026-03-28 09:59:31 +01:00
parent e5d746d597
commit 243f071a43
62 changed files with 873 additions and 1217 deletions

View file

@ -1,5 +1,3 @@
using System.Diagnostics.Contracts;
namespace GlobalClassLib;
public enum EnemyType {

View file

@ -3,29 +3,24 @@ namespace GlobalClassLib;
public abstract class GlobalEnemy<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> {
public TTile? Location { get; set; }
public bool Visible { get; set; }
public abstract string Name{ get; }
public abstract int TypeId{ get; }
public int Id { get; }
public abstract string Name{ get; }
public abstract EnemyType Type{ get; }
// ReSharper disable once StaticMemberInGenericType
private static int nextId = 0;
// public static Dictionary<TTile, GlobalEnemy<TTile, TCon>> PresentEnemies = new();
public GlobalEnemy() {
Id = nextId++;
}
public GlobalEnemy(int id) {
Id = id;
}
public virtual void Spawn(TTile? location) {
// PresentEnemies.Add(location, this);
public virtual void Spawn(TTile location) {
Location = location;
Visible = true;
Console.WriteLine($"Enemy {Id} ({Name}) spawned at {(location == null ? "" : location.Id)} {(location == null ? "" : location.GridPosition)}");
Console.WriteLine($"Enemy {Id} ({Name}) spawned at {location.Id} {location.GridPosition}");
}
public virtual void Update() { }

View file

@ -1,27 +1,22 @@
namespace GlobalClassLib;
public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class
public int Id { get; }
public abstract class GlobalMapTile<TCon, TTile>(int id, (int x, int y) gridPosition)
where TCon : GlobalTileConnector<TTile, TCon>
where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class
public int Id { get; } = id;
public bool Lit { get; set; } = false;
public (int x, int y) GridPosition { get; private set; }
public (int x, int y) GridPosition { get; private set; } = gridPosition;
private readonly List<TCon> connectors = new();
private List<TCon> connectors = new();
public GlobalMapTile(int id, (int x, int y) gridPosition) {
Id = id;
GridPosition = gridPosition;
}
public void AddConnector(TCon connector) { // tile1 is ignored when provided
connector = connector.Clone();
connector.Tiles.tile1 = (TTile)this;
connectors.Add(connector);
connector.Tiles.tile2._AddConnectorNoRepeat(connector);
// connectors.Add(new TCon(this, tile, type));
// tile.connectors.Add(new GlobalTileConnector(tile, this, type));
}
private void _AddConnectorNoRepeat(TCon connector) {
// (connector.Tiles.tile1, connector.Tiles.tile2) = (connector.Tiles.tile2, connector.Tiles.tile1);
connectors.Add(connector);
}
@ -30,7 +25,7 @@ public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnecto
public override string ToString() => $"[{Id}] -> {string.Join(", ", connectors.Select(c => $"[{c.OtherTile((TTile)this).Id}]"))}";
public override int GetHashCode() => Id.GetHashCode();
public string PositionAsString => $"[{Id}]"; // for debug purposes
public string IdAsString => $"[{Id}]"; // debug
public TCon? GetConnector(int id) {
foreach (var con in connectors){

View file

@ -1,9 +1,15 @@
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 abstract class GlobalTileConnector<TTile, TCon>
where TTile : GlobalMapTile<TCon,TTile>
where TCon : GlobalTileConnector<TTile, TCon> {
public (TTile tile1, TTile tile2) Tiles;
public bool Blocked { get; set; }
public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id);
public ConnectorType Type { get; set; }
public TTile OtherTile(TTile tile) => Tiles.tile1 == tile ? Tiles.tile2 : Tiles.tile1;
public GlobalTileConnector(TTile tile1, TTile tile2, ConnectorType type) {
Tiles.tile1 = tile1;
Tiles.tile2 = tile2;
@ -14,16 +20,7 @@ public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTi
Tiles.tile2 = tile2;
Type = type;
}
public (TTile tile1, TTile tile2) Tiles;
public bool Blocked { get; set; }
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;
public Direction GetDirection(TTile tile) {
if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE;
@ -39,7 +36,7 @@ public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTi
}
}
public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";
public override string ToString() => $"Con ({Tiles.Item1.IdAsString} -> {Tiles.Item2.IdAsString})";
public abstract TCon Clone();
}