bug fixes
This commit is contained in:
parent
2a796509c8
commit
1759f7cd8e
12 changed files with 151 additions and 48 deletions
14
Sledgemapper.Api/Commands/DeleteNoteCommand.cs
Normal file
14
Sledgemapper.Api/Commands/DeleteNoteCommand.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Sledgemapper.Shared.Entities;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class DeleteNoteCommand : BaseCommand<bool>
|
||||
{
|
||||
public Note Note { get; private set; }
|
||||
|
||||
public DeleteNoteCommand(string sessionName, Note note, int userId) : base(sessionName, userId)
|
||||
{
|
||||
Note = note;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace Sledgemapper.Api.Controllers
|
|||
{
|
||||
private readonly IMediator _mediator;
|
||||
private int UserId => int.Parse(HttpContext.User.Identity.Name);
|
||||
|
||||
|
||||
public SessionController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
[HttpPost]
|
||||
|
@ -77,5 +77,11 @@ namespace Sledgemapper.Api.Controllers
|
|||
{
|
||||
await _mediator.Send(new DeleteWallCommand(sessionName, wall, UserId));
|
||||
}
|
||||
|
||||
[HttpDelete("note")]
|
||||
public async Task Delete(string sessionName, [FromBody] Note note)
|
||||
{
|
||||
await _mediator.Send(new DeleteNoteCommand(sessionName, note, UserId));
|
||||
}
|
||||
}
|
||||
}
|
43
Sledgemapper.Api/Handlers/DeleteNoteCommandHandler.cs
Normal file
43
Sledgemapper.Api/Handlers/DeleteNoteCommandHandler.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.Data;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
|
||||
public class DeleteNoteCommandHandler : IRequestHandler<DeleteNoteCommand, bool>
|
||||
{
|
||||
private readonly MyDbContext _dbcontext;
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public DeleteNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
|
||||
public async Task<bool> Handle(DeleteNoteCommand notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize<Note>(notification.Note);
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
|
||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||
{
|
||||
Operation = "D",
|
||||
SessionId = session.SessionId,
|
||||
Type = "N",
|
||||
Timestamp = notification.Timestamp,
|
||||
Object = jsonString,
|
||||
UserId = notification.UserId
|
||||
});
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
await _mediator.Publish(new DeleteNoteNotification(session, notification.Note, notification.UserId));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,10 @@ namespace Sledgemapper.Api.Commands
|
|||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.NewOverlay(overlay, overlay.ID);
|
||||
break;
|
||||
case "N":
|
||||
var note = JsonSerializer.Deserialize<Note>(mapUpdate.Object);
|
||||
mapSession.NewNote(note);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -73,6 +77,10 @@ namespace Sledgemapper.Api.Commands
|
|||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.DeleteOverlay(overlay);
|
||||
break;
|
||||
case "N":
|
||||
var note = JsonSerializer.Deserialize<Note>(mapUpdate.Object);
|
||||
mapSession.DeleteNote(note);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
Sledgemapper.Api/Handlers/SendDeleteNoteMessage.cs
Normal file
22
Sledgemapper.Api/Handlers/SendDeleteNoteMessage.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Sledgemapper.Clients;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Sledgemapper.Api.Hubs;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class SendDeleteNoteMessage : INotificationHandler<DeleteNoteNotification>
|
||||
{
|
||||
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||
|
||||
public SendDeleteNoteMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||
|
||||
public async Task Handle(DeleteNoteNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
await _hub.Clients.Groups(notification.Session.SessionName).DeleteNote(notification.Note);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -142,7 +142,8 @@ namespace Sledgemapper.Api.Hubs
|
|||
foreach (var userSession in userSessions)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId);
|
||||
await Clients.Group(session.SessionName).PlayerUpdate(null); //send remove player
|
||||
|
||||
await Clients.Group(session.SessionName).RemovePlayer(new Player{UserId=userId}); //send remove player
|
||||
_dbContext.SessionUsers.Remove(userSession);
|
||||
}
|
||||
}
|
||||
|
|
14
Sledgemapper.Api/Notifications/DeleteNoteNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/DeleteNoteNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Sledgemapper.Shared.Entities;
|
||||
|
||||
namespace Sledgemapper.Api.Notifications
|
||||
{
|
||||
public class DeleteNoteNotification : BaseNotification
|
||||
{
|
||||
public Note Note { get; private set; }
|
||||
|
||||
public DeleteNoteNotification(Models.Session session, Note note, int userId) : base(session, userId)
|
||||
{
|
||||
Note = note;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -10,10 +10,12 @@ namespace Sledgemapper.Clients
|
|||
Task NewOverlay(Overlay overlay);
|
||||
Task NewNote(Note note);
|
||||
Task DeleteTile(Tile tile);
|
||||
Task DeleteNote(Note note);
|
||||
Task DeleteWall(Wall wall);
|
||||
Task DeleteOverlay(Overlay overlay);
|
||||
Task NewPlayer(Player player);
|
||||
Task PlayerUpdate(Player player);
|
||||
Task RemovePlayer(Player player);
|
||||
Task UpdateMap(Session player);
|
||||
Task RefreshPlayers();
|
||||
}
|
||||
|
|
|
@ -79,6 +79,11 @@ namespace Sledgemapper
|
|||
SessionData.Walls.Remove(tile.ToString(), out var _);
|
||||
});
|
||||
|
||||
Connection.On<Note>("DeleteNote", (tile) =>
|
||||
{
|
||||
SessionData.Notes.Remove(tile.ToString(), out var _);
|
||||
});
|
||||
|
||||
Connection.On<Overlay>("DeleteOverlay", (tile) =>
|
||||
{
|
||||
SessionData.Overlays.Remove(tile.ToString(), out var _);
|
||||
|
@ -98,6 +103,15 @@ namespace Sledgemapper
|
|||
}
|
||||
});
|
||||
|
||||
Connection.On<Player>("RemovePlayer", (player) =>
|
||||
{
|
||||
var p = SessionData.Players.FirstOrDefault(m => m.UserId == player.UserId);
|
||||
if (p != null)
|
||||
{
|
||||
SessionData.Players.Remove(p);
|
||||
}
|
||||
});
|
||||
|
||||
Connection.On<Wall>("NewWall", (tile) =>
|
||||
{
|
||||
SessionData.Walls.Remove(tile.ToString(), out var _);
|
||||
|
|
|
@ -436,7 +436,6 @@ namespace Sledgemapper
|
|||
DrawNotes();
|
||||
DrawGrid(visibleTilesX, visibleTilesY);
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_sessionData.SessionName))
|
||||
{
|
||||
var isoffscreen = IsOffscreen(_state.SelectedTile);
|
||||
|
@ -469,8 +468,6 @@ namespace Sledgemapper
|
|||
var uas = new List<float> { ua1, ua2, ua3, ua4 };
|
||||
if (uas.Any(u => u > 0 && u < 1))
|
||||
{
|
||||
|
||||
|
||||
var ua = uas.Where(u => u > 0 && u < 1).Min();
|
||||
|
||||
var i = uas.IndexOf(ua);
|
||||
|
@ -647,58 +644,38 @@ namespace Sledgemapper
|
|||
{
|
||||
posX = tile.X * _state.TileSize + _state.TileSize / 2f;
|
||||
posY = tile.Y * _state.TileSize + _state.TileSize / 2f;
|
||||
|
||||
// _spriteBatch.Draw(content, new Vector2(posX, posY),null, _settings.OverlayTintColor, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize - 10) / content.Width, SpriteEffects.None, 0);
|
||||
// _spriteBatch.Draw(content, new Vector2(posX, posY),null, _settings.OverlayTintColor, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize - 10) / content.Width, SpriteEffects.None, 0);
|
||||
}
|
||||
_spriteBatch.Draw(content, new Vector2(posX + _state.TileSize / 25, posY + _state.TileSize / 25), null, Color.Black * .2f, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize - 10) / content.Width, SpriteEffects.None, 0);
|
||||
_spriteBatch.Draw(content, new Vector2(posX, posY), null, _settings.OverlayTintColor, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize - 10) / content.Width, SpriteEffects.None, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPlayers()
|
||||
{
|
||||
try
|
||||
foreach (var player in _sessionData.Players.Copy())
|
||||
{
|
||||
foreach (var player in _sessionData.Players.Copy())
|
||||
{
|
||||
|
||||
var color = player.Color.ToColor();
|
||||
_spriteBatch.DrawRectangle(new Rectangle(player.Position.X * _state.TileSize - 4, player.Position.Y * _state.TileSize - 4, _state.TileSize + 7, _state.TileSize + 7), color, 2);
|
||||
|
||||
foreach (var font in _fonts.Keys)
|
||||
{
|
||||
System.Console.WriteLine(font);
|
||||
}
|
||||
|
||||
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
||||
|
||||
var fscale = _state.TileSize / ((float)ffont.LineSpacing * 2);
|
||||
_spriteBatch.DrawString(ffont,
|
||||
player.Initials,
|
||||
new Vector2(player.Position.X * _state.TileSize + 2, player.Position.Y * _state.TileSize + _state.TileSize - 2 - ffont.LineSpacing * fscale),
|
||||
color,
|
||||
0,
|
||||
Vector2.Zero,
|
||||
fscale,
|
||||
SpriteEffects.None,
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
foreach (var player in _sessionData.Players.Copy())
|
||||
{
|
||||
var isOffscreen = IsOffscreen(player.Position);
|
||||
if (isOffscreen)
|
||||
{
|
||||
DrawPlayerPointer(player);
|
||||
}
|
||||
}
|
||||
var color = player.Color.ToColor();
|
||||
_spriteBatch.DrawRectangle(new Rectangle(player.Position.X * _state.TileSize - 4, player.Position.Y * _state.TileSize - 4, _state.TileSize + 7, _state.TileSize + 7), color, 2);
|
||||
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
||||
var fscale = _state.TileSize / ((float)ffont.LineSpacing * 2);
|
||||
_spriteBatch.DrawString(ffont,
|
||||
player.Initials,
|
||||
new Vector2(player.Position.X * _state.TileSize + 2, player.Position.Y * _state.TileSize + _state.TileSize - 2 - ffont.LineSpacing * fscale),
|
||||
color,
|
||||
0,
|
||||
Vector2.Zero,
|
||||
fscale,
|
||||
SpriteEffects.None,
|
||||
0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
foreach (var player in _sessionData.Players.Copy())
|
||||
{
|
||||
System.Console.WriteLine(ex.Message);
|
||||
var isOffscreen = IsOffscreen(player.Position);
|
||||
if (isOffscreen)
|
||||
{
|
||||
DrawPlayerPointer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1209,6 +1186,7 @@ namespace Sledgemapper
|
|||
window.Content = content;
|
||||
|
||||
window.ShowModal(_desktop);
|
||||
content.TxtSession.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void OnMenuConnectLoginSelected(object sender, EventArgs e)
|
||||
|
@ -1248,9 +1226,10 @@ namespace Sledgemapper
|
|||
|
||||
content.BtnRegister.Click += OnButtonRegisterClick;
|
||||
content.BtnLogin.Click += OnButtonLoginClick;
|
||||
|
||||
|
||||
window.Content = content;
|
||||
window.ShowModal(_desktop);
|
||||
content.TxtEmail.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
||||
|
@ -1294,6 +1273,7 @@ namespace Sledgemapper
|
|||
window.Content = content;
|
||||
|
||||
window.ShowModal(_desktop);
|
||||
content.TxtSession.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void OnMenuFileSaveSelected(object sender, EventArgs e)
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace Sledgemapper
|
|||
var color = new Color(int.Parse(hexs[0], System.Globalization.NumberStyles.HexNumber),
|
||||
int.Parse(hexs[1], System.Globalization.NumberStyles.HexNumber),
|
||||
int.Parse(hexs[2], System.Globalization.NumberStyles.HexNumber));
|
||||
System.Console.WriteLine(color);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue