Skip to content

Commit

Permalink
將IMonopolyResponse移動到SharedLibrary
Browse files Browse the repository at this point in the history
這個變更使前端能夠直接使用IMonopolyResponse作為SignalR的Event名稱。
在移動後為了避免ServerTest使用到MonopolyMap,因此把MonopolyMap移動到其他命名空間
  • Loading branch information
aa89227 committed Aug 13, 2023
1 parent 991076e commit e06e41e
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 56 deletions.
91 changes: 46 additions & 45 deletions Client/Components/BlazorMap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using SharedLibrary.MonopolyMap;
using System.ComponentModel;

namespace Client.Components;

Expand All @@ -21,7 +22,7 @@ public class BlazorMap

public int BlockHeight => _blockHeight;

public BlazorMap(SharedLibrary.MonopolyMap data)
public BlazorMap(MonopolyMap data)
{
// 自動Mapping _data 到 _blocks
_blocks = new Block[data.Data.Length][];
Expand All @@ -35,13 +36,13 @@ public BlazorMap(SharedLibrary.MonopolyMap data)
var y = i * (_blockHeight + _blockMargin);
_blocks[i][j] = monopolyBlock.Type switch
{
SharedLibrary.BlockType.None => null!,
SharedLibrary.BlockType.Land => CreateLand(monopolyBlock, x, y),
SharedLibrary.BlockType.Road => new Road(x, y, monopolyBlock.Id, monopolyBlock.ToRoad().RoadType.ToBlazorRoadType()),
SharedLibrary.BlockType.ParkingLot => new ParkingLot(x, y, monopolyBlock.Id),
SharedLibrary.BlockType.Prison => new Prison(x, y, monopolyBlock.Id),
SharedLibrary.BlockType.StartPoint => new StartPoint(x, y, monopolyBlock.Id),
SharedLibrary.BlockType.Station => new Station(x, y, monopolyBlock.Id, monopolyBlock.ToStation().RoadType.ToBlazorStationRoadType()),
BlockType.None => null!,
BlockType.Land => CreateLand(monopolyBlock, x, y),
BlockType.Road => new Road(x, y, monopolyBlock.Id, monopolyBlock.ToRoad().RoadType.ToBlazorRoadType()),
BlockType.ParkingLot => new ParkingLot(x, y, monopolyBlock.Id),
BlockType.Prison => new Prison(x, y, monopolyBlock.Id),
BlockType.StartPoint => new StartPoint(x, y, monopolyBlock.Id),
BlockType.Station => new Station(x, y, monopolyBlock.Id, monopolyBlock.ToStation().RoadType.ToBlazorStationRoadType()),
_ => throw new InvalidEnumArgumentException()
};
}
Expand All @@ -59,7 +60,7 @@ public BlazorMap(SharedLibrary.MonopolyMap data)
/// <param name="_y">原座標Y</param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
private static Land CreateLand(SharedLibrary.BlockBase block, int x, int y)
private static Land CreateLand(BlockBase block, int x, int y)
{
var type = block.ToLand().LandType.ToBlazorLandType();
double offsetX = type switch
Expand Down Expand Up @@ -178,67 +179,67 @@ public static string GetImageName(this BlazorMap.StationRoadType stationRoadType
return GetImageName(typeof(BlazorMap.StationRoadType), stationRoadType);
}

public static SharedLibrary.Land ToLand(this SharedLibrary.BlockBase block)
public static Land ToLand(this BlockBase block)
{
return (SharedLibrary.Land)block;
return (Land)block;
}

public static BlazorMap.LandType ToBlazorLandType(this SharedLibrary.LandType landType)
public static BlazorMap.LandType ToBlazorLandType(this LandType landType)
{
return landType switch
{
SharedLibrary.LandType.Right => BlazorMap.LandType.Right,
SharedLibrary.LandType.Down => BlazorMap.LandType.Down,
SharedLibrary.LandType.Left => BlazorMap.LandType.Left,
SharedLibrary.LandType.Up => BlazorMap.LandType.Up,
LandType.Right => BlazorMap.LandType.Right,
LandType.Down => BlazorMap.LandType.Down,
LandType.Left => BlazorMap.LandType.Left,
LandType.Up => BlazorMap.LandType.Up,
_ => throw new InvalidEnumArgumentException()
};
}

public static SharedLibrary.Road ToRoad(this SharedLibrary.BlockBase block)
public static Road ToRoad(this BlockBase block)
{
return (SharedLibrary.Road)block;
return (Road)block;
}

public static BlazorMap.RoadType ToBlazorRoadType(this SharedLibrary.RoadType roadType)
public static BlazorMap.RoadType ToBlazorRoadType(this RoadType roadType)
{
return roadType switch
{
SharedLibrary.RoadType.TopLeftIntersection => BlazorMap.RoadType.TopLeftIntersection,
SharedLibrary.RoadType.TopIntersection => BlazorMap.RoadType.TopIntersection,
SharedLibrary.RoadType.TopRightIntersection => BlazorMap.RoadType.TopRightIntersection,
SharedLibrary.RoadType.LeftCenterIntersection => BlazorMap.RoadType.LeftCenterIntersection,
SharedLibrary.RoadType.CenterIntersection => BlazorMap.RoadType.CenterIntersection,
SharedLibrary.RoadType.RightCenterIntersection => BlazorMap.RoadType.RightCenterIntersection,
SharedLibrary.RoadType.BottomLeftIntersection => BlazorMap.RoadType.BottomLeftIntersection,
SharedLibrary.RoadType.BottomIntersection => BlazorMap.RoadType.BottomIntersection,
SharedLibrary.RoadType.BottomRightIntersection => BlazorMap.RoadType.BottomRightIntersection,
SharedLibrary.RoadType.HorizontalRoad => BlazorMap.RoadType.HorizontalRoad,
SharedLibrary.RoadType.VerticalRoad => BlazorMap.RoadType.VerticalRoad,
RoadType.TopLeftIntersection => BlazorMap.RoadType.TopLeftIntersection,
RoadType.TopIntersection => BlazorMap.RoadType.TopIntersection,
RoadType.TopRightIntersection => BlazorMap.RoadType.TopRightIntersection,
RoadType.LeftCenterIntersection => BlazorMap.RoadType.LeftCenterIntersection,
RoadType.CenterIntersection => BlazorMap.RoadType.CenterIntersection,
RoadType.RightCenterIntersection => BlazorMap.RoadType.RightCenterIntersection,
RoadType.BottomLeftIntersection => BlazorMap.RoadType.BottomLeftIntersection,
RoadType.BottomIntersection => BlazorMap.RoadType.BottomIntersection,
RoadType.BottomRightIntersection => BlazorMap.RoadType.BottomRightIntersection,
RoadType.HorizontalRoad => BlazorMap.RoadType.HorizontalRoad,
RoadType.VerticalRoad => BlazorMap.RoadType.VerticalRoad,
_ => throw new InvalidEnumArgumentException()
};
}

public static SharedLibrary.Station ToStation(this SharedLibrary.BlockBase block)
public static Station ToStation(this BlockBase block)
{
return (SharedLibrary.Station)block;
return (Station)block;
}

public static BlazorMap.StationRoadType ToBlazorStationRoadType(this SharedLibrary.RoadType stationRoadType)
public static BlazorMap.StationRoadType ToBlazorStationRoadType(this RoadType stationRoadType)
{
return stationRoadType switch
{
SharedLibrary.RoadType.TopLeftIntersection => BlazorMap.StationRoadType.TopLeftIntersection,
SharedLibrary.RoadType.TopIntersection => BlazorMap.StationRoadType.TopIntersection,
SharedLibrary.RoadType.TopRightIntersection => BlazorMap.StationRoadType.TopRightIntersection,
SharedLibrary.RoadType.LeftCenterIntersection => BlazorMap.StationRoadType.LeftCenterIntersection,
SharedLibrary.RoadType.CenterIntersection => BlazorMap.StationRoadType.CenterIntersection,
SharedLibrary.RoadType.RightCenterIntersection => BlazorMap.StationRoadType.RightCenterIntersection,
SharedLibrary.RoadType.BottomLeftIntersection => BlazorMap.StationRoadType.BottomLeftIntersection,
SharedLibrary.RoadType.BottomIntersection => BlazorMap.StationRoadType.BottomIntersection,
SharedLibrary.RoadType.BottomRightIntersection => BlazorMap.StationRoadType.BottomRightIntersection,
SharedLibrary.RoadType.HorizontalRoad => BlazorMap.StationRoadType.HorizontalRoad,
SharedLibrary.RoadType.VerticalRoad => BlazorMap.StationRoadType.VerticalRoad,
RoadType.TopLeftIntersection => BlazorMap.StationRoadType.TopLeftIntersection,
RoadType.TopIntersection => BlazorMap.StationRoadType.TopIntersection,
RoadType.TopRightIntersection => BlazorMap.StationRoadType.TopRightIntersection,
RoadType.LeftCenterIntersection => BlazorMap.StationRoadType.LeftCenterIntersection,
RoadType.CenterIntersection => BlazorMap.StationRoadType.CenterIntersection,
RoadType.RightCenterIntersection => BlazorMap.StationRoadType.RightCenterIntersection,
RoadType.BottomLeftIntersection => BlazorMap.StationRoadType.BottomLeftIntersection,
RoadType.BottomIntersection => BlazorMap.StationRoadType.BottomIntersection,
RoadType.BottomRightIntersection => BlazorMap.StationRoadType.BottomRightIntersection,
RoadType.HorizontalRoad => BlazorMap.StationRoadType.HorizontalRoad,
RoadType.VerticalRoad => BlazorMap.StationRoadType.VerticalRoad,
_ => throw new InvalidEnumArgumentException()
};
}
Expand Down
2 changes: 1 addition & 1 deletion Client/Pages/Game.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Options;
using MudBlazor;
using SharedLibrary;
using SharedLibrary.MonopolyMap;
using System.Net.Http.Json;

namespace Client.Pages;
Expand Down
2 changes: 1 addition & 1 deletion Domain/Events/PlayerBuildHouseEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Domain.Events;

public record PlayerBuildHouseEvent(string GameId, string PlayerId, string BlockId, decimal PlayerMoney, int House)
public record PlayerBuildHouseEvent(string GameId, string PlayerId, string BlockId, decimal PlayerMoney, int House)
: DomainEvent(GameId);

public record PlayerCannotBuildHouseEvent(string GameId, string PlayerId, string BlockId)
Expand Down
1 change: 1 addition & 0 deletions Server/Hubs/MonopolyHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Application.Usecases;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using SharedLibrary;
using System.Security.Claims;

namespace Server.Hubs;
Expand Down
1 change: 1 addition & 0 deletions Server/MonopolyEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Domain.Events;
using Microsoft.AspNetCore.SignalR;
using Server.Hubs;
using SharedLibrary;

namespace Server;

Expand Down
2 changes: 1 addition & 1 deletion Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Server.Hubs;
using Server.Repositories;
using Server.Services;
using SharedLibrary;
using SharedLibrary.MonopolyMap;
using System.Security.Claims;

var builder = WebApplication.CreateBuilder(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Server.Hubs;
namespace SharedLibrary;

public interface IMonopolyResponses
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace SharedLibrary;
namespace SharedLibrary.MonopolyMap;

public class MonopolyMap
{
Expand Down Expand Up @@ -66,11 +66,11 @@ public enum LandType
Up
}

public class TestMap
public class TestMap
{
public MonopolyMap Map { get; set; }
public TestMap()
{
public TestMap()
{
var emptyBlock = new EmptyBlock();
var land = (string id, LandType landType) => new Land(id, landType);
var road = (string id, RoadType roadType) => new Road(id, roadType);
Expand Down
4 changes: 4 additions & 0 deletions SharedLibrary/SharedLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="MonopolyMap\" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/BuildHouseTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/BuyBlockTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/MortgageTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/PayTollTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
2 changes: 1 addition & 1 deletion Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Server.DataModels;
using Server.Hubs;
using Server.Repositories;
using SharedLibrary;
using System.Net.Http.Headers;
using System.Net.Http.Json;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/RedeemTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/RollDiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Domain;
using Domain.Maps;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
1 change: 1 addition & 0 deletions Test/ServerTests/AcceptanceTests/SelectDirectionTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Application.Common;
using Domain;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;
using static ServerTests.Utils;

Expand Down
2 changes: 1 addition & 1 deletion Test/ServerTests/MonopolyTestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Server.DataModels;
using Server.Hubs;
using Server.Services;
using SharedLibrary;
using System.Collections.Concurrent;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;
Expand Down
2 changes: 1 addition & 1 deletion Test/ServerTests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Domain.Interfaces;
using Domain.Maps;
using Moq;
using Server.Hubs;
using SharedLibrary;
using static Domain.Map;

namespace ServerTests;
Expand Down

0 comments on commit e06e41e

Please sign in to comment.