refactoring
This commit is contained in:
parent
9c100531ef
commit
92f333a4c4
26 changed files with 860 additions and 491 deletions
|
@ -19,10 +19,34 @@ namespace Sledgemapper.Api.Controllers
|
||||||
await _mediator.Publish(new NewTileNotification(sessionName, tile));
|
await _mediator.Publish(new NewTileNotification(sessionName, tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("session")]
|
[HttpPost("overlay")]
|
||||||
public async Task Post(string sessionName, [FromBody]Overlay overlay)
|
public async Task Post(string sessionName, [FromBody]Overlay overlay)
|
||||||
{
|
{
|
||||||
await _mediator.Publish(new NewOverlayNotification(sessionName, overlay));
|
await _mediator.Publish(new NewOverlayNotification(sessionName, overlay));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("wall")]
|
||||||
|
public async Task Post(string sessionName, [FromBody]Wall wall)
|
||||||
|
{
|
||||||
|
await _mediator.Publish(new NewWallNotification(sessionName, wall));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("tile")]
|
||||||
|
public async Task Delete(string sessionName, [FromBody]Tile tile)
|
||||||
|
{
|
||||||
|
await _mediator.Publish(new DeleteTileNotification(sessionName, tile));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("overlay")]
|
||||||
|
public async Task Delete(string sessionName, [FromBody]Overlay overlay)
|
||||||
|
{
|
||||||
|
await _mediator.Publish(new DeleteOverlayNotification(sessionName, overlay));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("wall")]
|
||||||
|
public async Task Delete(string sessionName, [FromBody]Wall wall)
|
||||||
|
{
|
||||||
|
await _mediator.Publish(new DeleteWallNotification(sessionName, wall));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,117 +0,0 @@
|
||||||
using MediatR;
|
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using SignalRChat.Hubs;
|
|
||||||
using Sledgemapper.Api.Data;
|
|
||||||
using Sledgemapper.Clients;
|
|
||||||
using Sledgemapper.Shared.Entities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Sledgemapper.Api.Handlers
|
|
||||||
{
|
|
||||||
public abstract class BaseNotification : INotification
|
|
||||||
{
|
|
||||||
public double Timestamp { get; private set; }
|
|
||||||
public string SessionName { get; private set; }
|
|
||||||
|
|
||||||
public BaseNotification(string sessionName)
|
|
||||||
{
|
|
||||||
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
||||||
SessionName = sessionName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NewTileNotification : BaseNotification
|
|
||||||
{
|
|
||||||
public Tile Tile { get; private set; }
|
|
||||||
|
|
||||||
public NewTileNotification(string sessionName, Tile tile) : base(sessionName)
|
|
||||||
{
|
|
||||||
Tile = tile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NewOverlayNotification : BaseNotification
|
|
||||||
{
|
|
||||||
public Overlay Overlay { get; private set; }
|
|
||||||
|
|
||||||
public NewOverlayNotification(string sessionName, Overlay overlay) : base(sessionName)
|
|
||||||
{
|
|
||||||
Overlay = overlay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SendNewTileMessage : INotificationHandler<NewTileNotification>
|
|
||||||
{
|
|
||||||
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
|
||||||
|
|
||||||
public SendNewTileMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
|
||||||
|
|
||||||
public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
await _hub.Clients.Groups(notification.SessionName).NewTile(notification.Tile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SaveNewTile : INotificationHandler<NewTileNotification>
|
|
||||||
{
|
|
||||||
private readonly MyDbContext _dbcontext;
|
|
||||||
|
|
||||||
public SaveNewTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
|
||||||
|
|
||||||
public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
|
|
||||||
|
|
||||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
|
||||||
{
|
|
||||||
Operation = "N",
|
|
||||||
SessionName = notification.SessionName,
|
|
||||||
Type = "T",
|
|
||||||
Timestamp = notification.Timestamp,
|
|
||||||
Object = jsonString
|
|
||||||
});
|
|
||||||
await _dbcontext.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SendNewOverlayMessage : INotificationHandler<NewOverlayNotification>
|
|
||||||
{
|
|
||||||
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
|
||||||
|
|
||||||
public SendNewOverlayMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
|
||||||
|
|
||||||
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
await _hub.Clients.Groups(notification.SessionName).NewOverlay(notification.Overlay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SaveNewOverlay : INotificationHandler<NewOverlayNotification>
|
|
||||||
{
|
|
||||||
private readonly MyDbContext _dbcontext;
|
|
||||||
|
|
||||||
public SaveNewOverlay(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
|
||||||
|
|
||||||
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
|
|
||||||
|
|
||||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
|
||||||
{
|
|
||||||
Operation = "N",
|
|
||||||
SessionName = notification.SessionName,
|
|
||||||
Type = "O",
|
|
||||||
Timestamp = notification.Timestamp,
|
|
||||||
Object = jsonString
|
|
||||||
});
|
|
||||||
|
|
||||||
await _dbcontext.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
32
Sledgemapper.Api/Handlers/SaveDeleteOverlay.cs
Normal file
32
Sledgemapper.Api/Handlers/SaveDeleteOverlay.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using MediatR;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SaveDeleteOverlay : INotificationHandler<DeleteOverlayNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveDeleteOverlay(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteOverlayNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "D",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "O",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Sledgemapper.Api/Handlers/SaveDeleteTile.cs
Normal file
31
Sledgemapper.Api/Handlers/SaveDeleteTile.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using MediatR;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SaveDeleteTile : INotificationHandler<DeleteTileNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveDeleteTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteTileNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "D",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "T",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
Sledgemapper.Api/Handlers/SaveDeleteWall.cs
Normal file
35
Sledgemapper.Api/Handlers/SaveDeleteWall.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
|
||||||
|
public class SaveDeleteWall : INotificationHandler<DeleteWallNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveDeleteWall(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteWallNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Wall>(notification.Wall);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "D",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "W",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
Sledgemapper.Api/Handlers/SaveNewOverlay.cs
Normal file
32
Sledgemapper.Api/Handlers/SaveNewOverlay.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using MediatR;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SaveNewOverlay : INotificationHandler<NewOverlayNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveNewOverlay(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "N",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "O",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Sledgemapper.Api/Handlers/SaveNewTile.cs
Normal file
31
Sledgemapper.Api/Handlers/SaveNewTile.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using MediatR;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SaveNewTile : INotificationHandler<NewTileNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveNewTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "N",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "T",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Sledgemapper.Api/Handlers/SaveNewWall.cs
Normal file
31
Sledgemapper.Api/Handlers/SaveNewWall.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using MediatR;
|
||||||
|
using Sledgemapper.Api.Data;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SaveNewWall : INotificationHandler<NewWallNotification>
|
||||||
|
{
|
||||||
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
|
public SaveNewWall(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
||||||
|
|
||||||
|
public async Task Handle(NewWallNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var jsonString = JsonSerializer.Serialize<Wall>(notification.Wall);
|
||||||
|
|
||||||
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
|
{
|
||||||
|
Operation = "N",
|
||||||
|
SessionName = notification.SessionName,
|
||||||
|
Type = "W",
|
||||||
|
Timestamp = notification.Timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendDeleteOverlayMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendDeleteOverlayMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendDeleteOverlayMessage : INotificationHandler<DeleteOverlayNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendDeleteOverlayMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteOverlayNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).DeleteOverlay(notification.Overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendDeleteTileMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendDeleteTileMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendDeleteTileMessage : INotificationHandler<DeleteTileNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendDeleteTileMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteTileNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).DeleteTile(notification.Tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendDeleteWallMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendDeleteWallMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendDeleteWallMessage : INotificationHandler<DeleteWallNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendDeleteWallMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(DeleteWallNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).DeleteWall(notification.Wall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendNewOverlayMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendNewOverlayMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendNewOverlayMessage : INotificationHandler<NewOverlayNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendNewOverlayMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).NewOverlay(notification.Overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendNewTileMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendNewTileMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendNewTileMessage : INotificationHandler<NewTileNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendNewTileMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).NewTile(notification.Tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Sledgemapper.Api/Handlers/SendNewWallMessage.cs
Normal file
21
Sledgemapper.Api/Handlers/SendNewWallMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using SignalRChat.Hubs;
|
||||||
|
using Sledgemapper.Clients;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class SendNewWallMessage : INotificationHandler<NewWallNotification>
|
||||||
|
{
|
||||||
|
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
public SendNewWallMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
public async Task Handle(NewWallNotification notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _hub.Clients.Groups(notification.SessionName).NewWall(notification.Wall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ namespace SignalRChat.Hubs
|
||||||
private readonly MyDbContext _dbcontext;
|
private readonly MyDbContext _dbcontext;
|
||||||
|
|
||||||
// public SledgemapperHub(IMediator mediator) => _mediator = mediator;
|
// public SledgemapperHub(IMediator mediator) => _mediator = mediator;
|
||||||
public SledgemapperHub(MyDbContext dbcontext, IMediator mediator) { _dbcontext = dbcontext; _mediator=mediator;}
|
public SledgemapperHub(MyDbContext dbcontext, IMediator mediator) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||||
private static Dictionary<string, SessionData> _sessions = new Dictionary<string, SessionData>();
|
private static Dictionary<string, SessionData> _sessions = new Dictionary<string, SessionData>();
|
||||||
public List<string> Colors = new List<string>{"CC0000",
|
public List<string> Colors = new List<string>{"CC0000",
|
||||||
"CC3300",
|
"CC3300",
|
||||||
|
@ -45,10 +45,15 @@ namespace SignalRChat.Hubs
|
||||||
|
|
||||||
var jsonString = JsonSerializer.Serialize<Tile>(tile);
|
var jsonString = JsonSerializer.Serialize<Tile>(tile);
|
||||||
|
|
||||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog{
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
Operation="N", SessionName=sessionName, Type="T", Timestamp=timestamp, Object=jsonString
|
{
|
||||||
});
|
Operation = "N",
|
||||||
await _dbcontext.SaveChangesAsync();
|
SessionName = sessionName,
|
||||||
|
Type = "T",
|
||||||
|
Timestamp = timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
|
|
||||||
await Clients.Group(sessionName).NewTile(tile);
|
await Clients.Group(sessionName).NewTile(tile);
|
||||||
}
|
}
|
||||||
|
@ -73,12 +78,17 @@ await _dbcontext.SaveChangesAsync();
|
||||||
_sessions[sessionName].Overlays.TryRemove(t.ToString(), out var rtile);
|
_sessions[sessionName].Overlays.TryRemove(t.ToString(), out var rtile);
|
||||||
}
|
}
|
||||||
_sessions[sessionName].Overlays.TryAdd(tile.ToString(), tile);
|
_sessions[sessionName].Overlays.TryAdd(tile.ToString(), tile);
|
||||||
var jsonString = JsonSerializer.Serialize<Overlay>(tile);
|
var jsonString = JsonSerializer.Serialize<Overlay>(tile);
|
||||||
|
|
||||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog{
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||||
Operation="N", SessionName=sessionName, Type="O", Timestamp=timestamp, Object=jsonString
|
{
|
||||||
});
|
Operation = "N",
|
||||||
await _dbcontext.SaveChangesAsync();
|
SessionName = sessionName,
|
||||||
|
Type = "O",
|
||||||
|
Timestamp = timestamp,
|
||||||
|
Object = jsonString
|
||||||
|
});
|
||||||
|
await _dbcontext.SaveChangesAsync();
|
||||||
await Clients.Group(sessionName).NewOverlay(tile);
|
await Clients.Group(sessionName).NewOverlay(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
Sledgemapper.Api/Notifications/BaseNotification.cs
Normal file
17
Sledgemapper.Api/Notifications/BaseNotification.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using MediatR;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public abstract class BaseNotification : INotification
|
||||||
|
{
|
||||||
|
public double Timestamp { get; private set; }
|
||||||
|
public string SessionName { get; private set; }
|
||||||
|
|
||||||
|
public BaseNotification(string sessionName)
|
||||||
|
{
|
||||||
|
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
SessionName = sessionName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/DeleteOverlayNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/DeleteOverlayNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class DeleteOverlayNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Overlay Overlay { get; private set; }
|
||||||
|
|
||||||
|
public DeleteOverlayNotification(string sessionName, Overlay overlay) : base(sessionName)
|
||||||
|
{
|
||||||
|
Overlay = overlay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/DeleteTileNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/DeleteTileNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class DeleteTileNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Tile Tile { get; private set; }
|
||||||
|
|
||||||
|
public DeleteTileNotification(string sessionName, Tile tile) : base(sessionName)
|
||||||
|
{
|
||||||
|
Tile = tile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/DeleteWallNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/DeleteWallNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class DeleteWallNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Wall Wall { get; private set; }
|
||||||
|
|
||||||
|
public DeleteWallNotification(string sessionName, Wall wall) : base(sessionName)
|
||||||
|
{
|
||||||
|
Wall = wall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/NewOverlayNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/NewOverlayNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class NewOverlayNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Overlay Overlay { get; private set; }
|
||||||
|
|
||||||
|
public NewOverlayNotification(string sessionName, Overlay overlay) : base(sessionName)
|
||||||
|
{
|
||||||
|
Overlay = overlay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/NewTileNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/NewTileNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class NewTileNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Tile Tile { get; private set; }
|
||||||
|
|
||||||
|
public NewTileNotification(string sessionName, Tile tile) : base(sessionName)
|
||||||
|
{
|
||||||
|
Tile = tile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Sledgemapper.Api/Notifications/NewWallNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/NewWallNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
namespace Sledgemapper.Api.Handlers
|
||||||
|
{
|
||||||
|
public class NewWallNotification : BaseNotification
|
||||||
|
{
|
||||||
|
public Wall Wall { get; private set; }
|
||||||
|
|
||||||
|
public NewWallNotification(string sessionName, Wall wall) : base(sessionName)
|
||||||
|
{
|
||||||
|
Wall = wall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,16 +10,44 @@ namespace Sledgemapper.Shared.Entities
|
||||||
public TileAddedEventArgs(Tile tile) => Tile = tile;
|
public TileAddedEventArgs(Tile tile) => Tile = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OverlayAddedEventArgs : EventArgs
|
public class OverlayAddedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public Overlay Overlay { get; set; }
|
public Overlay Overlay { get; set; }
|
||||||
public OverlayAddedEventArgs(Overlay overlay) => Overlay = overlay;
|
public OverlayAddedEventArgs(Overlay overlay) => Overlay = overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class WallAddedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public Wall Wall { get; set; }
|
||||||
|
public WallAddedEventArgs(Wall wall) => Wall = wall;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 class SessionData
|
||||||
{
|
{
|
||||||
public event EventHandler<TileAddedEventArgs> RaiseTileAddedEvent;
|
public event EventHandler<TileAddedEventArgs> TileAdded;
|
||||||
public event EventHandler<OverlayAddedEventArgs> RaiseOverlayAddedEvent;
|
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 SessionData()
|
||||||
{
|
{
|
||||||
|
@ -39,82 +67,151 @@ namespace Sledgemapper.Shared.Entities
|
||||||
|
|
||||||
public void NewTile(Tile selectedTile, string tileId)
|
public void NewTile(Tile selectedTile, string tileId)
|
||||||
{
|
{
|
||||||
|
if (selectedTile is null || string.IsNullOrWhiteSpace(tileId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
||||||
Tile newTile;
|
var newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
||||||
if (tileExist)
|
if (tileExist)
|
||||||
{
|
{
|
||||||
Map.TryRemove(tile.ToString(), out var _);
|
Map.TryRemove(tile.ToString(), out var _);
|
||||||
if (tile.ID == tileId)
|
if (tile.ID == tileId)
|
||||||
{
|
{
|
||||||
newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId, Rotation = (tile.Rotation + 1) % 4 };
|
newTile.Rotation = (tile.Rotation + 1) % 4;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.TryAdd(newTile.ToString(), newTile);
|
Map.TryAdd(newTile.ToString(), newTile);
|
||||||
|
|
||||||
OnRaiseTileAddedEvent(new TileAddedEventArgs(newTile));
|
OnRaiseTileAddedEvent(new TileAddedEventArgs(newTile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewOverlay(Overlay selectedOverlay, string tileId)
|
public void NewOverlay(Overlay selectedOverlay, string overlayId)
|
||||||
{
|
{
|
||||||
|
if (selectedOverlay is null || string.IsNullOrWhiteSpace(overlayId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
||||||
Overlay newOverlay;
|
var newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = overlayId, Intersection = selectedOverlay.Intersection }; ;
|
||||||
if (overlayExist)
|
if (overlayExist)
|
||||||
{
|
{
|
||||||
Overlays.TryRemove(overlay.ToString(), out var rrtile);
|
Overlays.TryRemove(overlay.ToString(), out var rrtile);
|
||||||
if (overlay.ID == tileId)
|
if (overlay.ID == overlayId)
|
||||||
{
|
{
|
||||||
newOverlay = new Overlay { X = overlay.X, Y = overlay.Y, ID = tileId, Intersection = overlay.Intersection, Rotation = (overlay.Rotation + 1) % 4 };
|
newOverlay.Rotation = (overlay.Rotation + 1) % 4;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = tileId, Intersection = selectedOverlay.Intersection };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = tileId, Intersection = selectedOverlay.Intersection };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
||||||
OnRaiseOverlayAddedEvent(new OverlayAddedEventArgs(newOverlay));
|
OnRaiseOverlayAddedEvent(new OverlayAddedEventArgs(newOverlay));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewWall(Wall selectedWall, string wallId)
|
||||||
|
{
|
||||||
|
if (selectedWall is null || string.IsNullOrWhiteSpace(wallId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var tileExist = Walls.TryGetValue(selectedWall.ToString(), out var wall);
|
||||||
|
var newWall = new Wall { X = selectedWall.X, Y = selectedWall.Y, ID = wallId, Rotation = selectedWall.Rotation };
|
||||||
|
if (tileExist)
|
||||||
|
{
|
||||||
|
Walls.TryRemove(wall.ToString(), out var _);
|
||||||
|
}
|
||||||
|
|
||||||
|
Walls.TryAdd(newWall.ToString(), newWall);
|
||||||
|
OnRaiseWallAddedEvent(new WallAddedEventArgs(newWall));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteWall(Wall wall)
|
||||||
|
{
|
||||||
|
if (wall is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Walls.TryRemove(wall.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseWallDeletedEvent(new WallDeletedEventArgs(wall));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteOverlay(Overlay overlay)
|
||||||
|
{
|
||||||
|
if (overlay is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseOverlayDeletedEvent(new OverlayDeletedEventArgs(overlay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteTile(Tile tile)
|
||||||
|
{
|
||||||
|
if (tile is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Map.TryRemove(tile.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseTileDeletedEvent(new TileDeletedEventArgs(tile));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnRaiseTileAddedEvent(TileAddedEventArgs e)
|
protected virtual void OnRaiseTileAddedEvent(TileAddedEventArgs e)
|
||||||
{
|
{
|
||||||
// Make a temporary copy of the event to avoid possibility of
|
var raiseEvent = TileAdded;
|
||||||
// a race condition if the last subscriber unsubscribes
|
|
||||||
// immediately after the null check and before the event is raised.
|
|
||||||
EventHandler<TileAddedEventArgs> raiseEvent = RaiseTileAddedEvent;
|
|
||||||
|
|
||||||
// Event will be null if there are no subscribers
|
|
||||||
if (raiseEvent != null)
|
if (raiseEvent != null)
|
||||||
{
|
{
|
||||||
// Call to raise the event.
|
|
||||||
raiseEvent(this, e);
|
raiseEvent(this, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnRaiseOverlayAddedEvent(OverlayAddedEventArgs e)
|
protected virtual void OnRaiseOverlayAddedEvent(OverlayAddedEventArgs e)
|
||||||
{
|
{
|
||||||
// Make a temporary copy of the event to avoid possibility of
|
var raiseEvent = OverlayAdded;
|
||||||
// a race condition if the last subscriber unsubscribes
|
if (raiseEvent != null)
|
||||||
// immediately after the null check and before the event is raised.
|
{
|
||||||
EventHandler<OverlayAddedEventArgs> raiseEvent = RaiseOverlayAddedEvent;
|
raiseEvent(this, e);
|
||||||
|
}
|
||||||
// Event will be null if there are no subscribers
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
if (raiseEvent != null)
|
if (raiseEvent != null)
|
||||||
{
|
{
|
||||||
// Call to raise the event.
|
|
||||||
raiseEvent(this, e);
|
raiseEvent(this, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,17 @@ namespace Sledgemapper
|
||||||
|
|
||||||
[Post("/session/{sessionName}/overlay")]
|
[Post("/session/{sessionName}/overlay")]
|
||||||
Task NewOverlay([Body] Overlay overlay, string sessionName);
|
Task NewOverlay([Body] Overlay overlay, string sessionName);
|
||||||
|
|
||||||
|
[Post("/session/{sessionName}/wall")]
|
||||||
|
Task NewWall([Body] Wall overlay, string sessionName);
|
||||||
|
|
||||||
|
[Delete("/session/{sessionName}/wall")]
|
||||||
|
Task DeleteWall([Body] Wall wall, string sessionName);
|
||||||
|
|
||||||
|
[Delete("/session/{sessionName}/tile")]
|
||||||
|
Task DeleteTile([Body] Tile tile, string sessionName);
|
||||||
|
|
||||||
|
[Delete("/session/{sessionName}/overlay")]
|
||||||
|
Task DeleteOverlay([Body] Overlay overlay, string sessionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
|
@ -37,7 +37,6 @@ namespace Sledgemapper
|
||||||
private string _session;
|
private string _session;
|
||||||
private KeyboardState oldState;
|
private KeyboardState oldState;
|
||||||
private MouseState oldMouseState;
|
private MouseState oldMouseState;
|
||||||
|
|
||||||
private Vector3 _viewportCenter = new Vector3(0, 0, 0);
|
private Vector3 _viewportCenter = new Vector3(0, 0, 0);
|
||||||
private SpriteFont font;
|
private SpriteFont font;
|
||||||
private Dictionary<string, SpriteFont> _fonts;
|
private Dictionary<string, SpriteFont> _fonts;
|
||||||
|
@ -61,7 +60,7 @@ namespace Sledgemapper
|
||||||
Window.AllowUserResizing = true;
|
Window.AllowUserResizing = true;
|
||||||
Players = new List<Player>();
|
Players = new List<Player>();
|
||||||
connection = new HubConnectionBuilder()
|
connection = new HubConnectionBuilder()
|
||||||
// .WithAutomaticReconnect()
|
.WithAutomaticReconnect()
|
||||||
|
|
||||||
.WithUrl("http://localhost:5000/SledgemapperHub")
|
.WithUrl("http://localhost:5000/SledgemapperHub")
|
||||||
|
|
||||||
|
@ -72,25 +71,22 @@ namespace Sledgemapper
|
||||||
|
|
||||||
//if (myConfigurationService.VerifySslCertificate == false)
|
//if (myConfigurationService.VerifySslCertificate == false)
|
||||||
//{
|
//{
|
||||||
httpClientHandler.ServerCertificateCustomValidationCallback =
|
httpClientHandler.ServerCertificateCustomValidationCallback =
|
||||||
(message, certificate, chain, sslPolicyErrors) => true;
|
(message, certificate, chain, sslPolicyErrors) => true;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
_api = RestService.For<IMapApi>(
|
_api = RestService.For<IMapApi>(
|
||||||
new HttpClient(httpClientHandler)
|
new HttpClient(httpClientHandler)
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri ("http://localhost:5000")
|
BaseAddress = new Uri("http://localhost:5000")
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
connection.On<SessionData>("UpdateMap", (map) =>
|
connection.On<SessionData>("UpdateMap", (map) =>
|
||||||
{
|
{
|
||||||
_sessionData.Map = map.Map;
|
_sessionData.Map = map.Map;
|
||||||
_sessionData.Walls = map.Walls;
|
_sessionData.Walls = map.Walls;
|
||||||
_sessionData.Overlays = map.Overlays;
|
_sessionData.Overlays = map.Overlays;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Player>("PlayerUpdate", (player) =>
|
connection.On<Player>("PlayerUpdate", (player) =>
|
||||||
|
@ -104,38 +100,37 @@ namespace Sledgemapper
|
||||||
|
|
||||||
connection.On<Tile>("DeleteTile", (tile) =>
|
connection.On<Tile>("DeleteTile", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Map.Remove(tile.ToString(), out var rtile);
|
_sessionData.Map.Remove(tile.ToString(), out var _);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Wall>("DeleteWall", (tile) =>
|
connection.On<Wall>("DeleteWall", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Walls.Remove(tile.ToString(), out var rtile);
|
_sessionData.Walls.Remove(tile.ToString(), out var _);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Overlay>("DeleteOverlay", (tile) =>
|
connection.On<Overlay>("DeleteOverlay", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Overlays.Remove(tile.ToString(), out var rtile);
|
_sessionData.Overlays.Remove(tile.ToString(), out var _);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Tile>("NewTile", (tile) =>
|
connection.On<Tile>("NewTile", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Map.Remove(tile.ToString(), out var rtile);
|
_sessionData.Map.Remove(tile.ToString(), out var _);
|
||||||
_sessionData.Map.TryAdd(tile.ToString(), tile);
|
_sessionData.Map.TryAdd(tile.ToString(), tile);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Wall>("NewWall", (tile) =>
|
connection.On<Wall>("NewWall", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Walls.Remove(tile.ToString(), out var rtile);
|
_sessionData.Walls.Remove(tile.ToString(), out var _);
|
||||||
_sessionData.Walls.TryAdd(tile.ToString(), tile);
|
_sessionData.Walls.TryAdd(tile.ToString(), tile);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.On<Overlay>("NewOverlay", (tile) =>
|
connection.On<Overlay>("NewOverlay", (tile) =>
|
||||||
{
|
{
|
||||||
_sessionData.Overlays.Remove(tile.ToString(), out var rtile);
|
_sessionData.Overlays.Remove(tile.ToString(), out var _);
|
||||||
_sessionData.Overlays.TryAdd(tile.ToString(), tile);
|
_sessionData.Overlays.TryAdd(tile.ToString(), tile);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
connection.On<Player>("NewPlayer", (player) =>
|
connection.On<Player>("NewPlayer", (player) =>
|
||||||
{
|
{
|
||||||
var p = Players.FirstOrDefault(m => m.ConnectionId == player.ConnectionId);
|
var p = Players.FirstOrDefault(m => m.ConnectionId == player.ConnectionId);
|
||||||
|
@ -166,229 +161,11 @@ namespace Sledgemapper
|
||||||
var menuConnectJoin = new MenuItem("_connect_join", "Join");
|
var menuConnectJoin = new MenuItem("_connect_join", "Join");
|
||||||
var menuConnectSync = new MenuItem("_connect_sync", "Sync");
|
var menuConnectSync = new MenuItem("_connect_sync", "Sync");
|
||||||
|
|
||||||
menuConnectSync.Selected += async (s, e) =>
|
menuConnectSync.Selected += OnMenuConnectSyncSelected;
|
||||||
{
|
menuFileLoad.Selected += OnMenuFileLoadSelected;
|
||||||
await connection?.InvokeAsync("Sync", _session, _sessionData);
|
menuFileSave.Selected += OnMenuFileSaveSelected;
|
||||||
};
|
menuConnectNew.Selected += OnMenuConnectNewSelected;
|
||||||
|
menuConnectJoin.Selected += OnMenuConnectJoinSelected;
|
||||||
menuFileLoad.Selected += (s, e) =>
|
|
||||||
{
|
|
||||||
FileDialog dialog = new FileDialog(FileDialogMode.OpenFile)
|
|
||||||
{
|
|
||||||
Filter = "*.map"
|
|
||||||
//Folder = @"D:\Temp"
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.Closed += (s, a) =>
|
|
||||||
{
|
|
||||||
if (!dialog.Result)
|
|
||||||
{
|
|
||||||
// "Cancel" or Escape
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
using (StreamReader file = File.OpenText(dialog.FilePath))
|
|
||||||
{
|
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
|
||||||
_sessionData = (SessionData)serializer.Deserialize(file, typeof(SessionData));
|
|
||||||
}
|
|
||||||
// "Ok" or Enter
|
|
||||||
// ...
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.ShowModal(_desktop);
|
|
||||||
};
|
|
||||||
|
|
||||||
menuFileSave.Selected += (s, e) =>
|
|
||||||
{
|
|
||||||
FileDialog dialog = new FileDialog(FileDialogMode.SaveFile)
|
|
||||||
{
|
|
||||||
Filter = "*.map"
|
|
||||||
//Folder = @"D:\Temp"
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.Closed += (s, a) =>
|
|
||||||
{
|
|
||||||
if (!dialog.Result)
|
|
||||||
{
|
|
||||||
// "Cancel" or Escape
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
using (StreamWriter file = File.CreateText(dialog.FilePath))
|
|
||||||
{
|
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
|
||||||
serializer.Serialize(file, _sessionData);
|
|
||||||
}
|
|
||||||
// "Ok" or Enter
|
|
||||||
// ...
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.ShowModal(_desktop);
|
|
||||||
};
|
|
||||||
|
|
||||||
menuConnectNew.Selected += (s, e) =>
|
|
||||||
{
|
|
||||||
Window window = new Window
|
|
||||||
{
|
|
||||||
Title = "New mapping session"
|
|
||||||
};
|
|
||||||
var content = new VerticalStackPanel();
|
|
||||||
var grid = new Grid
|
|
||||||
{
|
|
||||||
Width = 200,
|
|
||||||
ShowGridLines = false,
|
|
||||||
ColumnSpacing = 8,
|
|
||||||
RowSpacing = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set partitioning configuration
|
|
||||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
|
|
||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
var sessionNameLabel = new Label { Text = "Session Name:" };
|
|
||||||
var initialsLabel = new Label { Text = "Initials:", GridRow = 1 };
|
|
||||||
var textbox = new TextBox { GridColumn = 1 };
|
|
||||||
var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 };
|
|
||||||
TextButton button = new TextButton
|
|
||||||
{
|
|
||||||
Text = "Start",
|
|
||||||
HorizontalAlignment = HorizontalAlignment.Center
|
|
||||||
};
|
|
||||||
grid.Widgets.Add(textbox);
|
|
||||||
grid.Widgets.Add(initialsTextbox);
|
|
||||||
grid.Widgets.Add(sessionNameLabel);
|
|
||||||
grid.Widgets.Add(initialsLabel);
|
|
||||||
|
|
||||||
content.Widgets.Add(grid);
|
|
||||||
|
|
||||||
button.Click += async (s, e) =>
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(textbox.Text))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (connection.State != HubConnectionState.Connected)
|
|
||||||
{ await connection.StartAsync(); }
|
|
||||||
var successful = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var session = await connection?.InvokeAsync<SessionData>("NewSession", textbox.Text, initialsTextbox.Text);
|
|
||||||
if (session != null)
|
|
||||||
{
|
|
||||||
session.RaiseTileAddedEvent += TileAddedEvent;
|
|
||||||
session.RaiseOverlayAddedEvent += OverlayAddedEvent;
|
|
||||||
Players = session.Players;
|
|
||||||
|
|
||||||
}
|
|
||||||
successful = session != null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
if (successful)
|
|
||||||
{
|
|
||||||
_session = textbox.Text;
|
|
||||||
window.Close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
content.Widgets.Add(button);
|
|
||||||
window.Content = content;
|
|
||||||
|
|
||||||
window.Closed += (s, a) =>
|
|
||||||
{
|
|
||||||
// Called when window is closed
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ShowModal(_desktop);
|
|
||||||
};
|
|
||||||
|
|
||||||
menuConnectJoin.Selected += (s, e) =>
|
|
||||||
{
|
|
||||||
Window window = new Window
|
|
||||||
{
|
|
||||||
Title = "Join mapping session"
|
|
||||||
};
|
|
||||||
var content = new VerticalStackPanel();
|
|
||||||
var grid = new Grid
|
|
||||||
{
|
|
||||||
Width = 200,
|
|
||||||
ShowGridLines = false,
|
|
||||||
ColumnSpacing = 8,
|
|
||||||
RowSpacing = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set partitioning configuration
|
|
||||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
|
|
||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
|
||||||
var sessionNameLabel = new Label { Text = "Session Name:" };
|
|
||||||
var initialsLabel = new Label { Text = "Initials:", GridRow = 1 };
|
|
||||||
var textbox = new TextBox { GridColumn = 1 };
|
|
||||||
var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 };
|
|
||||||
TextButton button = new TextButton
|
|
||||||
{
|
|
||||||
Text = "Start",
|
|
||||||
HorizontalAlignment = HorizontalAlignment.Center
|
|
||||||
};
|
|
||||||
grid.Widgets.Add(textbox);
|
|
||||||
grid.Widgets.Add(initialsTextbox);
|
|
||||||
grid.Widgets.Add(sessionNameLabel);
|
|
||||||
grid.Widgets.Add(initialsLabel);
|
|
||||||
|
|
||||||
content.Widgets.Add(grid);
|
|
||||||
|
|
||||||
// var content = new VerticalStackPanel();
|
|
||||||
// var textbox = new TextBox();
|
|
||||||
// TextButton button = new TextButton
|
|
||||||
// {
|
|
||||||
// Text = "Start",
|
|
||||||
// HorizontalAlignment = HorizontalAlignment.Center
|
|
||||||
// };
|
|
||||||
button.Click += async (s, e) =>
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(textbox.Text))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (connection.State != HubConnectionState.Connected)
|
|
||||||
{ await connection.StartAsync(); }
|
|
||||||
var successful = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await connection?.InvokeAsync<SessionData>("JoinSession", textbox.Text, initialsTextbox.Text);
|
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
_sessionData.Map = result.Map;
|
|
||||||
_sessionData.Walls = result.Walls;
|
|
||||||
_sessionData.Overlays = result.Overlays;
|
|
||||||
Players = result.Players;
|
|
||||||
}
|
|
||||||
successful = result != null; ;
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
if (successful)
|
|
||||||
{
|
|
||||||
_session = textbox.Text;
|
|
||||||
window.Close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//content.Widgets.Add(textbox);
|
|
||||||
content.Widgets.Add(button);
|
|
||||||
window.Content = content;
|
|
||||||
|
|
||||||
window.Closed += (s, a) =>
|
|
||||||
{
|
|
||||||
// Called when window is closed
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ShowModal(_desktop);
|
|
||||||
};
|
|
||||||
|
|
||||||
menuConnect.Items.Add(menuConnectNew);
|
menuConnect.Items.Add(menuConnectNew);
|
||||||
menuConnect.Items.Add(menuConnectJoin);
|
menuConnect.Items.Add(menuConnectJoin);
|
||||||
|
@ -402,7 +179,214 @@ namespace Sledgemapper
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMenuConnectJoinSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Window window = new Window
|
||||||
|
{
|
||||||
|
Title = "Join mapping session"
|
||||||
|
};
|
||||||
|
var content = new VerticalStackPanel();
|
||||||
|
var grid = new Grid
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
ShowGridLines = false,
|
||||||
|
ColumnSpacing = 8,
|
||||||
|
RowSpacing = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set partitioning configuration
|
||||||
|
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
|
||||||
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
var sessionNameLabel = new Label { Text = "Session Name:" };
|
||||||
|
var initialsLabel = new Label { Text = "Initials:", GridRow = 1 };
|
||||||
|
var textbox = new TextBox { GridColumn = 1 };
|
||||||
|
var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 };
|
||||||
|
TextButton button = new TextButton
|
||||||
|
{
|
||||||
|
Text = "Start",
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center
|
||||||
|
};
|
||||||
|
grid.Widgets.Add(textbox);
|
||||||
|
grid.Widgets.Add(initialsTextbox);
|
||||||
|
grid.Widgets.Add(sessionNameLabel);
|
||||||
|
grid.Widgets.Add(initialsLabel);
|
||||||
|
|
||||||
|
content.Widgets.Add(grid);
|
||||||
|
|
||||||
|
button.Click += async (s, e) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textbox.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (connection.State != HubConnectionState.Connected)
|
||||||
|
{ await connection.StartAsync(); }
|
||||||
|
var successful = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await connection?.InvokeAsync<SessionData>("JoinSession", textbox.Text, initialsTextbox.Text);
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
_sessionData.Map = result.Map;
|
||||||
|
_sessionData.Walls = result.Walls;
|
||||||
|
_sessionData.Overlays = result.Overlays;
|
||||||
|
Players = result.Players;
|
||||||
|
}
|
||||||
|
successful = result != null; ;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
if (successful)
|
||||||
|
{
|
||||||
|
_session = textbox.Text;
|
||||||
|
window.Close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
content.Widgets.Add(button);
|
||||||
|
window.Content = content;
|
||||||
|
|
||||||
|
window.ShowModal(_desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Window window = new Window
|
||||||
|
{
|
||||||
|
Title = "New mapping session"
|
||||||
|
};
|
||||||
|
var content = new VerticalStackPanel();
|
||||||
|
var grid = new Grid
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
ShowGridLines = false,
|
||||||
|
ColumnSpacing = 8,
|
||||||
|
RowSpacing = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set partitioning configuration
|
||||||
|
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
|
||||||
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
var sessionNameLabel = new Label { Text = "Session Name:" };
|
||||||
|
var initialsLabel = new Label { Text = "Initials:", GridRow = 1 };
|
||||||
|
var textbox = new TextBox { GridColumn = 1 };
|
||||||
|
var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 };
|
||||||
|
TextButton button = new TextButton
|
||||||
|
{
|
||||||
|
Text = "Start",
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center
|
||||||
|
};
|
||||||
|
grid.Widgets.Add(textbox);
|
||||||
|
grid.Widgets.Add(initialsTextbox);
|
||||||
|
grid.Widgets.Add(sessionNameLabel);
|
||||||
|
grid.Widgets.Add(initialsLabel);
|
||||||
|
|
||||||
|
content.Widgets.Add(grid);
|
||||||
|
|
||||||
|
button.Click += async (s, e) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textbox.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (connection.State != HubConnectionState.Connected)
|
||||||
|
{ await connection.StartAsync(); }
|
||||||
|
var successful = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var session = await connection?.InvokeAsync<SessionData>("NewSession", textbox.Text, initialsTextbox.Text);
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
_sessionData = session;
|
||||||
|
session.TileAdded += OnTileAdded;
|
||||||
|
session.OverlayAdded += OnOverlayAdded;
|
||||||
|
session.WallAdded += OnWallAdded;
|
||||||
|
session.TileDeleted += OnTileDeleted;
|
||||||
|
session.WallDeleted += OnWallDeleted;
|
||||||
|
session.OverlayDeleted += OnOverlayDeleted;
|
||||||
|
Players = session.Players;
|
||||||
|
|
||||||
|
}
|
||||||
|
successful = session != null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
if (successful)
|
||||||
|
{
|
||||||
|
_session = textbox.Text;
|
||||||
|
window.Close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
content.Widgets.Add(button);
|
||||||
|
window.Content = content;
|
||||||
|
|
||||||
|
window.Closed += (s, a) =>
|
||||||
|
{
|
||||||
|
// Called when window is closed
|
||||||
|
};
|
||||||
|
|
||||||
|
window.ShowModal(_desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMenuFileSaveSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FileDialog dialog = new FileDialog(FileDialogMode.SaveFile)
|
||||||
|
{
|
||||||
|
Filter = "*.map"
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.Closed += (s, a) =>
|
||||||
|
{
|
||||||
|
if (!dialog.Result)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamWriter file = File.CreateText(dialog.FilePath))
|
||||||
|
{
|
||||||
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
|
serializer.Serialize(file, _sessionData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.ShowModal(_desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMenuFileLoadSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FileDialog dialog = new FileDialog(FileDialogMode.OpenFile)
|
||||||
|
{
|
||||||
|
Filter = "*.map"
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.Closed += (s, a) =>
|
||||||
|
{
|
||||||
|
if (!dialog.Result)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (StreamReader file = File.OpenText(dialog.FilePath))
|
||||||
|
{
|
||||||
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
|
_sessionData = (SessionData)serializer.Deserialize(file, typeof(SessionData));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.ShowModal(_desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await connection?.InvokeAsync("Sync", _session, _sessionData);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
|
@ -521,7 +505,6 @@ namespace Sledgemapper
|
||||||
|
|
||||||
_fonts = Content.LoadContentFolder<SpriteFont>("fonts");
|
_fonts = Content.LoadContentFolder<SpriteFont>("fonts");
|
||||||
|
|
||||||
|
|
||||||
// Add it to the desktop
|
// Add it to the desktop
|
||||||
// _desktop = new Desktop();
|
// _desktop = new Desktop();
|
||||||
_desktop.Root = mainPanel;
|
_desktop.Root = mainPanel;
|
||||||
|
@ -580,15 +563,15 @@ namespace Sledgemapper
|
||||||
_selectedTile.Y = _hoveredTile.Y;
|
_selectedTile.Y = _hoveredTile.Y;
|
||||||
connection?.SendAsync("UpdatePosition", _session, _selectedTile);
|
connection?.SendAsync("UpdatePosition", _session, _selectedTile);
|
||||||
|
|
||||||
SetTile(_currentTileId);
|
_sessionData.NewTile(_selectedTile, _currentTileId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InsertMode.Wall:
|
case InsertMode.Wall:
|
||||||
|
_sessionData.NewWall(_selectedWall, _currentWallId);
|
||||||
|
|
||||||
SetWall(_currentWallId);
|
|
||||||
break;
|
break;
|
||||||
case InsertMode.Overlay:
|
case InsertMode.Overlay:
|
||||||
SetOverlay(_currentOverlayId);
|
_sessionData.NewOverlay(_selectedOverlay, _currentOverlayId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -622,25 +605,19 @@ namespace Sledgemapper
|
||||||
case InsertMode.Tile:
|
case InsertMode.Tile:
|
||||||
_selectedTile.X = _hoveredTile.X;
|
_selectedTile.X = _hoveredTile.X;
|
||||||
_selectedTile.Y = _hoveredTile.Y;
|
_selectedTile.Y = _hoveredTile.Y;
|
||||||
DeleteTile();
|
_sessionData.DeleteTile(_selectedTile);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InsertMode.Wall:
|
case InsertMode.Wall:
|
||||||
|
_sessionData.DeleteWall(_selectedWall);
|
||||||
DeleteWall();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InsertMode.Overlay:
|
case InsertMode.Overlay:
|
||||||
|
_sessionData.DeleteOverlay(_selectedOverlay);
|
||||||
DeleteOverlay();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var key in newState.GetPressedKeys())
|
foreach (var key in newState.GetPressedKeys())
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case Keys.Left:
|
case Keys.Left:
|
||||||
|
@ -932,83 +909,30 @@ namespace Sledgemapper
|
||||||
_selectedOverlay.Intersection = false;
|
_selectedOverlay.Intersection = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetTile(string tileId)
|
|
||||||
{
|
|
||||||
_sessionData.NewTile(_selectedTile, tileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TileAddedEvent(object sender, TileAddedEventArgs e)
|
private void OnOverlayAdded(object sender, OverlayAddedEventArgs e)
|
||||||
{
|
|
||||||
_api.NewTile(e.Tile, _session);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetOverlay(string tileId)
|
|
||||||
{
|
|
||||||
_sessionData.NewOverlay(_selectedOverlay, tileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OverlayAddedEvent(object sender, OverlayAddedEventArgs e)
|
|
||||||
{
|
{
|
||||||
_api.NewOverlay(e.Overlay, _session);
|
_api.NewOverlay(e.Overlay, _session);
|
||||||
}
|
}
|
||||||
|
private void OnTileAdded(object sender, TileAddedEventArgs e)
|
||||||
private void DeleteWall()
|
|
||||||
{
|
{
|
||||||
var tileExist = _sessionData.Walls.TryGetValue(_selectedWall.ToString(), out var wall);
|
_api.NewTile(e.Tile, _session);
|
||||||
if (tileExist)
|
|
||||||
{
|
|
||||||
//var wall = _sessionData.Walls.First(m => m.X == _selectedWall.X && m.Y == _selectedWall.Y && m.Rotation == _selectedWall.Rotation);
|
|
||||||
//var index = _sessionData.Walls.IndexOf(wall);
|
|
||||||
_sessionData.Walls.TryRemove(wall.ToString(), out var rwall);
|
|
||||||
connection?.InvokeAsync("DeleteWall", _session, wall);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
private void OnWallAdded(object sender, WallAddedEventArgs e)
|
||||||
private void DeleteOverlay()
|
|
||||||
{
|
{
|
||||||
var tileExist = _sessionData.Overlays.TryGetValue(_selectedOverlay.ToString(), out var overlay);
|
_api.NewWall(e.Wall, _session);
|
||||||
if (tileExist)
|
|
||||||
{
|
|
||||||
//var wall = _sessionData.Overlays.First(m => m.X == _selectedOverlay.X && m.Y == _selectedOverlay.Y && m.Intersection == _selectedOverlay.Intersection);
|
|
||||||
//var index = _sessionData.Overlays.IndexOf(wall);
|
|
||||||
_sessionData.Overlays.TryRemove(overlay.ToString(), out var roverlay);
|
|
||||||
connection?.InvokeAsync("DeleteOverlay", _session, overlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
private void OnOverlayDeleted(object sender, OverlayDeletedEventArgs e)
|
||||||
private void DeleteTile()
|
|
||||||
{
|
{
|
||||||
var tileExist = _sessionData.Map.TryGetValue(_selectedTile.ToString(), out var tile);
|
_api.DeleteOverlay(e.Overlay, _session);
|
||||||
if (tileExist)
|
|
||||||
{
|
|
||||||
// var tile = _sessionData.Map.First(m => m.X == _selectedTile.X && m.Y == _selectedTile.Y);
|
|
||||||
// var index = _sessionData.Map.IndexOf(tile);
|
|
||||||
_sessionData.Map.TryRemove(tile.ToString(), out var rtile);
|
|
||||||
connection?.InvokeAsync("DeleteTile", _session, tile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
private void OnTileDeleted(object sender, TileDeletedEventArgs e)
|
||||||
private void SetWall(string wallId)
|
|
||||||
{
|
{
|
||||||
var tileExist = _sessionData.Walls.TryGetValue(_selectedWall.ToString(), out var wall);
|
_api.DeleteTile(e.Tile, _session);
|
||||||
if (tileExist)
|
}
|
||||||
{
|
private void OnWallDeleted(object sender, WallDeletedEventArgs e)
|
||||||
// var wall = _sessionData.Walls.First(m => m.X == _selectedWall.X && m.Y == _selectedWall.Y && m.Rotation == _selectedWall.Rotation);
|
{
|
||||||
// var index = _sessionData.Walls.IndexOf(wall);
|
_api.DeleteWall(e.Wall, _session);
|
||||||
_sessionData.Walls.TryRemove(wall.ToString(), out var rwall);
|
|
||||||
var newWall = new Wall { X = _selectedWall.X, Y = _selectedWall.Y, ID = wallId, Rotation = _selectedWall.Rotation };
|
|
||||||
_sessionData.Walls.TryAdd(newWall.ToString(), newWall);
|
|
||||||
connection?.InvokeAsync("NewWall", _session, newWall);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var newWall = new Wall { X = _selectedWall.X, Y = _selectedWall.Y, ID = wallId, Rotation = _selectedWall.Rotation };
|
|
||||||
_sessionData.Walls.TryAdd(newWall.ToString(), newWall);
|
|
||||||
connection?.InvokeAsync("NewWall", _session, newWall);
|
|
||||||
|
|
||||||
//connection?.InvokeAsync("SendMessage", $"{_selectedTile.X}:{_selectedTile.Y}", tileId.ToString(), _session);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue