fixed load and overlay flow, missing sync
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9abe30904f
commit
db41143312
10 changed files with 51 additions and 19 deletions
|
@ -8,13 +8,13 @@ namespace Sledgemapper.Api.Commands
|
||||||
public class GetCampaignMapsCommand : IRequest<List<Session>>
|
public class GetCampaignMapsCommand : IRequest<List<Session>>
|
||||||
{
|
{
|
||||||
public double Timestamp { get; private set; }
|
public double Timestamp { get; private set; }
|
||||||
public string CampaignName { get; private set; }
|
public Guid CampaignId { get; private set; }
|
||||||
public string UserId { get; private set; }
|
public string UserId { get; private set; }
|
||||||
|
|
||||||
public GetCampaignMapsCommand(string campaingName, string userId)
|
public GetCampaignMapsCommand(Guid campaignId, string userId)
|
||||||
{
|
{
|
||||||
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
CampaignName = campaingName;
|
CampaignId = campaignId;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Sledgemapper.Shared.Entities;
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Sledgemapper.Api.Commands
|
namespace Sledgemapper.Api.Commands
|
||||||
{
|
{
|
||||||
public class GetMapSnapshotCommand : IRequest<Session>
|
public class GetMapSnapshotCommand : IRequest<Session>
|
||||||
{
|
{
|
||||||
public string SessionName { get; private set; }
|
public Guid MapId { get; private set; }
|
||||||
public GetMapSnapshotCommand(string sessionName)
|
public Guid CampaignId { get; private set;
|
||||||
|
}
|
||||||
|
public GetMapSnapshotCommand(Guid campaignId, Guid mapId)
|
||||||
{
|
{
|
||||||
SessionName = sessionName;
|
MapId = mapId;
|
||||||
|
CampaignId = campaignId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Sledgemapper.Api.Commands;
|
using Sledgemapper.Api.Commands;
|
||||||
using Sledgemapper.Shared.Entities;
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -65,7 +66,7 @@ namespace Sledgemapper.Api.Controllers
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{campaignName}/maps")]
|
[Route("{campaignName}/maps")]
|
||||||
public async Task<List<Session>> GetMaps(string campaignName)
|
public async Task<List<Session>> GetMaps(Guid campaignName)
|
||||||
{
|
{
|
||||||
var result = await _mediator.Send(new GetCampaignMapsCommand(campaignName, UserId.ToString()));
|
var result = await _mediator.Send(new GetCampaignMapsCommand(campaignName, UserId.ToString()));
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -26,9 +26,9 @@ namespace Sledgemapper.Api.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<Session> Get(string campaign, string mapName)
|
public async Task<Session> Get(Guid campaign, Guid mapName)
|
||||||
{
|
{
|
||||||
var result = await _mediator.Send(new GetMapSnapshotCommand(mapName));
|
var result = await _mediator.Send(new GetMapSnapshotCommand(campaign, mapName));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Sledgemapper.Api.Commands;
|
using Sledgemapper.Api.Commands;
|
||||||
using Sledgemapper.Api.Infrastructure.Data;
|
using Sledgemapper.Api.Infrastructure.Data;
|
||||||
|
@ -29,7 +29,20 @@ namespace Sledgemapper.Api.Handlers
|
||||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||||
_dbcontext.Attach(user);
|
_dbcontext.Attach(user);
|
||||||
|
|
||||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignName == command.CampaignName && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
|
|
||||||
|
|
||||||
|
var campaign = await _dbcontext
|
||||||
|
.Campaigns
|
||||||
|
.Where(campaign => campaign.CampaignId == command.CampaignId)
|
||||||
|
.Include(c => c.InvitedUsers)
|
||||||
|
.Include(c => c.Maps)
|
||||||
|
.Include(c => c.Owner)
|
||||||
|
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
|
||||||
|
|
||||||
var maps = campaign.Maps.Select(session => new Session { SessionName = session.SessionName, SessionId = session.SessionId }).ToList();
|
var maps = campaign.Maps.Select(session => new Session { SessionName = session.SessionName, SessionId = session.SessionId }).ToList();
|
||||||
return maps;
|
return maps;
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace Sledgemapper.Api.Commands
|
||||||
Snapshot snapshot;
|
Snapshot snapshot;
|
||||||
double timestamp;
|
double timestamp;
|
||||||
Shared.Entities.Session mapSession;
|
Shared.Entities.Session mapSession;
|
||||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
var session = _dbcontext.Sessions.First(m => m.SessionId == notification.MapId);
|
||||||
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
|
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
|
||||||
if (snapshot is null)
|
if (snapshot is null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,14 @@ namespace Sledgemapper.Api.Handlers
|
||||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||||
_dbcontext.Attach(user);
|
_dbcontext.Attach(user);
|
||||||
|
|
||||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.Campaign && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
|
|
||||||
|
var campaign = await _dbcontext
|
||||||
|
.Campaigns
|
||||||
|
.Where(campaign => campaign.CampaignId == command.Campaign)
|
||||||
|
.Include(c => c.InvitedUsers)
|
||||||
|
.Include(c => c.Maps)
|
||||||
|
.Include(c => c.Owner)
|
||||||
|
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
|
||||||
|
|
||||||
var maps = campaign.Maps.Any(s => s.SessionId == command.SessionId);
|
var maps = campaign.Maps.Any(s => s.SessionId == command.SessionId);
|
||||||
|
|
||||||
|
|
|
@ -75,10 +75,10 @@ namespace Sledgemapper
|
||||||
|
|
||||||
|
|
||||||
[Get("/campaign/{campaignName}/maps")]
|
[Get("/campaign/{campaignName}/maps")]
|
||||||
Task<List<Session>> GetMaps(string campaignName);
|
Task<List<Session>> GetMaps(Guid campaignName);
|
||||||
|
|
||||||
[Get("/map/{campaignName}/{mapName}")]
|
[Get("/map/{campaignName}/{mapName}")]
|
||||||
Task<Session> GetMap(string campaignName, string mapName);
|
Task<Session> GetMap(Guid campaignName, Guid mapName);
|
||||||
|
|
||||||
|
|
||||||
[Post("/campaign/{campaignName}/players/{email}")]
|
[Post("/campaign/{campaignName}/players/{email}")]
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace Sledgemapper.UI
|
||||||
CenterOnTile(obj.X, obj.Y);
|
CenterOnTile(obj.X, obj.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapOpenedMessage(MapOpenedMessage obj)
|
private async void OnMapOpenedMessage(MapOpenedMessage obj)
|
||||||
{
|
{
|
||||||
lblMap.Text = obj.MapName;
|
lblMap.Text = obj.MapName;
|
||||||
MenuConnectSync.Enabled = true;
|
MenuConnectSync.Enabled = true;
|
||||||
|
@ -93,6 +93,13 @@ namespace Sledgemapper.UI
|
||||||
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||||
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
|
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
|
||||||
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
|
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||||
|
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
|
||||||
|
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
|
||||||
|
CommunicationManager.SessionData.Map = serverMap.Map;
|
||||||
|
CommunicationManager.SessionData.Walls = serverMap.Walls;
|
||||||
|
CommunicationManager.SessionData.Notes = serverMap.Notes;
|
||||||
|
CommunicationManager.SessionData.Lines = serverMap.Lines;
|
||||||
|
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnSignalrConnectionUpdateMessage(SignalrConnectionUpdateMessage obj)
|
private async void OnSignalrConnectionUpdateMessage(SignalrConnectionUpdateMessage obj)
|
||||||
|
@ -204,7 +211,7 @@ namespace Sledgemapper.UI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverMap = await CommunicationManager.Api.Session(CommunicationManager.SessionData.SessionName);
|
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
|
||||||
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
|
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
|
||||||
CommunicationManager.SessionData.Map = serverMap.Map;
|
CommunicationManager.SessionData.Map = serverMap.Map;
|
||||||
CommunicationManager.SessionData.Walls = serverMap.Walls;
|
CommunicationManager.SessionData.Walls = serverMap.Walls;
|
||||||
|
|
|
@ -35,14 +35,14 @@ namespace Sledgemapper.UI
|
||||||
{
|
{
|
||||||
State.Instance.MapName = _selectedMap;
|
State.Instance.MapName = _selectedMap;
|
||||||
State.Instance.MapId = _selectedMapId;
|
State.Instance.MapId = _selectedMapId;
|
||||||
var map = CommunicationManager.Api.GetMap(State.Instance.CampaignName, State.Instance.MapName);
|
// var map = CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
|
||||||
Messenger.Publish(new MapOpenedMessage(this) { MapName = State.Instance.MapName });
|
Messenger.Publish(new MapOpenedMessage(this) { MapName = State.Instance.MapName });
|
||||||
this.GetContainingWindow().Close();
|
this.GetContainingWindow().Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadMaps()
|
public async Task LoadMaps()
|
||||||
{
|
{
|
||||||
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignName);
|
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignId);
|
||||||
foreach (var campaign in campaigns)
|
foreach (var campaign in campaigns)
|
||||||
{
|
{
|
||||||
var item = new ListItem();
|
var item = new ListItem();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue