back on track
This commit is contained in:
parent
81a7c49605
commit
9ef385deb7
6 changed files with 126 additions and 43 deletions
|
@ -10,7 +10,7 @@
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}_{ID}_{Intersection}";
|
||||
return $"{X}_{Y}_{Intersection}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}_{ID}";
|
||||
return $"{X}_{Y}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
public int Rotation { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}_{ID}";
|
||||
return $"{X}_{Y}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
SignalRChat/SignalRChat/.vscode/launch.json
vendored
Normal file
34
SignalRChat/SignalRChat/.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (web)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/net5.0/SignalRChat.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"stopAtEntry": false,
|
||||
"serverReadyAction": {
|
||||
"action": "openExternally",
|
||||
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
|
||||
},
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/Views": "${workspaceFolder}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
42
SignalRChat/SignalRChat/.vscode/tasks.json
vendored
Normal file
42
SignalRChat/SignalRChat/.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/SignalRChat.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/SignalRChat.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/SignalRChat.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -3,32 +3,47 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace SignalRChat.Hubs
|
||||
{
|
||||
public struct Overlay
|
||||
public class Overlay
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string ID { get; set; }
|
||||
public bool Intersection { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}_{Intersection}";
|
||||
}
|
||||
}
|
||||
|
||||
public struct Tile
|
||||
public class Tile
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string ID { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}";
|
||||
}
|
||||
}
|
||||
|
||||
public struct Wall
|
||||
public class Wall
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string ID { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X}_{Y}";
|
||||
}
|
||||
}
|
||||
|
||||
public class Player
|
||||
|
@ -44,19 +59,18 @@ namespace SignalRChat.Hubs
|
|||
{
|
||||
public SessionData()
|
||||
{
|
||||
Map = new ConcurrentBag<Tile>();
|
||||
Overlays = new ConcurrentBag<Overlay>();
|
||||
Walls = new ConcurrentBag<Wall>();
|
||||
Players = new ConcurrentBag<Player>();
|
||||
Colors = new ConcurrentBag<string>();
|
||||
Map = new ConcurrentDictionary<string, Tile>();
|
||||
Overlays = new ConcurrentDictionary<string, Overlay>();
|
||||
Walls = new ConcurrentDictionary<string, Wall>();
|
||||
Players = new List<Player>();
|
||||
Colors = new List<string>();
|
||||
}
|
||||
|
||||
public ConcurrentBag<Tile> Map { get; set; }
|
||||
public ConcurrentBag<Wall> Walls { get; set; }
|
||||
public ConcurrentBag<Overlay> Overlays { get; set; }
|
||||
public ConcurrentDictionary<string, Tile> Map { get; set; }
|
||||
public ConcurrentDictionary<string, Wall> Walls { get; set; }
|
||||
public ConcurrentDictionary<string, Overlay> Overlays { get; set; }
|
||||
public bool IsValid { get; set; }
|
||||
public ConcurrentBag<Player> Players { get; set; }
|
||||
public ConcurrentBag<string> Colors;
|
||||
public List<Player> Players { get; set; }
|
||||
public List<string> Colors;
|
||||
}
|
||||
|
||||
public class ChatHub : Hub
|
||||
|
@ -79,13 +93,13 @@ namespace SignalRChat.Hubs
|
|||
|
||||
public async Task NewTile(string sessionName, Tile tile)
|
||||
{
|
||||
var existingTile = _sessions[sessionName].Map.Any(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID);
|
||||
var existingTile = _sessions[sessionName].Map.TryGetValue(tile.ToString(), out var t);
|
||||
if (existingTile)
|
||||
{
|
||||
var t = _sessions[sessionName].Map.First(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID);
|
||||
_sessions[sessionName].Map.Remove(t);
|
||||
|
||||
_sessions[sessionName].Map.TryRemove(t.ToString(), out var rtile);
|
||||
}
|
||||
_sessions[sessionName].Map.Add(tile);
|
||||
_sessions[sessionName].Map.TryAdd(tile.ToString(), tile);
|
||||
|
||||
|
||||
await Clients.Group(sessionName).SendAsync("NewTile", tile);
|
||||
|
@ -93,55 +107,48 @@ namespace SignalRChat.Hubs
|
|||
|
||||
public async Task NewWall(string sessionName, Wall tile)
|
||||
{
|
||||
var existingTile = _sessions[sessionName].Walls.Any(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID);
|
||||
var existingTile = _sessions[sessionName].Walls.TryGetValue(tile.ToString(), out var t);
|
||||
if (existingTile)
|
||||
{
|
||||
var t = _sessions[sessionName].Walls.First(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID);
|
||||
_sessions[sessionName].Walls.Remove(t);
|
||||
_sessions[sessionName].Walls.TryRemove(t.ToString(), out var rtile);
|
||||
|
||||
}
|
||||
_sessions[sessionName].Walls.Add(tile);
|
||||
_sessions[sessionName].Walls.TryAdd(tile.ToString(), tile);
|
||||
await Clients.Group(sessionName).SendAsync("NewWall", tile);
|
||||
}
|
||||
|
||||
public async Task NewOverlay(string sessionName, Overlay tile)
|
||||
{
|
||||
var existingTile = _sessions[sessionName].Overlays.Any(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID && m.Intersection == tile.Intersection);
|
||||
var existingTile = _sessions[sessionName].Overlays.TryGetValue(tile.ToString(), out var t);
|
||||
if (existingTile)
|
||||
{
|
||||
var t = _sessions[sessionName].Overlays.First(m => m.X == tile.X && m.Y == tile.Y && m.ID == tile.ID && m.Intersection == tile.Intersection);
|
||||
_sessions[sessionName].Overlays.Remove(t);
|
||||
}
|
||||
_sessions[sessionName].Overlays.Add(tile);
|
||||
_sessions[sessionName].Overlays.TryRemove(t.ToString(), out var rtile);
|
||||
|
||||
}
|
||||
_sessions[sessionName].Overlays.TryAdd(tile.ToString(), tile);
|
||||
await Clients.Group(sessionName).SendAsync("NewOverlay", tile);
|
||||
}
|
||||
|
||||
public async Task DeleteTile(string sessionName, Tile tile)
|
||||
{
|
||||
if (_sessions[sessionName].Map.Contains(tile))
|
||||
{
|
||||
_sessions[sessionName].Map.Remove(tile);
|
||||
}
|
||||
_sessions[sessionName].Map.TryRemove(tile.ToString(), out var rtile);
|
||||
|
||||
|
||||
await Clients.Group(sessionName).SendAsync("DeleteTile", tile);
|
||||
}
|
||||
|
||||
public async Task DeleteWall(string sessionName, Wall tile)
|
||||
{
|
||||
if (_sessions[sessionName].Walls.Contains(tile))
|
||||
{
|
||||
_sessions[sessionName].Walls.Remove(tile);
|
||||
}
|
||||
_sessions[sessionName].Walls.TryRemove(tile.ToString(), out var rtile);
|
||||
|
||||
|
||||
await Clients.Group(sessionName).SendAsync("DeleteWall", tile);
|
||||
}
|
||||
|
||||
public async Task DeleteOverlay(string sessionName, Overlay tile)
|
||||
{
|
||||
if (_sessions[sessionName].Overlays.Contains(tile))
|
||||
{
|
||||
_sessions[sessionName].Overlays.Remove(tile);
|
||||
}
|
||||
_sessions[sessionName].Overlays.TryRemove(tile.ToString(), out var rtile);
|
||||
|
||||
|
||||
await Clients.Group(sessionName).SendAsync("DeleteOverlay", tile);
|
||||
}
|
||||
|
@ -189,7 +196,7 @@ namespace SignalRChat.Hubs
|
|||
return _sessions[sessionName];
|
||||
}
|
||||
|
||||
public async Task Sync(string sessionName, List<Tile> map)
|
||||
public async Task Sync(string sessionName, ConcurrentDictionary<string, Tile> map)
|
||||
{
|
||||
_sessions[sessionName].Map = map;
|
||||
await Clients.Group(sessionName).SendAsync("UpdateMap", map);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue