more refactoring

This commit is contained in:
Michele Scandura 2020-11-09 16:47:17 +00:00
parent d61f46d07a
commit 886d2a88b0
13 changed files with 592 additions and 573 deletions

View file

@ -1,12 +1,8 @@
namespace Sledgemapper.Shared.Entities
{
public class Overlay
public class Overlay :BaseMapEntity
{
public int X { get; set; }
public int Y { get; set; }
public string ID { get; set; }
public bool Intersection { get; set; }
public int Rotation { get; set; }
public override string ToString()
{

View file

@ -4,52 +4,24 @@ using System;
namespace Sledgemapper.Shared.Entities
{
public class TileAddedEventArgs : EventArgs
public class MapEntityAddedEventArgs : EventArgs
{
public Tile Tile { get; set; }
public TileAddedEventArgs(Tile tile) => Tile = tile;
public BaseMapEntity MapEntity { get; private set; }
public MapEntityAddedEventArgs(BaseMapEntity mapEntity) => MapEntity = mapEntity;
}
public class OverlayAddedEventArgs : EventArgs
public class MapEntityDeletedEventArgs : EventArgs
{
public Overlay Overlay { get; set; }
public OverlayAddedEventArgs(Overlay overlay) => Overlay = overlay;
public BaseMapEntity MapEntity { get; private set; }
public MapEntityDeletedEventArgs(BaseMapEntity mapEntity) => MapEntity = mapEntity;
}
public class WallAddedEventArgs : EventArgs
public class Session
{
public Wall Wall { get; set; }
public WallAddedEventArgs(Wall wall) => Wall = wall;
}
public event EventHandler<MapEntityAddedEventArgs> MapEntityAdded;
public event EventHandler<MapEntityDeletedEventArgs> MapEntityDeleted;
public class WallDeletedEventArgs : EventArgs
{
public Wall Wall { get; set; }
public WallDeletedEventArgs(Wall wall) => Wall = wall;
}
public class OverlayDeletedEventArgs : EventArgs
{
public Overlay Overlay { get; set; }
public OverlayDeletedEventArgs(Overlay overlay) => Overlay = overlay;
}
public class TileDeletedEventArgs : EventArgs
{
public Tile Tile { get; set; }
public TileDeletedEventArgs(Tile tile) => Tile = tile;
}
public class SessionData
{
public event EventHandler<TileAddedEventArgs> TileAdded;
public event EventHandler<OverlayAddedEventArgs> OverlayAdded;
public event EventHandler<WallAddedEventArgs> WallAdded;
public event EventHandler<WallDeletedEventArgs> WallDeleted;
public event EventHandler<OverlayDeletedEventArgs> OverlayDeleted;
public event EventHandler<TileDeletedEventArgs> TileDeleted;
public SessionData()
public Session()
{
Map = new ConcurrentDictionary<string, Tile>();
Overlays = new ConcurrentDictionary<string, Overlay>();
@ -64,6 +36,7 @@ namespace Sledgemapper.Shared.Entities
public bool IsValid { get; set; }
public List<Player> Players { get; set; }
public List<string> Colors;
public string SessionName { get; set; }
public void NewTile(Tile selectedTile, string tileId)
{
@ -84,7 +57,7 @@ namespace Sledgemapper.Shared.Entities
}
Map.TryAdd(newTile.ToString(), newTile);
OnRaiseTileAddedEvent(new TileAddedEventArgs(newTile));
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
}
public void NewOverlay(Overlay selectedOverlay, string overlayId)
@ -105,7 +78,7 @@ namespace Sledgemapper.Shared.Entities
}
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
OnRaiseOverlayAddedEvent(new OverlayAddedEventArgs(newOverlay));
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newOverlay));
}
public void NewWall(Wall selectedWall, string wallId)
@ -122,7 +95,7 @@ namespace Sledgemapper.Shared.Entities
}
Walls.TryAdd(newWall.ToString(), newWall);
OnRaiseWallAddedEvent(new WallAddedEventArgs(newWall));
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newWall));
}
public void DeleteWall(Wall wall)
@ -134,82 +107,48 @@ namespace Sledgemapper.Shared.Entities
var removed = Walls.TryRemove(wall.ToString(), out var _);
if (removed)
{
OnRaiseWallDeletedEvent(new WallDeletedEventArgs(wall));
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(wall));
}
}
public void DeleteOverlay(Overlay overlay)
{
if (overlay is null)
if (overlay is null)
{
return;
}
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
if (removed)
{
OnRaiseOverlayDeletedEvent(new OverlayDeletedEventArgs(overlay));
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(overlay));
}
}
public void DeleteTile(Tile tile)
{
if (tile is null)
if (tile is null)
{
return;
}
var removed = Map.TryRemove(tile.ToString(), out var _);
if (removed)
{
OnRaiseTileDeletedEvent(new TileDeletedEventArgs(tile));
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(tile));
}
}
protected virtual void OnRaiseTileAddedEvent(TileAddedEventArgs e)
protected virtual void OnRaiseMapEntityAddedEvent(MapEntityAddedEventArgs e)
{
var raiseEvent = TileAdded;
var raiseEvent = MapEntityAdded;
if (raiseEvent != null)
{
raiseEvent(this, e);
}
}
protected virtual void OnRaiseOverlayAddedEvent(OverlayAddedEventArgs e)
protected virtual void OnRaiseMapEntityDeletedEvent(MapEntityDeletedEventArgs e)
{
var raiseEvent = OverlayAdded;
if (raiseEvent != null)
{
raiseEvent(this, e);
}
}
protected virtual void OnRaiseWallAddedEvent(WallAddedEventArgs e)
{
var raiseEvent = WallAdded
;
if (raiseEvent != null)
{
raiseEvent(this, e);
}
}
protected virtual void OnRaiseWallDeletedEvent(WallDeletedEventArgs e)
{
var raiseEvent = WallDeleted;
if (raiseEvent != null)
{
raiseEvent(this, e);
}
}
protected virtual void OnRaiseOverlayDeletedEvent(OverlayDeletedEventArgs e)
{
var raiseEvent = OverlayDeleted;
if (raiseEvent != null)
{
raiseEvent(this, e);
}
}
protected virtual void OnRaiseTileDeletedEvent(TileDeletedEventArgs e)
{
var raiseEvent = TileDeleted;
var raiseEvent = MapEntityDeleted;
if (raiseEvent != null)
{
raiseEvent(this, e);

View file

@ -1,18 +1,19 @@
namespace Sledgemapper.Shared.Entities
{
public class Tile
{
public int X { get; set; }
public abstract class BaseMapEntity
{
public int X { get; set; }
public int Y { get; set; }
public string ID { get; set; }
public int Rotation { get; set; }
public override string ToString()
public int Rotation { get; set; }
public override string ToString()
{
return $"{X}_{Y}";
}
}
public class Tile :BaseMapEntity
{
}

View file

@ -2,15 +2,10 @@
{
public class Wall
public class Wall :BaseMapEntity
{
public int X { get; set; }
public int Y { get; set; }
public string ID { get; set; }
public int Rotation { get; set; }
public override string ToString()
{
return $"{X}_{Y}";
}
}
}