really good progress, need to fix tile upload
This commit is contained in:
parent
573e9ea7bf
commit
9ef43bb9f6
25 changed files with 280 additions and 112 deletions
|
@ -34,15 +34,15 @@ namespace SignalRChat.Hubs
|
|||
// other colors
|
||||
// #cca300, #20f200, #004011, #00e6d6, #005c73, #0057d9, #d900ca, #660029, #d9003a
|
||||
// private static Dictionary<string, Session> _sessions = new Dictionary<string, Session>();
|
||||
public List<string> Colors = new List<string>{"CC0000",
|
||||
"CC3300",
|
||||
"FFCC00",
|
||||
"009900",
|
||||
"006666",
|
||||
"0066FF",
|
||||
"0000CC",
|
||||
"663399",
|
||||
"CC0099"};
|
||||
public List<string> Colors = new List<string>{
|
||||
"#CC0000",
|
||||
"#20f200",
|
||||
"#FFCC00",
|
||||
"#006666",
|
||||
"#660029",
|
||||
"#0000CC",
|
||||
"#663399",
|
||||
"#CC0099"};
|
||||
|
||||
public async Task NewTile(string sessionName, Tile tile)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ namespace SignalRChat.Hubs
|
|||
// return session;
|
||||
// }
|
||||
|
||||
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName, string initials)
|
||||
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
|
||||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
|
@ -151,25 +151,30 @@ namespace SignalRChat.Hubs
|
|||
var userSession = new SessionUser { SessionId = session.SessionId, UserId = userId };
|
||||
_dbContext.SessionUsers.Add(userSession);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
var usersSession = _dbContext.SessionUsers.Where(m => m.SessionId == session.SessionId).Select(m => m.UserId).ToList();
|
||||
var players = _datacontext.
|
||||
Users.
|
||||
Where(m => usersSession.Contains(m.Id)).ToList().
|
||||
//Select((r, index) => new { Place = index, Name = r })
|
||||
Select((p, index) => new Player
|
||||
{
|
||||
Initials = p.Initials,
|
||||
UserId = userId,
|
||||
Color = Colors[index],
|
||||
Position = new Tile { X = 0, Y = 0 }
|
||||
}).ToList();
|
||||
// var players = _datacontext.
|
||||
// Users.
|
||||
// Where(m => usersSession.Contains(m.Id)).ToList().
|
||||
// //Select((r, index) => new { Place = index, Name = r })
|
||||
// Select((p, index) => new Player
|
||||
// {
|
||||
// Initials = p.Initials,
|
||||
// UserId = userId,
|
||||
// Color = Colors[index],
|
||||
// Position = new Tile { X = 0, Y = 0 }
|
||||
// }).ToList();
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, sessionName);
|
||||
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == session.SessionId).OrderBy(m => m.UserId).ToList();
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = Colors[SessionUsers.IndexOf(SessionUsers.FirstOrDefault(m => m.UserId == userId))] };
|
||||
|
||||
await Clients.Group(sessionName).NewPlayer(player);
|
||||
var newSession = new Sledgemapper.Shared.Entities.Session
|
||||
{
|
||||
Players = players,
|
||||
SessionName = sessionName
|
||||
};
|
||||
|
||||
|
@ -196,12 +201,12 @@ namespace SignalRChat.Hubs
|
|||
|
||||
public async Task UpdatePosition(string sessionName, Tile tile)
|
||||
{
|
||||
// var userId = int.Parse(Context.User.Identity.Name);
|
||||
// var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionName == sessionName);
|
||||
|
||||
// var player = _sessions[sessionName].Players.First(m => m.ConnectionId == Context.ConnectionId);
|
||||
// player.Position = tile;
|
||||
// await Clients.Group(sessionName).PlayerUpdate(player);
|
||||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionName == sessionName);
|
||||
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == session.SessionId).OrderBy(m => m.UserId).ToList();
|
||||
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = Colors[SessionUsers.IndexOf(SessionUsers.FirstOrDefault(m => m.UserId == userId))] };
|
||||
await Clients.Group(sessionName).PlayerUpdate(player);
|
||||
}
|
||||
|
||||
// public async Task<Session> Refresh(string sessionName)
|
||||
|
@ -243,7 +248,7 @@ namespace SignalRChat.Hubs
|
|||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId);
|
||||
await Clients.Group(session.SessionName).PlayerUpdate(null); //send remove player
|
||||
_dbContext.Sessions.Remove(session);
|
||||
_dbContext.SessionUsers.Remove(userSession);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -252,4 +257,5 @@ namespace SignalRChat.Hubs
|
|||
await base.OnDisconnectedAsync(exception);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue