ping on map feature complete
This commit is contained in:
parent
17cce56866
commit
bce97de302
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
@ -0,0 +1,13 @@
|
||||
// using Sledgemapper.Shared.Entities;
|
||||
|
||||
// namespace Sledgemapper.Api.Commands
|
||||
// {
|
||||
// public class PingCommand : BaseCommand<bool>
|
||||
// {
|
||||
// public Ping Location { get; private set; }
|
||||
// public PingCommand(string sessionName, Ping location, int userId) : base(sessionName, userId)
|
||||
// {
|
||||
// Location = location;
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -2,6 +2,7 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -30,6 +31,12 @@ namespace Sledgemapper.Api.Controllers
|
||||
return result;
|
||||
}
|
||||
|
||||
// [HttpPost("ping")]
|
||||
// public async Task Post(string sessionName, [FromBody] Ping pingLocation)
|
||||
// {
|
||||
// await _mediator.Send(new PingCommand(sessionName, pingLocation, UserId));
|
||||
// }
|
||||
|
||||
[HttpPost("snapshot")]
|
||||
public async Task Post(string sessionName, [FromBody] Session session)
|
||||
{
|
||||
@ -60,13 +67,13 @@ namespace Sledgemapper.Api.Controllers
|
||||
await _mediator.Send(new NewNoteCommand(sessionName, note, UserId));
|
||||
}
|
||||
|
||||
[HttpPost("room")]
|
||||
[HttpPost("room")]
|
||||
public async Task Post(string sessionName, [FromBody] Room room)
|
||||
{
|
||||
await _mediator.Send(new NewRoomCommand(sessionName, room, UserId));
|
||||
}
|
||||
|
||||
[HttpPost("line")]
|
||||
[HttpPost("line")]
|
||||
public async Task Post(string sessionName, [FromBody] Line line)
|
||||
{
|
||||
await _mediator.Send(new NewLineCommand(sessionName, line, UserId));
|
||||
|
@ -35,7 +35,5 @@ namespace Sledgemapper.Api.Commands
|
||||
await _mediator.Publish(new NewTileNotification(session, notification.Tile, notification.UserId));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// using MediatR;
|
||||
// using Sledgemapper.Api.Data;
|
||||
// using System.Threading;
|
||||
// using System.Threading.Tasks;
|
||||
// using Sledgemapper.Api.Notifications;
|
||||
// using System.Linq;
|
||||
|
||||
// namespace Sledgemapper.Api.Commands
|
||||
// {
|
||||
// public class PingCommandHandler : IRequestHandler<PingCommand, bool>
|
||||
// {
|
||||
// private readonly MyDbContext _dbcontext;
|
||||
// private readonly IMediator _mediator;
|
||||
|
||||
// public PingCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
// public async Task<bool> Handle(PingCommand notification, CancellationToken cancellationToken)
|
||||
// {
|
||||
// var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
|
||||
|
||||
// await _mediator.Publish(new PingNotification(session, notification.Location, notification.UserId));
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
// }
|
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
@ -0,0 +1,23 @@
|
||||
// using MediatR;
|
||||
// using Microsoft.AspNetCore.SignalR;
|
||||
// using Sledgemapper.Api.Notifications;
|
||||
// using Sledgemapper.Clients;
|
||||
// using System.Threading;
|
||||
// using System.Threading.Tasks;
|
||||
// using Sledgemapper.Api.Hubs;
|
||||
|
||||
// namespace Sledgemapper.Api.Handlers
|
||||
// {
|
||||
// public class SendPingMessage : INotificationHandler<PingNotification>
|
||||
// {
|
||||
// private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||
|
||||
// public SendPingMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||
|
||||
// public async Task Handle(PingNotification notification, CancellationToken cancellationToken)
|
||||
// {
|
||||
|
||||
// await _hub.Clients.Groups(notification.Session.SessionName).Ping(notification.Location, notification.UserId);
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -51,7 +51,7 @@ namespace Sledgemapper.Api.Hubs
|
||||
await Clients.Group(sessionName).NewRoom(room);
|
||||
}
|
||||
|
||||
public async Task NewLine(string sessionName, Line line)
|
||||
public async Task NewLine(string sessionName, Line line)
|
||||
{
|
||||
await Clients.Group(sessionName).NewLine(line);
|
||||
}
|
||||
@ -86,6 +86,15 @@ namespace Sledgemapper.Api.Hubs
|
||||
await Clients.Group(sessionName).DeleteOverlay(tile);
|
||||
}
|
||||
|
||||
public async Task Ping(string sessionName, Tile location)
|
||||
{
|
||||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] };
|
||||
await Clients.Group(sessionName).Ping(new Ping{X=location.X, Y=location.Y, Player=player});
|
||||
}
|
||||
|
||||
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
|
||||
|
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
@ -0,0 +1,14 @@
|
||||
// using Sledgemapper.Shared.Entities;
|
||||
|
||||
// namespace Sledgemapper.Api.Notifications
|
||||
// {
|
||||
// public class PingNotification : BaseNotification
|
||||
// {
|
||||
// public Ping Location { get; private set; }
|
||||
|
||||
// public PingNotification(Models.Session session, Ping location, int userId) : base(session, userId)
|
||||
// {
|
||||
// Location = location;
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -20,5 +20,6 @@ namespace Sledgemapper.Clients
|
||||
Task UpdateMap(Session player);
|
||||
Task RefreshPlayers();
|
||||
Task NewLine(Line line);
|
||||
Task Ping(Ping ping);
|
||||
}
|
||||
}
|
||||
|
450
Sledgemapper.Shared/Easings.cs
Normal file
450
Sledgemapper.Shared/Easings.cs
Normal file
@ -0,0 +1,450 @@
|
||||
|
||||
using System;
|
||||
#if UNITY
|
||||
using UnityEngine;
|
||||
using Math = UnityEngine.Mathf;
|
||||
#endif
|
||||
|
||||
static public class Easings
|
||||
{
|
||||
/// <summary>
|
||||
/// Constant Pi.
|
||||
/// </summary>
|
||||
private const float PI = (float)(float)Math.PI;
|
||||
|
||||
/// <summary>
|
||||
/// Constant Pi / 2.
|
||||
/// </summary>
|
||||
private const float HALFPI =(float) (float)Math.PI / 2.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Easing Functions enumeration
|
||||
/// </summary>
|
||||
public enum Functions
|
||||
{
|
||||
Linear,
|
||||
QuadraticEaseIn,
|
||||
QuadraticEaseOut,
|
||||
QuadraticEaseInOut,
|
||||
CubicEaseIn,
|
||||
CubicEaseOut,
|
||||
CubicEaseInOut,
|
||||
QuarticEaseIn,
|
||||
QuarticEaseOut,
|
||||
QuarticEaseInOut,
|
||||
QuinticEaseIn,
|
||||
QuinticEaseOut,
|
||||
QuinticEaseInOut,
|
||||
SineEaseIn,
|
||||
SineEaseOut,
|
||||
SineEaseInOut,
|
||||
CircularEaseIn,
|
||||
CircularEaseOut,
|
||||
CircularEaseInOut,
|
||||
ExponentialEaseIn,
|
||||
ExponentialEaseOut,
|
||||
ExponentialEaseInOut,
|
||||
ElasticEaseIn,
|
||||
ElasticEaseOut,
|
||||
ElasticEaseInOut,
|
||||
BackEaseIn,
|
||||
BackEaseOut,
|
||||
BackEaseInOut,
|
||||
BounceEaseIn,
|
||||
BounceEaseOut,
|
||||
BounceEaseInOut
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interpolate using the specified function.
|
||||
/// </summary>
|
||||
static public float Interpolate(float p, Functions function)
|
||||
{
|
||||
switch(function)
|
||||
{
|
||||
default:
|
||||
case Functions.Linear: return Linear(p);
|
||||
case Functions.QuadraticEaseOut: return QuadraticEaseOut(p);
|
||||
case Functions.QuadraticEaseIn: return QuadraticEaseIn(p);
|
||||
case Functions.QuadraticEaseInOut: return QuadraticEaseInOut(p);
|
||||
case Functions.CubicEaseIn: return CubicEaseIn(p);
|
||||
case Functions.CubicEaseOut: return CubicEaseOut(p);
|
||||
case Functions.CubicEaseInOut: return CubicEaseInOut(p);
|
||||
case Functions.QuarticEaseIn: return QuarticEaseIn(p);
|
||||
case Functions.QuarticEaseOut: return QuarticEaseOut(p);
|
||||
case Functions.QuarticEaseInOut: return QuarticEaseInOut(p);
|
||||
case Functions.QuinticEaseIn: return QuinticEaseIn(p);
|
||||
case Functions.QuinticEaseOut: return QuinticEaseOut(p);
|
||||
case Functions.QuinticEaseInOut: return QuinticEaseInOut(p);
|
||||
case Functions.SineEaseIn: return SineEaseIn(p);
|
||||
case Functions.SineEaseOut: return SineEaseOut(p);
|
||||
case Functions.SineEaseInOut: return SineEaseInOut(p);
|
||||
case Functions.CircularEaseIn: return CircularEaseIn(p);
|
||||
case Functions.CircularEaseOut: return CircularEaseOut(p);
|
||||
case Functions.CircularEaseInOut: return CircularEaseInOut(p);
|
||||
case Functions.ExponentialEaseIn: return ExponentialEaseIn(p);
|
||||
case Functions.ExponentialEaseOut: return ExponentialEaseOut(p);
|
||||
case Functions.ExponentialEaseInOut: return ExponentialEaseInOut(p);
|
||||
case Functions.ElasticEaseIn: return ElasticEaseIn(p);
|
||||
case Functions.ElasticEaseOut: return ElasticEaseOut(p);
|
||||
case Functions.ElasticEaseInOut: return ElasticEaseInOut(p);
|
||||
case Functions.BackEaseIn: return BackEaseIn(p);
|
||||
case Functions.BackEaseOut: return BackEaseOut(p);
|
||||
case Functions.BackEaseInOut: return BackEaseInOut(p);
|
||||
case Functions.BounceEaseIn: return BounceEaseIn(p);
|
||||
case Functions.BounceEaseOut: return BounceEaseOut(p);
|
||||
case Functions.BounceEaseInOut: return BounceEaseInOut(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the line y = x
|
||||
/// </summary>
|
||||
static public float Linear(float p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the parabola y = x^2
|
||||
/// </summary>
|
||||
static public float QuadraticEaseIn(float p)
|
||||
{
|
||||
return p * p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the parabola y = -x^2 + 2x
|
||||
/// </summary>
|
||||
static public float QuadraticEaseOut(float p)
|
||||
{
|
||||
return -(p * (p - 2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise quadratic
|
||||
/// y = (1/2)((2x)^2) ; [0, 0.5)
|
||||
/// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float QuadraticEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 2 * p * p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (-2 * p * p) + (4 * p) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the cubic y = x^3
|
||||
/// </summary>
|
||||
static public float CubicEaseIn(float p)
|
||||
{
|
||||
return p * p * p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the cubic y = (x - 1)^3 + 1
|
||||
/// </summary>
|
||||
static public float CubicEaseOut(float p)
|
||||
{
|
||||
float f = (p - 1);
|
||||
return f * f * f + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise cubic
|
||||
/// y = (1/2)((2x)^3) ; [0, 0.5)
|
||||
/// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float CubicEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 4 * p * p * p;
|
||||
}
|
||||
else
|
||||
{
|
||||
float f = ((2 * p) - 2);
|
||||
return 0.5f * f * f * f + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the quartic x^4
|
||||
/// </summary>
|
||||
static public float QuarticEaseIn(float p)
|
||||
{
|
||||
return p * p * p * p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the quartic y = 1 - (x - 1)^4
|
||||
/// </summary>
|
||||
static public float QuarticEaseOut(float p)
|
||||
{
|
||||
float f = (p - 1);
|
||||
return f * f * f * (1 - p) + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
// Modeled after the piecewise quartic
|
||||
// y = (1/2)((2x)^4) ; [0, 0.5)
|
||||
// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float QuarticEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 8 * p * p * p * p;
|
||||
}
|
||||
else
|
||||
{
|
||||
float f = (p - 1);
|
||||
return -8 * f * f * f * f + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the quintic y = x^5
|
||||
/// </summary>
|
||||
static public float QuinticEaseIn(float p)
|
||||
{
|
||||
return p * p * p * p * p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the quintic y = (x - 1)^5 + 1
|
||||
/// </summary>
|
||||
static public float QuinticEaseOut(float p)
|
||||
{
|
||||
float f = (p - 1);
|
||||
return f * f * f * f * f + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise quintic
|
||||
/// y = (1/2)((2x)^5) ; [0, 0.5)
|
||||
/// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float QuinticEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 16 * p * p * p * p * p;
|
||||
}
|
||||
else
|
||||
{
|
||||
float f = ((2 * p) - 2);
|
||||
return 0.5f * f * f * f * f * f + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after quarter-cycle of sine wave
|
||||
/// </summary>
|
||||
static public float SineEaseIn(float p)
|
||||
{
|
||||
return (float)(float)Math.Sin((p - 1) * HALFPI) + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after quarter-cycle of sine wave (different phase)
|
||||
/// </summary>
|
||||
static public float SineEaseOut(float p)
|
||||
{
|
||||
return (float)(float)Math.Sin(p * HALFPI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after half sine wave
|
||||
/// </summary>
|
||||
static public float SineEaseInOut(float p)
|
||||
{
|
||||
return 0.5f * (1 - (float)(float)Math.Cos(p * PI));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after shifted quadrant IV of unit circle
|
||||
/// </summary>
|
||||
static public float CircularEaseIn(float p)
|
||||
{
|
||||
return 1 - (float)Math.Sqrt(1 - (p * p));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after shifted quadrant II of unit circle
|
||||
/// </summary>
|
||||
static public float CircularEaseOut(float p)
|
||||
{
|
||||
return (float)Math.Sqrt((2 - p) * p);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise circular function
|
||||
/// y = (1/2)(1 - (float)Math.Sqrt(1 - 4x^2)) ; [0, 0.5)
|
||||
/// y = (1/2)((float)Math.Sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float CircularEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 0.5f * (1 - (float)Math.Sqrt(1 - 4 * (p * p)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.5f * ((float)Math.Sqrt(-((2 * p) - 3) * ((2 * p) - 1)) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the exponential function y = 2^(10(x - 1))
|
||||
/// </summary>
|
||||
static public float ExponentialEaseIn(float p)
|
||||
{
|
||||
return (p == 0.0f) ? p : (float)Math.Pow(2, 10 * (p - 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the exponential function y = -2^(-10x) + 1
|
||||
/// </summary>
|
||||
static public float ExponentialEaseOut(float p)
|
||||
{
|
||||
return (p == 1.0f) ? p : 1 - (float)Math.Pow(2, -10 * p);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise exponential
|
||||
/// y = (1/2)2^(10(2x - 1)) ; [0,0.5)
|
||||
/// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
|
||||
/// </summary>
|
||||
static public float ExponentialEaseInOut(float p)
|
||||
{
|
||||
if(p == 0.0 || p == 1.0) return p;
|
||||
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 0.5f * (float)Math.Pow(2, (20 * p) - 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -0.5f * (float)Math.Pow(2, (-20 * p) + 10) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the damped sine wave y = sin(13pi/2*x)*(float)Math.Pow(2, 10 * (x - 1))
|
||||
/// </summary>
|
||||
static public float ElasticEaseIn(float p)
|
||||
{
|
||||
return (float)Math.Sin(13 * HALFPI * p) * (float)Math.Pow(2, 10 * (p - 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*(float)Math.Pow(2, -10x) + 1
|
||||
/// </summary>
|
||||
static public float ElasticEaseOut(float p)
|
||||
{
|
||||
return (float)Math.Sin(-13 * HALFPI * (p + 1)) * (float)Math.Pow(2, -10 * p) + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise exponentially-damped sine wave:
|
||||
/// y = (1/2)*sin(13pi/2*(2*x))*(float)Math.Pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
|
||||
/// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*(float)Math.Pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float ElasticEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 0.5f * (float)Math.Sin(13 * HALFPI * (2 * p)) * (float)Math.Pow(2, 10 * ((2 * p) - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.5f * ((float)Math.Sin(-13 * HALFPI * ((2 * p - 1) + 1)) * (float)Math.Pow(2, -10 * (2 * p - 1)) + 2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the overshooting cubic y = x^3-x*sin(x*pi)
|
||||
/// </summary>
|
||||
static public float BackEaseIn(float p)
|
||||
{
|
||||
return p * p * p - p * (float)Math.Sin(p * PI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
|
||||
/// </summary>
|
||||
static public float BackEaseOut(float p)
|
||||
{
|
||||
float f = (1 - p);
|
||||
return 1 - (f * f * f - f * (float)Math.Sin(f * PI));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modeled after the piecewise overshooting cubic function:
|
||||
/// y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5)
|
||||
/// y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
|
||||
/// </summary>
|
||||
static public float BackEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
float f = 2 * p;
|
||||
return 0.5f * (f * f * f - f * (float)Math.Sin(f * PI));
|
||||
}
|
||||
else
|
||||
{
|
||||
float f = (1 - (2*p - 1));
|
||||
return 0.5f * (1 - (f * f * f - f * (float)Math.Sin(f * PI))) + 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
static public float BounceEaseIn(float p)
|
||||
{
|
||||
return 1 - BounceEaseOut(1 - p);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
static public float BounceEaseOut(float p)
|
||||
{
|
||||
if(p < 4/11.0f)
|
||||
{
|
||||
return (121 * p * p)/16.0f;
|
||||
}
|
||||
else if(p < 8/11.0f)
|
||||
{
|
||||
return (363/40.0f * p * p) - (99/10.0f * p) + 17/5.0f;
|
||||
}
|
||||
else if(p < 9/10.0f)
|
||||
{
|
||||
return (4356/361.0f * p * p) - (35442/1805.0f * p) + 16061/1805.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (54/5.0f * p * p) - (513/25.0f * p) + 268/25.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
static public float BounceEaseInOut(float p)
|
||||
{
|
||||
if(p < 0.5f)
|
||||
{
|
||||
return 0.5f * BounceEaseIn(p*2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.5f * BounceEaseOut(p * 2 - 1) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,11 @@ namespace Sledgemapper.Shared.Entities
|
||||
Overlays = new ConcurrentDictionary<string, Overlay>();
|
||||
Walls = new ConcurrentDictionary<string, Wall>();
|
||||
Notes = new ConcurrentDictionary<string, Note>();
|
||||
Lines=new ConcurrentDictionary<string, Line>();
|
||||
Rooms=new ConcurrentDictionary<string, Room>();
|
||||
Lines = new ConcurrentDictionary<string, Line>();
|
||||
Rooms = new ConcurrentDictionary<string, Room>();
|
||||
Players = new List<Player>();
|
||||
Colors = new List<string>();
|
||||
Pings = new ConcurrentDictionary<Guid, Ping>();
|
||||
}
|
||||
|
||||
public ConcurrentDictionary<string, Tile> Map { get; set; }
|
||||
@ -39,189 +40,190 @@ namespace Sledgemapper.Shared.Entities
|
||||
public ConcurrentDictionary<string, Note> Notes { get; set; }
|
||||
public bool IsValid { get; set; }
|
||||
public List<Player> Players { get; set; }
|
||||
public List<string> Colors { get; set; }
|
||||
public string SessionName { get; set; }
|
||||
public int SessionId { get; set; }
|
||||
public ConcurrentDictionary<string, Line> Lines { get; set; }
|
||||
public ConcurrentDictionary<string, Room> Rooms { get; set; }
|
||||
public ConcurrentDictionary<Guid, Ping> Pings { get; set; }
|
||||
public List<string> Colors { get; set; }
|
||||
public string SessionName { get; set; }
|
||||
public int SessionId { get; set; }
|
||||
public ConcurrentDictionary<string, Line> Lines { get; set; }
|
||||
public ConcurrentDictionary<string, Room> Rooms { get; set; }
|
||||
|
||||
public void NewTile(Tile selectedTile, string tileId)
|
||||
public void NewTile(Tile selectedTile, string tileId)
|
||||
{
|
||||
if (selectedTile is null || string.IsNullOrWhiteSpace(tileId))
|
||||
{
|
||||
if (selectedTile is null || string.IsNullOrWhiteSpace(tileId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
||||
var newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
||||
if (tileExist)
|
||||
{
|
||||
Map.TryRemove(tile.ToString(), out var _);
|
||||
if (tile.ID == tileId)
|
||||
{
|
||||
newTile.Rotation = (tile.Rotation + 1) % 4;
|
||||
}
|
||||
}
|
||||
|
||||
Map.TryAdd(newTile.ToString(), newTile);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
|
||||
return;
|
||||
}
|
||||
|
||||
public void NewOverlay(Overlay selectedOverlay, string overlayId)
|
||||
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
||||
var newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
||||
if (tileExist)
|
||||
{
|
||||
if (selectedOverlay is null || string.IsNullOrWhiteSpace(overlayId))
|
||||
Map.TryRemove(tile.ToString(), out var _);
|
||||
if (tile.ID == tileId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
||||
var newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = overlayId, Intersection = selectedOverlay.Intersection };
|
||||
if (overlayExist)
|
||||
{
|
||||
Overlays.TryRemove(overlay.ToString(), out var _);
|
||||
if (overlay.ID == overlayId)
|
||||
{
|
||||
newOverlay.Rotation = (overlay.Rotation + 1) % 4;
|
||||
}
|
||||
}
|
||||
|
||||
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(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);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newWall));
|
||||
}
|
||||
|
||||
public void NewNote(Note selectedNote)
|
||||
{
|
||||
if (selectedNote is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var noteExists = Notes.TryGetValue(selectedNote.ToString(), out var note);
|
||||
var newNote = new Note { X = selectedNote.X, Y = selectedNote.Y, Text=selectedNote.Text };
|
||||
if (noteExists)
|
||||
{
|
||||
Walls.TryRemove(note.ToString(), out var _);
|
||||
}
|
||||
|
||||
Notes.TryAdd(newNote.ToString(), newNote);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newNote));
|
||||
}
|
||||
|
||||
public void DeleteWall(Wall wall)
|
||||
{
|
||||
if (wall is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Walls.TryRemove(wall.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(wall));
|
||||
newTile.Rotation = (tile.Rotation + 1) % 4;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteNote(Note note)
|
||||
Map.TryAdd(newTile.ToString(), newTile);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
|
||||
}
|
||||
|
||||
public void NewOverlay(Overlay selectedOverlay, string overlayId)
|
||||
{
|
||||
if (selectedOverlay is null || string.IsNullOrWhiteSpace(overlayId))
|
||||
{
|
||||
if (note is null)
|
||||
return;
|
||||
}
|
||||
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
||||
var newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = overlayId, Intersection = selectedOverlay.Intersection };
|
||||
if (overlayExist)
|
||||
{
|
||||
Overlays.TryRemove(overlay.ToString(), out var _);
|
||||
if (overlay.ID == overlayId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Notes.TryRemove(note.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(note));
|
||||
newOverlay.Rotation = (overlay.Rotation + 1) % 4;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteOverlay(Overlay overlay)
|
||||
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newOverlay));
|
||||
}
|
||||
|
||||
public void NewWall(Wall selectedWall, string wallId)
|
||||
{
|
||||
if (selectedWall is null || string.IsNullOrWhiteSpace(wallId))
|
||||
{
|
||||
if (overlay is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(overlay));
|
||||
}
|
||||
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 _);
|
||||
}
|
||||
|
||||
public void DeleteTile(Tile tile)
|
||||
Walls.TryAdd(newWall.ToString(), newWall);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newWall));
|
||||
}
|
||||
|
||||
public void NewNote(Note selectedNote)
|
||||
{
|
||||
if (selectedNote is null)
|
||||
{
|
||||
if (tile is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Map.TryRemove(tile.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(tile));
|
||||
}
|
||||
return;
|
||||
}
|
||||
var noteExists = Notes.TryGetValue(selectedNote.ToString(), out var note);
|
||||
var newNote = new Note { X = selectedNote.X, Y = selectedNote.Y, Text = selectedNote.Text };
|
||||
if (noteExists)
|
||||
{
|
||||
Walls.TryRemove(note.ToString(), out var _);
|
||||
}
|
||||
|
||||
protected virtual void OnRaiseMapEntityAddedEvent(MapEntityAddedEventArgs e)
|
||||
Notes.TryAdd(newNote.ToString(), newNote);
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newNote));
|
||||
}
|
||||
|
||||
public void DeleteWall(Wall wall)
|
||||
{
|
||||
if (wall is null)
|
||||
{
|
||||
MapEntityAdded?.Invoke(this, e);
|
||||
return;
|
||||
}
|
||||
|
||||
protected virtual void OnRaiseMapEntityDeletedEvent(MapEntityDeletedEventArgs e)
|
||||
var removed = Walls.TryRemove(wall.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
MapEntityDeleted?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public void NewLine(Line line)
|
||||
{
|
||||
if (line is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lineExist = Lines.TryGetValue(line.ToString(), out var tile);
|
||||
var newLine = new Line { Start=line.Start, End=line.End, Width=line.Width};
|
||||
if (lineExist)
|
||||
{
|
||||
Lines.TryRemove(line.ToString(), out var _);
|
||||
}
|
||||
|
||||
Lines.TryAdd(newLine.ToString(), newLine);
|
||||
|
||||
//TODO fix this
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||
}
|
||||
|
||||
public void NewRoom(Room line)
|
||||
{
|
||||
if (line is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lineExist = Rooms.TryGetValue(line.ToString(), out var tile);
|
||||
var newLine = new Room { Start=line.Start, End=line.End, Delete=line.Delete};
|
||||
if (lineExist)
|
||||
{
|
||||
Rooms.TryRemove(line.ToString(), out var _);
|
||||
}
|
||||
|
||||
Rooms.TryAdd(newLine.ToString(), newLine);
|
||||
|
||||
//TODO fix this
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(wall));
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteNote(Note note)
|
||||
{
|
||||
if (note is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Notes.TryRemove(note.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(note));
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteOverlay(Overlay overlay)
|
||||
{
|
||||
if (overlay is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(overlay));
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteTile(Tile tile)
|
||||
{
|
||||
if (tile is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var removed = Map.TryRemove(tile.ToString(), out var _);
|
||||
if (removed)
|
||||
{
|
||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(tile));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnRaiseMapEntityAddedEvent(MapEntityAddedEventArgs e)
|
||||
{
|
||||
MapEntityAdded?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnRaiseMapEntityDeletedEvent(MapEntityDeletedEventArgs e)
|
||||
{
|
||||
MapEntityDeleted?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public void NewLine(Line line)
|
||||
{
|
||||
if (line is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lineExist = Lines.TryGetValue(line.ToString(), out var tile);
|
||||
var newLine = new Line { Start = line.Start, End = line.End, Width = line.Width };
|
||||
if (lineExist)
|
||||
{
|
||||
Lines.TryRemove(line.ToString(), out var _);
|
||||
}
|
||||
|
||||
Lines.TryAdd(newLine.ToString(), newLine);
|
||||
|
||||
//TODO fix this
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||
}
|
||||
|
||||
public void NewRoom(Room line)
|
||||
{
|
||||
if (line is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lineExist = Rooms.TryGetValue(line.ToString(), out var tile);
|
||||
var newLine = new Room { Start = line.Start, End = line.End, Delete = line.Delete };
|
||||
if (lineExist)
|
||||
{
|
||||
Rooms.TryRemove(line.ToString(), out var _);
|
||||
}
|
||||
|
||||
Rooms.TryAdd(newLine.ToString(), newLine);
|
||||
|
||||
//TODO fix this
|
||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,13 @@ namespace Sledgemapper.Shared.Entities
|
||||
public double Timestamp { get; set; }
|
||||
}
|
||||
|
||||
public class Ping : BaseMapEntity
|
||||
{
|
||||
public Player Player { get; set; }
|
||||
public int Iterations {get;set;}
|
||||
public double StartTime {get;set;}
|
||||
}
|
||||
|
||||
public class Tile : BaseMapEntity
|
||||
{
|
||||
|
||||
|
@ -155,6 +155,11 @@ namespace Sledgemapper
|
||||
p.Position = player.Position;
|
||||
}
|
||||
});
|
||||
|
||||
Connection.On<Ping>("Ping", (ping) =>
|
||||
{
|
||||
SessionData.Pings.TryAdd(Guid.NewGuid(), ping);
|
||||
});
|
||||
}
|
||||
|
||||
private Task<string> GetToken()
|
||||
@ -233,6 +238,14 @@ namespace Sledgemapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal async Task Ping(Tile hoveredTile)
|
||||
{
|
||||
if (Connection!=null && Connection.State == HubConnectionState.Connected)
|
||||
{
|
||||
await Connection.InvokeAsync("Ping",SessionData.SessionName, hoveredTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AuthenticatedHttpClientHandler : HttpClientHandler
|
||||
|
@ -93,6 +93,23 @@
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:fonts/font99.spritefont
|
||||
|
||||
#begin handcursors
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:handcursors
|
||||
|
||||
#begin handcursorsIndex
|
||||
/importer:XmlImporter
|
||||
/processor:
|
||||
/build:handcursorsIndex
|
||||
|
||||
#begin icon_delete.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
@ -141,6 +158,23 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:location.png
|
||||
|
||||
#begin rippleSpriteIndex
|
||||
/importer:XmlImporter
|
||||
/processor:PassThroughProcessor
|
||||
/build:rippleSpriteIndex
|
||||
|
||||
#begin rippleSpriteMap
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:rippleSpriteMap
|
||||
|
||||
#begin shaders/OutlineShader.fx
|
||||
/importer:EffectImporter
|
||||
/processor:EffectProcessor
|
||||
@ -380,30 +414,6 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall01.png
|
||||
|
||||
#begin walls/wall01.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall01.png
|
||||
|
||||
#begin walls/wall02.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall02.png
|
||||
|
||||
#begin walls/wall02.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
@ -428,18 +438,6 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall03.png
|
||||
|
||||
#begin walls/wall03.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall03.png
|
||||
|
||||
#begin walls/wall04.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
@ -452,30 +450,6 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall04.png
|
||||
|
||||
#begin walls/wall04.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall04.png
|
||||
|
||||
#begin walls/wall05.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:walls/wall05.png
|
||||
|
||||
#begin walls/wall05.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
|
BIN
Sledgemapper/Content/handcursors
Normal file
BIN
Sledgemapper/Content/handcursors
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
Sledgemapper/Content/handcursors.png
Normal file
BIN
Sledgemapper/Content/handcursors.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 349 B |
7
Sledgemapper/Content/handcursorsIndex
Normal file
7
Sledgemapper/Content/handcursorsIndex
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<XnaContent>
|
||||
<Asset Type="System.Collections.Generic.Dictionary[System.String, Microsoft.Xna.Framework.Rectangle]">
|
||||
<Item><Key>handcursor_00</Key><Value>0 0 60 60</Value></Item>
|
||||
<Item><Key>handcursor_01</Key><Value>61 0 60 60</Value></Item>
|
||||
</Asset>
|
||||
</XnaContent>
|
24
Sledgemapper/Content/rippleSpriteIndex
Normal file
24
Sledgemapper/Content/rippleSpriteIndex
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<XnaContent>
|
||||
<Asset Type="System.Collections.Generic.Dictionary[System.String, Microsoft.Xna.Framework.Rectangle]">
|
||||
<Item><Key>ripple_00</Key><Value>0 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_01</Key><Value>129 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_02</Key><Value>258 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_03</Key><Value>0 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_04</Key><Value>129 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_05</Key><Value>0 258 128 128</Value></Item>
|
||||
<Item><Key>ripple_06</Key><Value>129 258 128 128</Value></Item>
|
||||
<Item><Key>ripple_07</Key><Value>258 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_08</Key><Value>258 258 128 128</Value></Item>
|
||||
<Item><Key>ripple_09</Key><Value>387 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_10</Key><Value>387 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_11</Key><Value>516 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_12</Key><Value>387 258 128 128</Value></Item>
|
||||
<Item><Key>ripple_13</Key><Value>516 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_14</Key><Value>645 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_15</Key><Value>774 0 128 128</Value></Item>
|
||||
<Item><Key>ripple_16</Key><Value>645 129 128 128</Value></Item>
|
||||
<Item><Key>ripple_17</Key><Value>516 258 128 128</Value></Item>
|
||||
<Item><Key>ripple_18</Key><Value>645 258 128 128</Value></Item>
|
||||
</Asset>
|
||||
</XnaContent>
|
BIN
Sledgemapper/Content/rippleSpriteMap
Normal file
BIN
Sledgemapper/Content/rippleSpriteMap
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGame.Extended;
|
||||
using MonoGame.Extended.VectorDraw;
|
||||
using Myra;
|
||||
using Myra.Graphics2D.Brushes;
|
||||
using Myra.Graphics2D.TextureAtlases;
|
||||
@ -24,6 +25,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AsyncAwaitBestPractices;
|
||||
|
||||
namespace Sledgemapper
|
||||
{
|
||||
@ -177,6 +179,7 @@ namespace Sledgemapper
|
||||
_lblOverlayName.Visible = false;
|
||||
}
|
||||
|
||||
private SpriteSheet _rippleSpriteSheet;
|
||||
Label _lblOverlayName;
|
||||
|
||||
private void OnTileButtonTouchEntered(object sender, EventArgs e)
|
||||
@ -221,7 +224,10 @@ namespace Sledgemapper
|
||||
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
|
||||
|
||||
_spriteSheet = new SpriteSheet();
|
||||
_spriteSheet.LoadContent(Content);
|
||||
_spriteSheet.LoadContent(Content, "spriteIndex", "sprites");
|
||||
_rippleSpriteSheet = new SpriteSheet();
|
||||
_rippleSpriteSheet.LoadContent(Content, "handcursorsIndex", "handcursors");
|
||||
|
||||
_lblOverlayName = new Label();
|
||||
_lblOverlayName.Background = new SolidBrush(Color.SlateGray);
|
||||
_lblOverlayName.Padding = new Myra.Graphics2D.Thickness(4);
|
||||
@ -375,6 +381,7 @@ namespace Sledgemapper
|
||||
window.ShowModal(_desktop);
|
||||
noteWindow.NoteText.SetKeyboardFocus();
|
||||
}
|
||||
private bool _showRipple = false;
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
@ -619,6 +626,17 @@ namespace Sledgemapper
|
||||
}
|
||||
}
|
||||
|
||||
if (oldState.IsKeyDown(Keys.LeftShift) && newState.IsKeyUp(Keys.LeftShift))
|
||||
{
|
||||
_communicationManager.Ping(_state.HoveredTile).SafeFireAndForget();
|
||||
|
||||
_sessionData.Pings.TryAdd(Guid.NewGuid(),new Ping{
|
||||
X=_state.HoveredTile.X,
|
||||
Y=_state.HoveredTile.Y,
|
||||
Player=new Player{Color=Color.Purple.ToHexString()}
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var key in newState.GetPressedKeys())
|
||||
{
|
||||
switch (key)
|
||||
@ -688,7 +706,7 @@ namespace Sledgemapper
|
||||
|
||||
_spriteBatch.Begin(
|
||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
||||
sortMode: SpriteSortMode.Texture);
|
||||
sortMode: SpriteSortMode.Texture, samplerState: SamplerState.PointClamp);
|
||||
|
||||
DrawTiles();
|
||||
|
||||
@ -711,8 +729,10 @@ namespace Sledgemapper
|
||||
DrawLinePreview();
|
||||
|
||||
DrawRoomPreview();
|
||||
|
||||
_spriteBatch.End();
|
||||
DrawRipple(gameTime);
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
@ -724,6 +744,83 @@ namespace Sledgemapper
|
||||
}
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
private int _rippleFrameIndex = 0;
|
||||
|
||||
|
||||
private void DrawRipple(GameTime gameTime)
|
||||
{
|
||||
_spriteBatch.Begin(
|
||||
blendState: BlendState.NonPremultiplied,
|
||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter));
|
||||
|
||||
var durationMs = 2000;
|
||||
var baseRadius = _state.TileSize / 4f;
|
||||
var baseOuterRadius = (float)_state.TileSize;
|
||||
var iterations = 3f;
|
||||
var guids = _sessionData.Pings.Keys.ToArray();
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var pingFound = _sessionData.Pings.TryGetValue(guid, out var ping);
|
||||
if (!pingFound)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ping.StartTime == 0)
|
||||
{
|
||||
ping.StartTime = gameTime.TotalGameTime.TotalMilliseconds;
|
||||
}
|
||||
|
||||
var x = ping.X * _state.TileSize + _state.TileSize / 2f;
|
||||
var y = ping.Y * _state.TileSize + _state.TileSize / 2f;
|
||||
|
||||
if (IsOffscreen(new Tile { X = ping.X, Y = ping.Y }))
|
||||
{
|
||||
DrawPingPointer(ping, gameTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_spriteBatch.DrawCircle(
|
||||
center: new Vector2(x, y),
|
||||
radius: baseRadius,
|
||||
sides: 20,
|
||||
color: ping.Player.Color.ToColor(),
|
||||
thickness: baseRadius);
|
||||
|
||||
for (var i = 0; i < iterations; i++)
|
||||
{
|
||||
var cycleTime = (((float)gameTime.TotalGameTime.TotalMilliseconds + (float)i * durationMs / iterations) % durationMs) / durationMs;
|
||||
var easing = Easings.Interpolate(cycleTime, Easings.Functions.SineEaseInOut);
|
||||
_spriteBatch.DrawCircle(
|
||||
center: new Vector2(x, y),
|
||||
radius: baseRadius + baseOuterRadius * easing,
|
||||
sides: 20,
|
||||
color: new Color(ping.Player.Color.ToColor(), (1 - easing)),
|
||||
thickness: 2 + 5 * (1 - easing));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var pingFound = _sessionData.Pings.TryGetValue(guid, out var ping);
|
||||
if (!pingFound)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((gameTime.TotalGameTime.TotalMilliseconds - ping.StartTime) > 20000 )
|
||||
{
|
||||
_sessionData.Pings.TryRemove(guid, out var _);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawRoomPreview()
|
||||
{
|
||||
@ -1440,6 +1537,106 @@ namespace Sledgemapper
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPingPointer(Ping ping, GameTime gameTime)
|
||||
{
|
||||
var durationMs = 2000f;
|
||||
var baseRadius = _state.TileSize / 4f;
|
||||
var baseOuterRadius = (float)_state.TileSize;
|
||||
var iterations = 3f;
|
||||
|
||||
|
||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
||||
|
||||
var cx = center.X / _state.TileSize;
|
||||
var cy = center.Y / _state.TileSize;
|
||||
|
||||
var p1 = new Vector2(cx * _state.TileSize, cy * _state.TileSize);
|
||||
var p2 = new Vector2(ping.X * _state.TileSize, ping.Y * _state.TileSize);
|
||||
|
||||
var p3 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
var p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua1 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
var ua2 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
p4 = new Vector2(200 - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua3 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua4 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
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);
|
||||
var x = (p1.X + ua * (p2.X - p1.X));
|
||||
var y = (p1.Y + ua * (p2.Y - p1.Y));
|
||||
Vector2[] vertexes = new Vector2[0];
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 20, y + 10), new Vector2(x - 20, y - 10), new Vector2(x, y) };
|
||||
break;
|
||||
case 1:
|
||||
y += 20;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y + 20), new Vector2(x + 10, y + 20), new Vector2(x, y) };
|
||||
break;
|
||||
case 2:
|
||||
x += 0;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x + 20, y + 10), new Vector2(x + 20, y - 10), new Vector2(x, y) };
|
||||
break;
|
||||
case 3:
|
||||
y -= 20;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y - 20), new Vector2(x + 10, y - 20), new Vector2(x, y) };
|
||||
break;
|
||||
}
|
||||
|
||||
_spriteBatch.DrawPolygon(Vector2.Zero, vertexes, ping.Player.Color.ToColor(), 4);
|
||||
|
||||
|
||||
for (var j = 0; j < iterations; j++)
|
||||
{
|
||||
var cycleTime = (((float)gameTime.TotalGameTime.TotalMilliseconds + (float)j * durationMs / iterations) % durationMs) / durationMs;
|
||||
var easing = Easings.Interpolate(cycleTime, Easings.Functions.SineEaseInOut);
|
||||
var v2 = new Vector2[vertexes.Length];
|
||||
|
||||
|
||||
var tCenter = new Vector2((vertexes[0].X + vertexes[1].X + vertexes[2].X) / 3f, (vertexes[0].Y + vertexes[1].Y + vertexes[2].Y) / 3f);
|
||||
|
||||
// var v1s = ((v2[0].X-tCenter.X)*(2 * (1 - easing)))+tCenter.X
|
||||
|
||||
for (int i1 = 0; i1 < v2.Length; i1++)
|
||||
{
|
||||
|
||||
var svx = ((vertexes[i1].X - tCenter.X) * (1 + (2 * easing))) + tCenter.X;
|
||||
var svy = ((vertexes[i1].Y - tCenter.Y) * (1 + (2 * easing))) + tCenter.Y;
|
||||
v2[i1] = new Vector2(svx, svy);
|
||||
}
|
||||
|
||||
_spriteBatch.DrawPolygon(
|
||||
offset: Vector2.Zero,
|
||||
points: v2,
|
||||
color:new Color(ping.Player.Color.ToColor(), 1f-easing),
|
||||
thickness: 2+2*(1-easing));
|
||||
|
||||
// _spriteBatch.DrawCircle(
|
||||
// center: new Vector2(x, y),
|
||||
// radius: baseRadius + baseOuterRadius * easing,
|
||||
// sides: 20,
|
||||
// color: new Color(ping.Player.Color.ToColor(), (1 - easing)),
|
||||
// thickness: 2 + 5 * (1 - easing));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPlayerPointer(Player player)
|
||||
{
|
||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
||||
@ -2328,10 +2525,10 @@ namespace Sledgemapper
|
||||
internal Texture2D Texture;
|
||||
internal Dictionary<String, Rectangle> index;
|
||||
|
||||
public void LoadContent(ContentManager content)
|
||||
public void LoadContent(ContentManager content, string spriteIndex, string texture)
|
||||
{
|
||||
index = content.Load<Dictionary<String, Rectangle>>("spriteIndex");
|
||||
Texture = content.Load<Texture2D>("sprites");
|
||||
index = content.Load<Dictionary<String, Rectangle>>(spriteIndex);
|
||||
Texture = content.Load<Texture2D>(texture);
|
||||
}
|
||||
|
||||
internal Rectangle? SourceRectangle(string spriteName)
|
||||
@ -2349,4 +2546,6 @@ namespace Sledgemapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user