more cleanup

This commit is contained in:
Michele Scandura 2020-11-18 11:22:46 +00:00
parent af441e772b
commit 77832db39d
28 changed files with 45 additions and 105 deletions

View File

@ -1,9 +1,7 @@
using System.Net;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Handlers;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,8 +1,5 @@
using System;
using System.Security.AccessControl;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Models; using Sledgemapper.Api.Models;
using System.Reflection;
namespace Sledgemapper.Api.Data namespace Sledgemapper.Api.Data
{ {
public static class DbInitializer public static class DbInitializer

View File

@ -1,10 +1,8 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Http.Features;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Data;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;

View File

@ -4,9 +4,7 @@ using Sledgemapper.Api.Data;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Api.Handlers;
using System.Linq; using System.Linq;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;

View File

@ -12,7 +12,7 @@ namespace Sledgemapper.Helpers
public AppException(string message) : base(message) { } public AppException(string message) : base(message) { }
public AppException(string message, params object[] args) public AppException(string message, params object[] args)
: base(String.Format(CultureInfo.CurrentCulture, message, args)) : base(string.Format(CultureInfo.CurrentCulture, message, args))
{ {
} }
} }

View File

@ -16,7 +16,7 @@ namespace SignalRChat.Hubs
[Authorize] [Authorize]
public class SledgemapperHub : Hub<ISledgemapperClient> public class SledgemapperHub : Hub<ISledgemapperClient>
{ {
private static readonly ConcurrentDictionary<int, string> UserColors = new ConcurrentDictionary<int, string>(); private static readonly ConcurrentDictionary<int, string> UserColors = new();
private readonly MyDbContext _dbContext; private readonly MyDbContext _dbContext;
private readonly DataContext _datacontext; private readonly DataContext _datacontext;
@ -29,7 +29,8 @@ namespace SignalRChat.Hubs
// other colors // other colors
// #cca300, #20f200, #004011, #00e6d6, #005c73, #0057d9, #d900ca, #660029, #d9003a // #cca300, #20f200, #004011, #00e6d6, #005c73, #0057d9, #d900ca, #660029, #d9003a
// private static Dictionary<string, Session> _sessions = new Dictionary<string, Session>(); // private static Dictionary<string, Session> _sessions = new Dictionary<string, Session>();
public List<string> Colors = new List<string>{ public List<string> Colors = new()
{
"#e6194B", "#e6194B",
"#f58231", "#f58231",
"#3cb44b", "#3cb44b",

View File

@ -1,5 +1,4 @@
using System; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Migrations.SqlServerMigrations namespace Sledgemapper.Migrations.SqlServerMigrations
{ {

View File

@ -1,5 +1,4 @@
using System; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Migrations.SqliteMigrations namespace Sledgemapper.Migrations.SqliteMigrations
{ {

View File

@ -1,4 +1,3 @@
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Models

View File

@ -1,5 +1,3 @@
using System.Data;
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Models

View File

@ -1,5 +1,3 @@
using System.Data;
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Models

View File

@ -1,4 +1,3 @@
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Models

View File

@ -1,5 +1,3 @@
using System.Data;
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Models

View File

@ -1,5 +1,4 @@
using MediatR; using MediatR;
using Sledgemapper.Shared.Entities;
using System; using System;
namespace Sledgemapper.Api.Notifications namespace Sledgemapper.Api.Notifications

View File

@ -1,6 +1,3 @@
using Sledgemapper.Api.Models;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
namespace Sledgemapper.Api.Notifications namespace Sledgemapper.Api.Notifications

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -1,15 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SignalRChat.Hubs; using SignalRChat.Hubs;
using MediatR.Pipeline;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Data;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using MediatR; using MediatR;

View File

@ -1,5 +1,4 @@
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Sledgemapper.Clients namespace Sledgemapper.Clients

View File

@ -5,7 +5,7 @@ namespace SignalRChat.Hubs
{ {
public static class ExtensionMethods public static class ExtensionMethods
{ {
private static Random rng = new Random(); private static Random rng = new();
public static void Shuffle<T>(this IList<T> list) public static void Shuffle<T>(this IList<T> list)
{ {

View File

@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sledgemapper.Api", "Sledgem
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sledgemapper.Shared", "Sledgemapper.Shared\Sledgemapper.Shared.csproj", "{7194CFCC-AECB-494F-AA7D-2E0E286A5F34}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sledgemapper.Shared", "Sledgemapper.Shared\Sledgemapper.Shared.csproj", "{7194CFCC-AECB-494F-AA7D-2E0E286A5F34}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "Identity\WebApi.csproj", "{9479E33D-08EE-4B50-B6D0-218801A6E7AC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -29,10 +27,6 @@ Global
{7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Debug|Any CPU.Build.0 = Debug|Any CPU {7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Release|Any CPU.ActiveCfg = Release|Any CPU {7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Release|Any CPU.Build.0 = Release|Any CPU {7194CFCC-AECB-494F-AA7D-2E0E286A5F34}.Release|Any CPU.Build.0 = Release|Any CPU
{9479E33D-08EE-4B50-B6D0-218801A6E7AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9479E33D-08EE-4B50-B6D0-218801A6E7AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9479E33D-08EE-4B50-B6D0-218801A6E7AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9479E33D-08EE-4B50-B6D0-218801A6E7AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -17,8 +17,8 @@ namespace Sledgemapper
{ {
public IMapApi Api { get; private set; } public IMapApi Api { get; private set; }
public HubConnection Connection { get; private set; } public HubConnection Connection { get; private set; }
public Session SessionData; public readonly Session SessionData;
private ChannelsQueue Queue = new ChannelsQueue(); private readonly ChannelsQueue Queue = new();
private AuthenticateResponse _authenticateResponse; private AuthenticateResponse _authenticateResponse;
public CommunicationManager(Session sessionData) public CommunicationManager(Session sessionData)

View File

@ -1,6 +1,4 @@
// using MonoGame.Extended;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections;
using System.IO; using System.IO;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
@ -12,10 +10,10 @@ namespace Sledgemapper
{ {
public static Dictionary<string, T> LoadContentFolder<T>(this ContentManager contentManager, string contentFolder) public static Dictionary<string, T> LoadContentFolder<T>(this ContentManager contentManager, string contentFolder)
{ {
DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "/" + contentFolder); DirectoryInfo dir = new(contentManager.RootDirectory + "/" + contentFolder);
if (!dir.Exists) if (!dir.Exists)
throw new DirectoryNotFoundException(); throw new DirectoryNotFoundException();
Dictionary<string, T> result = new Dictionary<string, T>(); Dictionary<string, T> result = new();
FileInfo[] files = dir.GetFiles("*.*"); FileInfo[] files = dir.GetFiles("*.*");
foreach (FileInfo file in files) foreach (FileInfo file in files)

View File

@ -1,10 +1,6 @@
using Refit; using Refit;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Sledgemapper namespace Sledgemapper

View File

@ -1,10 +1,6 @@
using Refit; using Refit;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Sledgemapper namespace Sledgemapper

View File

@ -6,19 +6,19 @@ namespace System
{ {
public static class ObjectExtensions public static class ObjectExtensions
{ {
private static readonly MethodInfo CloneMethod = typeof(Object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly MethodInfo CloneMethod = typeof(object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);
public static bool IsPrimitive(this Type type) public static bool IsPrimitive(this Type type)
{ {
if (type == typeof(String)) return true; if (type == typeof(string)) return true;
return (type.IsValueType & type.IsPrimitive); return type.IsValueType && type.IsPrimitive;
} }
public static Object Copy(this Object originalObject) public static object Copy(this object originalObject)
{ {
return InternalCopy(originalObject, new Dictionary<Object, Object>(new ReferenceEqualityComparer())); return InternalCopy(originalObject, new Dictionary<object, object>(new ReferenceEqualityComparer()));
} }
private static Object InternalCopy(Object originalObject, IDictionary<Object, Object> visited) private static object InternalCopy(object originalObject, IDictionary<object, object> visited)
{ {
if (originalObject == null) return null; if (originalObject == null) return null;
var typeToReflect = originalObject.GetType(); var typeToReflect = originalObject.GetType();
@ -29,7 +29,7 @@ namespace System
if (typeToReflect.IsArray) if (typeToReflect.IsArray)
{ {
var arrayType = typeToReflect.GetElementType(); var arrayType = typeToReflect.GetElementType();
if (IsPrimitive(arrayType) == false) if (!IsPrimitive(arrayType))
{ {
Array clonedArray = (Array)cloneObject; Array clonedArray = (Array)cloneObject;
clonedArray.ForEach((array, indices) => array.SetValue(InternalCopy(clonedArray.GetValue(indices), visited), indices)); clonedArray.ForEach((array, indices) => array.SetValue(InternalCopy(clonedArray.GetValue(indices), visited), indices));
@ -55,7 +55,7 @@ namespace System
{ {
foreach (FieldInfo fieldInfo in typeToReflect.GetFields(bindingFlags)) foreach (FieldInfo fieldInfo in typeToReflect.GetFields(bindingFlags))
{ {
if (filter != null && filter(fieldInfo) == false) continue; if (filter != null && !filter(fieldInfo)) continue;
if (IsPrimitive(fieldInfo.FieldType)) continue; if (IsPrimitive(fieldInfo.FieldType)) continue;
var originalFieldValue = fieldInfo.GetValue(originalObject); var originalFieldValue = fieldInfo.GetValue(originalObject);
var clonedFieldValue = InternalCopy(originalFieldValue, visited); var clonedFieldValue = InternalCopy(originalFieldValue, visited);
@ -64,11 +64,11 @@ namespace System
} }
public static T Copy<T>(this T original) public static T Copy<T>(this T original)
{ {
return (T)Copy((Object)original); return (T)Copy((object)original);
} }
} }
public class ReferenceEqualityComparer : EqualityComparer<Object> public class ReferenceEqualityComparer : EqualityComparer<object>
{ {
public override bool Equals(object x, object y) public override bool Equals(object x, object y)
{ {
@ -88,7 +88,7 @@ namespace System
public static void ForEach(this Array array, Action<Array, int[]> action) public static void ForEach(this Array array, Action<Array, int[]> action)
{ {
if (array.LongLength == 0) return; if (array.LongLength == 0) return;
ArrayTraverse walker = new ArrayTraverse(array); ArrayTraverse walker = new(array);
do action(array, walker.Position); do action(array, walker.Position);
while (walker.Step()); while (walker.Step());
} }
@ -97,7 +97,7 @@ namespace System
internal class ArrayTraverse internal class ArrayTraverse
{ {
public int[] Position; public int[] Position;
private int[] maxLengths; private readonly int[] maxLengths;
public ArrayTraverse(Array array) public ArrayTraverse(Array array)
{ {

View File

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.SignalR.Client; using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@ -7,16 +7,13 @@ using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.TextureAtlases; using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI; using Myra.Graphics2D.UI;
using Myra.Graphics2D.UI.File; using Myra.Graphics2D.UI.File;
using Myra.Graphics2D.UI.Properties;
using Newtonsoft.Json; using Newtonsoft.Json;
using Refit;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.UI; using Sledgemapper.UI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
namespace Sledgemapper namespace Sledgemapper
{ {
@ -29,9 +26,9 @@ namespace Sledgemapper
private readonly Desktop _desktop; private readonly Desktop _desktop;
private KeyboardState oldState; private KeyboardState oldState;
private MouseState oldMouseState; private MouseState oldMouseState;
private Vector3 _viewportCenter = new Vector3(0, 0, 0); private Vector3 _viewportCenter = new(0, 0, 0);
private Dictionary<string, SpriteFont> _fonts; private Dictionary<string, SpriteFont> _fonts;
private Session _sessionData; private readonly Session _sessionData;
private AuthenticateResponse _authResponse; private AuthenticateResponse _authResponse;
private MainWidget _mainWidget; private MainWidget _mainWidget;
@ -41,7 +38,6 @@ namespace Sledgemapper
_graphics.GraphicsProfile = GraphicsProfile.Reach; _graphics.GraphicsProfile = GraphicsProfile.Reach;
_graphics.PreferMultiSampling = false; _graphics.PreferMultiSampling = false;
//GraphicsDevice?.PresentationParameters.MultiSampleCount = 8;
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
_desktop = new Desktop(); _desktop = new Desktop();
@ -114,7 +110,7 @@ namespace Sledgemapper
{ {
var mouseState = Mouse.GetState(); var mouseState = Mouse.GetState();
var screenPosition = new Point((mouseState.Position.X - (int)_viewportCenter.X), (mouseState.Position.Y - (int)_viewportCenter.Y)); var screenPosition = new Point(mouseState.Position.X - (int)_viewportCenter.X, mouseState.Position.Y - (int)_viewportCenter.Y);
_state._hoveredTile.X = screenPosition.X / _state._tileSize; _state._hoveredTile.X = screenPosition.X / _state._tileSize;
_state._hoveredTile.Y = screenPosition.Y / _state._tileSize; _state._hoveredTile.Y = screenPosition.Y / _state._tileSize;
@ -245,7 +241,6 @@ namespace Sledgemapper
{ {
return; return;
} }
//GraphicsDevice.Clear(new Color(24,118,157));
GraphicsDevice.Clear(Color.LightGray); GraphicsDevice.Clear(Color.LightGray);
var visibleTilesX = GraphicsDevice.Viewport.Width / _state._tileSize + 1; var visibleTilesX = GraphicsDevice.Viewport.Width / _state._tileSize + 1;
@ -481,19 +476,13 @@ namespace Sledgemapper
{ {
var result = await _communicationManager.Api.NewSession(localContent.TxtSession.Text); var result = await _communicationManager.Api.NewSession(localContent.TxtSession.Text);
// var session = await _communicationManager.Connection?.InvokeAsync<Session>("NewSession", localContent.TxtSession.Text, _authResponse.Initials);
if (result) if (result)
{ {
//_sessionData;
_sessionData.SessionName = localContent.TxtSession.Text; _sessionData.SessionName = localContent.TxtSession.Text;
_sessionData.MapEntityAdded -= OnMapEntityAdded; _sessionData.MapEntityAdded -= OnMapEntityAdded;
_sessionData.MapEntityDeleted -= OnMapEntityDeleted; _sessionData.MapEntityDeleted -= OnMapEntityDeleted;
_sessionData.MapEntityAdded += OnMapEntityAdded; _sessionData.MapEntityAdded += OnMapEntityAdded;
_sessionData.MapEntityDeleted += OnMapEntityDeleted; _sessionData.MapEntityDeleted += OnMapEntityDeleted;
// _sessionData.Players = session.Players;
} }
successful = result; successful = result;
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text); var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text);
@ -508,7 +497,10 @@ namespace Sledgemapper
if (successful) if (successful)
{ {
_sessionData.SessionName = localContent.TxtSession.Text; _sessionData.SessionName = localContent.TxtSession.Text;
_communicationManager.SessionData = _sessionData; _communicationManager.SessionData.Map = _sessionData.Map;
_communicationManager.SessionData.Overlays = _sessionData.Overlays;
_communicationManager.SessionData.Walls = _sessionData.Walls;
localWindow.Close(); localWindow.Close();
} }
} }
@ -642,7 +634,7 @@ namespace Sledgemapper
private void OnMenuConnectJoinSelected(object sender, EventArgs e) private void OnMenuConnectJoinSelected(object sender, EventArgs e)
{ {
Window window = new Window Window window = new()
{ {
Title = "Join mapping session" Title = "Join mapping session"
}; };
@ -657,7 +649,7 @@ namespace Sledgemapper
private void OnMenuConnectLoginSelected(object sender, EventArgs e) private void OnMenuConnectLoginSelected(object sender, EventArgs e)
{ {
Window window = new Window Window window = new()
{ {
Title = "Login" Title = "Login"
}; };
@ -699,7 +691,6 @@ namespace Sledgemapper
private async void OnMenuConnectSyncSelected(object sender, EventArgs e) private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
{ {
// await _communicationManager.Connection?.InvokeAsync("Sync", _sessionData.SessionName, _sessionData);
var serverMap = await _communicationManager.Api.Session(_sessionData.SessionName); var serverMap = await _communicationManager.Api.Session(_sessionData.SessionName);
_sessionData.Overlays = serverMap.Overlays; _sessionData.Overlays = serverMap.Overlays;
_sessionData.Map = serverMap.Map; _sessionData.Map = serverMap.Map;
@ -709,14 +700,11 @@ namespace Sledgemapper
private async void OnMenuConnectUploadSelected(object sender, EventArgs e) private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
{ {
await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName); await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName);
// _sessionData.Overlays = serverMap.Overlays;
// _sessionData.Map = serverMap.Map;
// _sessionData.Walls = serverMap.Walls;
} }
private void OnMenuConnectNewSelected(object sender, EventArgs e) private void OnMenuConnectNewSelected(object sender, EventArgs e)
{ {
Window window = new Window Window window = new()
{ {
Title = "New mapping session" Title = "New mapping session"
}; };
@ -731,7 +719,7 @@ namespace Sledgemapper
private void OnMenuFileSaveSelected(object sender, EventArgs e) private void OnMenuFileSaveSelected(object sender, EventArgs e)
{ {
FileDialog dialog = new FileDialog(FileDialogMode.SaveFile) FileDialog dialog = new(FileDialogMode.SaveFile)
{ {
Filter = "*.map" Filter = "*.map"
}; };
@ -744,7 +732,7 @@ namespace Sledgemapper
} }
using StreamWriter file = File.CreateText(dialog.FilePath); using StreamWriter file = File.CreateText(dialog.FilePath);
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new();
serializer.Serialize(file, _sessionData); serializer.Serialize(file, _sessionData);
}; };
@ -765,7 +753,7 @@ namespace Sledgemapper
return; return;
} }
using StreamReader file = File.OpenText(dialog.FilePath); using StreamReader file = File.OpenText(dialog.FilePath);
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new();
var loadData = (Session)serializer.Deserialize(file, typeof(Session)); var loadData = (Session)serializer.Deserialize(file, typeof(Session));
_sessionData.Map=loadData.Map; _sessionData.Map=loadData.Map;
_sessionData.Overlays=loadData.Overlays; _sessionData.Overlays=loadData.Overlays;

View File

@ -6,10 +6,10 @@ namespace Sledgemapper
{ {
public class State public class State
{ {
public Tile _selectedTile = new Tile { X = 1, Y = 1 }; public Tile _selectedTile = new() { X = 1, Y = 1 };
public Tile _hoveredTile = new Tile { X = 1, Y = 1 }; public Tile _hoveredTile = new() { X = 1, Y = 1 };
public Wall _selectedWall = new Wall { X = 1, Y = 1 }; public Wall _selectedWall = new() { X = 1, Y = 1 };
public Overlay _selectedOverlay = new Overlay { X = 1, Y = 1 }; public Overlay _selectedOverlay = new() { X = 1, Y = 1 };
public int _tileSize = 30; public int _tileSize = 30;
public string _currentTileId = ""; public string _currentTileId = "";
public string _currentWallId = ""; public string _currentWallId = "";
@ -54,7 +54,7 @@ namespace Sledgemapper
_selectedOverlay.X = _hoveredTile.X; _selectedOverlay.X = _hoveredTile.X;
_selectedOverlay.Y = _hoveredTile.Y; _selectedOverlay.Y = _hoveredTile.Y;
var q1 = Math.Pow(mousePosition.X - _hoveredTile.X * _tileSize, 2); var q1 = Math.Pow(mousePosition.X - _hoveredTile.X * _tileSize, 2);
var q2 = Math.Pow((_hoveredTile.Y * _tileSize - mousePosition.Y), 2); var q2 = Math.Pow(_hoveredTile.Y * _tileSize - mousePosition.Y, 2);
var s = Math.Sqrt(q1 + q2); var s = Math.Sqrt(q1 + q2);
if (s < _tileSize / 3) if (s < _tileSize / 3)
@ -73,7 +73,7 @@ namespace Sledgemapper
} }
//q1 = System.Math.Pow(mousePosition.X - (_hoveredTile.X + 1) * _tileSize, 2); //q1 = System.Math.Pow(mousePosition.X - (_hoveredTile.X + 1) * _tileSize, 2);
q2 = Math.Pow(((_hoveredTile.Y + 1) * _tileSize - mousePosition.Y), 2); q2 = Math.Pow((_hoveredTile.Y + 1) * _tileSize - mousePosition.Y, 2);
s = Math.Sqrt(q1 + q2); s = Math.Sqrt(q1 + q2);
if (s < _tileSize / 3) if (s < _tileSize / 3)
{ {
@ -84,7 +84,7 @@ namespace Sledgemapper
} }
q1 = Math.Pow(mousePosition.X - _hoveredTile.X * _tileSize, 2); q1 = Math.Pow(mousePosition.X - _hoveredTile.X * _tileSize, 2);
q2 = Math.Pow(((_hoveredTile.Y + 1) * _tileSize - mousePosition.Y), 2); q2 = Math.Pow((_hoveredTile.Y + 1) * _tileSize - mousePosition.Y, 2);
s = Math.Sqrt(q1 + q2); s = Math.Sqrt(q1 + q2);
if (s < _tileSize / 3) if (s < _tileSize / 3)
{ {

View File

@ -1,6 +1,4 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper namespace Sledgemapper
{ {
@ -14,7 +12,7 @@ namespace Sledgemapper
b1 = Sign(pt, v1, v2) < 0.0f; b1 = Sign(pt, v1, v2) < 0.0f;
b2 = Sign(pt, v2, v3) < 0.0f; b2 = Sign(pt, v2, v3) < 0.0f;
b3 = Sign(pt, v3, v1) < 0.0f; b3 = Sign(pt, v3, v1) < 0.0f;
return ((b1 == b2) && (b2 == b3)); return (b1 == b2) && (b2 == b3);
} }
} }
} }