generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/refactor/split-readyroom-and-monopoly' into …
…develop # Conflicts: # Application/Common/IRepository.cs # Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs # Monopoly.Web/Pages/Ready/Components/ReadyButton.razor.cs # Monopoly.Web/Pages/Ready/ReadyPage.razor.cs
- Loading branch information
Showing
244 changed files
with
3,830 additions
and
2,115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace Application.Common; | ||
|
||
public abstract record BaseRequest; | ||
public abstract record GameRequest(string GameId, string PlayerId): BaseRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
using Domain.Common; | ||
using Monopoly.DomainLayer.Common; | ||
|
||
namespace Application.Common; | ||
|
||
public interface IEventBus<TEvent> where TEvent : DomainEvent | ||
{ | ||
public Task PublishAsync(IEnumerable<TEvent> events); | ||
public Task PublishAsync(IEnumerable<TEvent> events, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace Application.Common; | ||
|
||
public interface IPresenter<in TResponse> | ||
public interface IPresenter<TResponse> | ||
{ | ||
public Task PresentAsync(TResponse response); | ||
public Task PresentAsync(TResponse response, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
using Application.DataModels; | ||
using Domain.Maps; | ||
|
||
namespace Application.Common; | ||
|
||
internal static class RepositoryExtensions | ||
{ | ||
internal static string Save(this IRepository repository, Domain.MonopolyAggregate domainMonopolyAggregate) | ||
{ | ||
var monopoly = domainMonopolyAggregate.ToApplication(); | ||
return repository.Save(monopoly); | ||
} | ||
|
||
/// <summary> | ||
/// (Monopoly) Domain to Application | ||
/// </summary> | ||
/// <param name="domainMonopolyAggregate"></param> | ||
/// <returns></returns> | ||
private static MonopolyDataModel ToApplication(this Domain.MonopolyAggregate domainMonopolyAggregate) | ||
{ | ||
var players = domainMonopolyAggregate.Players.Select(player => | ||
{ | ||
var playerChess = player.Chess; | ||
|
||
Chess chess = new(playerChess.CurrentBlockId, playerChess.CurrentDirection.ToApplicationDirection()); | ||
|
||
var landContracts = player.LandContractList.Select(contract => | ||
new LandContract(contract.Land.Id, contract.InMortgage, contract.Deadline)).ToArray(); | ||
|
||
return new Player( | ||
player.Id, | ||
player.Money, | ||
chess, | ||
landContracts, | ||
player.State, | ||
player.BankruptRounds, | ||
player.LocationId, | ||
player.RoleId | ||
); | ||
}).ToArray(); | ||
|
||
Map map = new(domainMonopolyAggregate.Map.Id, domainMonopolyAggregate.Map.Blocks | ||
.Select(row => { return row.Select(block => block?.ToApplicationBlock()).ToArray(); }).ToArray() | ||
); | ||
var gamestage = domainMonopolyAggregate.GameStage switch | ||
{ | ||
Domain.GameStage.Ready => GameStage.Preparing, | ||
Domain.GameStage.Gaming => GameStage.Gaming, | ||
_ => throw new NotImplementedException(), | ||
}; | ||
if (gamestage == GameStage.Preparing) | ||
{ | ||
return new MonopolyDataModel(domainMonopolyAggregate.Id, [..players], map, domainMonopolyAggregate.HostId, null!, | ||
null!, gamestage); | ||
} | ||
|
||
var currentPlayer = | ||
domainMonopolyAggregate.Players.First(player => | ||
player.Id == domainMonopolyAggregate.CurrentPlayerState.PlayerId); | ||
var auction = domainMonopolyAggregate.CurrentPlayerState.Auction; | ||
var currentPlayerState = new CurrentPlayerState( | ||
domainMonopolyAggregate.CurrentPlayerState.PlayerId, | ||
domainMonopolyAggregate.CurrentPlayerState.IsPayToll, | ||
domainMonopolyAggregate.CurrentPlayerState.IsBoughtLand, | ||
domainMonopolyAggregate.CurrentPlayerState.IsUpgradeLand, | ||
domainMonopolyAggregate.CurrentPlayerState.Auction is null | ||
? null | ||
: new Auction(auction!.LandContract.Land.Id, auction.HighestBidder?.Id, auction.HighestPrice), | ||
domainMonopolyAggregate.CurrentPlayerState.RemainingSteps, | ||
domainMonopolyAggregate.CurrentPlayerState.HadSelectedDirection | ||
); | ||
var LandHouses = domainMonopolyAggregate.Map.Blocks.SelectMany(block => block).OfType<Domain.Land>() | ||
.Where(land => land.House > 0) | ||
.Select(land => new LandHouse(land.Id, land.House)).ToArray(); | ||
|
||
|
||
return new DataModels.MonopolyDataModel(domainMonopolyAggregate.Id, players, map, domainMonopolyAggregate.HostId, | ||
currentPlayerState, LandHouses, gamestage); | ||
} | ||
|
||
private static Block ToApplicationBlock(this Domain.Block domainBlock) | ||
{ | ||
return domainBlock switch | ||
{ | ||
Domain.StartPoint startBlock => new StartPoint(startBlock.Id), | ||
Domain.Station stationBlock => new Station(stationBlock.Id), | ||
Domain.Land landBlock => new Land(landBlock.Id), | ||
Domain.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id), | ||
Domain.Jail prisonBlock => new Jail(prisonBlock.Id), | ||
null => new EmptyBlock(), | ||
_ => throw new NotImplementedException(), | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// (Monopoly) Application to Domain | ||
/// </summary> | ||
/// <param name="monopolyDataModel"></param> | ||
/// <returns></returns> | ||
internal static Domain.MonopolyAggregate ToDomain(this MonopolyDataModel monopolyDataModel) | ||
{ | ||
//Domain.Map map = new(monopoly.Map.Id, monopoly.Map.Blocks | ||
// .Select(row => | ||
// { | ||
// return row.Select(block => block?.ToDomainBlock()).ToArray(); | ||
// }).ToArray() | ||
// ); | ||
Domain.Map map = new SevenXSevenMap(); | ||
var builder = new Domain.Builders.MonopolyBuilder() | ||
.WithId(monopolyDataModel.Id) | ||
.WithHost(monopolyDataModel.HostId) | ||
.WithMap(map); | ||
monopolyDataModel.Players.ToList().ForEach( | ||
p => builder.WithPlayer(p.Id, playerBuilder => | ||
playerBuilder.WithMoney(p.Money) | ||
.WithPosition(p.Chess.CurrentPosition, p.Chess.Direction.ToString()) | ||
.WithLandContracts(p.LandContracts) | ||
.WithBankrupt(p.BankruptRounds) | ||
.WithLocation(p.LocationId) | ||
.WithRole(p.RoleId) | ||
.WithState(p.PlayerState) | ||
)); | ||
builder.WithGameStage(monopolyDataModel.GameStage switch | ||
{ | ||
GameStage.Preparing => Domain.GameStage.Ready, | ||
GameStage.Gaming => Domain.GameStage.Gaming, | ||
_ => throw new NotImplementedException(), | ||
}); | ||
if (monopolyDataModel.GameStage == GameStage.Preparing) | ||
{ | ||
return builder.Build(); | ||
} | ||
|
||
var cps = monopolyDataModel.CurrentPlayerState; | ||
if (cps.Auction is null) | ||
{ | ||
builder.WithCurrentPlayer(cps.PlayerId, x => x.WithBoughtLand(cps.IsBoughtLand) | ||
.WithUpgradeLand(cps.IsUpgradeLand) | ||
.WithPayToll(cps.IsPayToll) | ||
.WithSelectedDirection(cps.HadSelectedDirection)); | ||
} | ||
else | ||
{ | ||
builder.WithCurrentPlayer(cps.PlayerId, x => x.WithAuction( | ||
cps.Auction.LandId, cps.Auction.HighestBidderId, cps.Auction.HighestPrice)); | ||
} | ||
|
||
monopolyDataModel.LandHouses.ToList().ForEach(LandHouse => builder.WithLandHouse(LandHouse.LandId, LandHouse.House)); | ||
|
||
return builder.Build(); | ||
} | ||
|
||
private static Domain.Builders.PlayerBuilder WithLandContracts(this Domain.Builders.PlayerBuilder builder, | ||
LandContract[] landContracts) | ||
{ | ||
landContracts.ToList().ForEach(landContract => | ||
{ | ||
builder.WithLandContract(landContract.LandId, landContract.InMortgage, landContract.Deadline); | ||
}); | ||
return builder; | ||
} | ||
|
||
private static Domain.Block? ToDomainBlock(this Block? block) | ||
{ | ||
return block switch | ||
{ | ||
StartPoint startBlock => new Domain.StartPoint(startBlock.Id), | ||
Station stationBlock => new Domain.Station(stationBlock.Id), | ||
Land landBlock => new Domain.Land(landBlock.Id), | ||
ParkingLot parkingLotBlock => new Domain.ParkingLot(parkingLotBlock.Id), | ||
Jail prisonBlock => new Domain.Jail(prisonBlock.Id), | ||
EmptyBlock => null, | ||
_ => throw new NotImplementedException(), | ||
}; | ||
} | ||
|
||
private static Direction ToApplicationDirection(this Domain.Map.Direction direction) | ||
{ | ||
return direction switch | ||
{ | ||
Domain.Map.Direction.Up => Direction.Up, | ||
Domain.Map.Direction.Down => Direction.Down, | ||
Domain.Map.Direction.Left => Direction.Left, | ||
Domain.Map.Direction.Right => Direction.Right, | ||
_ => throw new NotImplementedException(), | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Domain.Common; | ||
using Monopoly.DomainLayer.Common; | ||
|
||
namespace Application.Common; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Application/DataModels/Monopoly.cs → Application/DataModels/MonopolyDataModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Application.Common; | ||
using Application.Usecases.ReadyRoom; | ||
using Monopoly.DomainLayer.ReadyRoom; | ||
|
||
namespace Application.Queries; | ||
|
||
public record GetReadyRoomInfosRequest(string GameId, string PlayerId) | ||
: GameRequest(GameId, PlayerId); | ||
public record GetReadyRoomInfosResponse(string RequestPlayerId, ReadyRoomAggregate ReadyRoom) : Response; | ||
|
||
public class GetReadyRoomInfosUsecase(IReadyRoomRepository repository) | ||
: Usecase<GetReadyRoomInfosRequest, GetReadyRoomInfosResponse> | ||
{ | ||
public override async Task ExecuteAsync(GetReadyRoomInfosRequest request, | ||
IPresenter<GetReadyRoomInfosResponse> presenter, CancellationToken cancellationToken = default) | ||
{ | ||
var readyRoom = await repository.GetReadyRoomAsync(request.GameId); | ||
await presenter.PresentAsync(new GetReadyRoomInfosResponse(request.PlayerId, readyRoom), cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.