Trim some code.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using AiurObserver;
|
||||
using Aiursoft.ChessServer.Data;
|
||||
using Aiursoft.ChessServer.Models;
|
||||
using Aiursoft.WebTools.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Aiursoft.Scanner.Abstractions;
|
||||
using System.Collections.Concurrent;
|
||||
using Aiursoft.ChessServer.Models;
|
||||
using Chess;
|
||||
|
||||
namespace Aiursoft.ChessServer.Data;
|
||||
|
||||
@@ -21,41 +20,4 @@ public class InMemoryDatabase : ISingletonDependency
|
||||
return Games.GetOrAdd(id, _ => new Game());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GameContext
|
||||
{
|
||||
public GameContext(Game game, int id)
|
||||
{
|
||||
Id = id;
|
||||
Turn = game.Board.Turn.AsChar;
|
||||
Ended = game.Board.IsEndGame;
|
||||
End = game.Board.EndGame?.EndgameType;
|
||||
Won = game.Board.EndGame?.WonSide;
|
||||
MoveIndex = game.Board.MoveIndex;
|
||||
WhiteKingChecked = game.Board.WhiteKingChecked;
|
||||
BlackKingChecked = game.Board.BlackKingChecked;
|
||||
Links = new Dictionary<string, string>
|
||||
{
|
||||
{ "ascii", $"games/{id}.ascii" },
|
||||
{ "fen", $"games/{id}.fen" },
|
||||
{ "pgn", $"games/{id}.pgn" },
|
||||
{ "html", $"games/{id}.html" },
|
||||
{ "websocket", $"games/{id}.ws" },
|
||||
{ "move-post", $"games/{id}/move/{{player}}/{{move_algebraic_notation}}" }
|
||||
};
|
||||
Listeners = game.Channel.GetListenerCount();
|
||||
}
|
||||
|
||||
|
||||
public int Id { get; }
|
||||
public Dictionary<string, string> Links { get; }
|
||||
public char Turn { get; }
|
||||
public bool Ended { get; }
|
||||
public EndgameType? End { get; }
|
||||
public PieceColor? Won { get; }
|
||||
public int MoveIndex { get; }
|
||||
public bool WhiteKingChecked { get; }
|
||||
public bool BlackKingChecked { get; }
|
||||
public int Listeners { get; }
|
||||
}
|
||||
@@ -5,9 +5,9 @@ namespace Aiursoft.ChessServer.Models;
|
||||
|
||||
public class Game
|
||||
{
|
||||
public ChessBoard Board { get; set; } = new();
|
||||
public ChessBoard Board { get; } = new();
|
||||
|
||||
public AsyncObservable<string> Channel { get; set; } = new();
|
||||
public AsyncObservable<string> Channel { get; } = new();
|
||||
|
||||
public object MovePieceLock { get; } = new();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Aiursoft.ChessServer.Models;
|
||||
using Chess;
|
||||
|
||||
namespace Aiursoft.ChessServer.Models;
|
||||
|
||||
public class GameContext
|
||||
{
|
||||
public GameContext(Game game, int id)
|
||||
{
|
||||
Id = id;
|
||||
Turn = game.Board.Turn.AsChar;
|
||||
Ended = game.Board.IsEndGame;
|
||||
End = game.Board.EndGame?.EndgameType;
|
||||
Won = game.Board.EndGame?.WonSide;
|
||||
MoveIndex = game.Board.MoveIndex;
|
||||
WhiteKingChecked = game.Board.WhiteKingChecked;
|
||||
BlackKingChecked = game.Board.BlackKingChecked;
|
||||
Links = new Dictionary<string, string>
|
||||
{
|
||||
{ "ascii", $"games/{id}.ascii" },
|
||||
{ "fen", $"games/{id}.fen" },
|
||||
{ "pgn", $"games/{id}.pgn" },
|
||||
{ "html", $"games/{id}.html" },
|
||||
{ "websocket", $"games/{id}.ws" },
|
||||
{ "move-post", $"games/{id}/move/{{player}}/{{move_algebraic_notation}}" }
|
||||
};
|
||||
Listeners = game.Channel.GetListenerCount();
|
||||
}
|
||||
|
||||
|
||||
public int Id { get; }
|
||||
public Dictionary<string, string> Links { get; }
|
||||
public char Turn { get; }
|
||||
public bool Ended { get; }
|
||||
public EndgameType? End { get; }
|
||||
public PieceColor? Won { get; }
|
||||
public int MoveIndex { get; }
|
||||
public bool WhiteKingChecked { get; }
|
||||
public bool BlackKingChecked { get; }
|
||||
public int Listeners { get; }
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
using System.Reflection;
|
||||
using Aiursoft.ChessServer.Middlewares;
|
||||
using Aiursoft.Scanner;
|
||||
using Aiursoft.WebTools.Models;
|
||||
|
||||
namespace Aiursoft.ChessServer;
|
||||
|
||||
public class Program
|
||||
@@ -12,25 +7,4 @@ public class Program
|
||||
var app = WebTools.Extends.App<Startup>(args);
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup : IWebStartup
|
||||
{
|
||||
public void ConfigureServices(IConfiguration configuration, IWebHostEnvironment environment, IServiceCollection services)
|
||||
{
|
||||
services.AddLibraryDependencies();
|
||||
|
||||
services
|
||||
.AddControllersWithViews()
|
||||
.AddApplicationPart(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
public void Configure(WebApplication app)
|
||||
{
|
||||
app.UseMiddleware<AllowCrossOriginMiddleware>();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.MapDefaultControllerRoute();
|
||||
app.UseWebSockets();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using Aiursoft.ChessServer.Middlewares;
|
||||
using Aiursoft.Scanner;
|
||||
using Aiursoft.WebTools.Models;
|
||||
|
||||
namespace Aiursoft.ChessServer;
|
||||
|
||||
public class Startup : IWebStartup
|
||||
{
|
||||
public void ConfigureServices(IConfiguration configuration, IWebHostEnvironment environment, IServiceCollection services)
|
||||
{
|
||||
services.AddLibraryDependencies();
|
||||
|
||||
services
|
||||
.AddControllersWithViews()
|
||||
.AddApplicationPart(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
public void Configure(WebApplication app)
|
||||
{
|
||||
app.UseMiddleware<AllowCrossOriginMiddleware>();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.MapDefaultControllerRoute();
|
||||
app.UseWebSockets();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user