From 5ef3be8cc87b937b08f6ba94d75151883d092c8e Mon Sep 17 00:00:00 2001 From: mcmuzzle Date: Mon, 23 Feb 2026 10:21:01 +0000 Subject: [PATCH] mise en place de la structure de base du plateau (#40) Co-authored-by: mcmuzzle Reviewed-on: https://gitea.borealian.ovh/mcmuzzle/LittleTown/pulls/40 --- .gitignore | 3 +- src/LittleTown.Api/LittleTown.Api.csproj.user | 6 + .../Components/MatchBoard.razor | 68 +++++ .../Components/MatchBoard.razor.cs | 11 + .../Components/MatchBoard.razor.css | 110 +++++++ .../LittleTown.Blazor.Client.csproj | 5 + .../Pages/Match.razor | 8 + .../Pages/Match.razor.cs | 16 + .../Pages/Match.razor.css | 4 + .../LittleTown.Blazor.Client/Program.cs | 7 + .../Services/IMatchService.cs | 13 + .../Services/MatchService.cs | 26 ++ .../Services/WasmStaticDataGetter.cs | 69 +++++ .../ViewModels/MatchViewModel.cs | 19 ++ .../LittleTown.Blazor.Client/_Imports.razor | 4 +- .../wwwroot/data/Board1.json | 276 ++++++++++++++++++ .../wwwroot/data/Buildings.json | 183 ++++++++++++ .../wwwroot/data/Objectives.json | 92 ++++++ .../LittleTown.Blazor/Components/App.razor | 2 +- .../Components/Layout/NavMenu.razor | 5 + .../LittleTown.Blazor.csproj | 5 + .../LittleTown.Blazor.csproj.user | 6 + .../LittleTown.Blazor/Program.cs | 9 +- .../Aggregates/MatchAggregate/Match.cs | 2 +- .../Inputs/IStaticDataGetter.cs | 5 + .../LittleTown.StaticDataAccess.csproj | 9 +- .../StaticDataGetter.cs | 17 +- src/LittleTown.sln | 6 + 28 files changed, 975 insertions(+), 11 deletions(-) create mode 100644 src/LittleTown.Api/LittleTown.Api.csproj.user create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.css create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.css create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/IMatchService.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/MatchService.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Board1.json create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Buildings.json create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Objectives.json create mode 100644 src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj.user diff --git a/.gitignore b/.gitignore index a395674..796f9cd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ bin obj report tools/ -TestResults \ No newline at end of file +TestResults +/src/.vs diff --git a/src/LittleTown.Api/LittleTown.Api.csproj.user b/src/LittleTown.Api/LittleTown.Api.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/src/LittleTown.Api/LittleTown.Api.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor new file mode 100644 index 0000000..4f2fe10 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor @@ -0,0 +1,68 @@ +
+
+ @foreach (var row in MatchViewModel.Rows) + { +
+ @foreach (var cell in row) + { + @cell + } +
+ } +
+ +
+ diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs new file mode 100644 index 0000000..3e0b5e2 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs @@ -0,0 +1,11 @@ +using LittleTown.Blazor.Client.ViewModels; +using Microsoft.AspNetCore.Components; + +namespace LittleTown.Blazor.Client.Components +{ + public partial class MatchBoard + { + [Parameter, EditorRequired] + public MatchViewModel MatchViewModel { get; init; } + } +} \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.css b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.css new file mode 100644 index 0000000..d0b2683 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.css @@ -0,0 +1,110 @@ +.board { + display: flex; + flex-direction: column; + width: 100%; + height: 100%; +} +.terrain { + width: 100%; + background-color: red; + box-sizing: border-box; +} + +.terrain-row { + display: grid; + grid-auto-flow: column; + grid-auto-columns: 1fr; /* toutes les cellules même largeur */ +} + +.terrain-cell { + aspect-ratio: 1 / 1; /* largeur = hauteur */ + display: flex; + align-items: center; + justify-content: center; + border: 1px solid black; +} +.footer { + width: 100%; + background-color: gray; + display: flex; + flex-direction: column; + +} + +.topScore { + flex: 1; + display: flex; + flex-direction: row; +} + +.bottomScore { + flex: 1; + display: flex; + flex-direction: row; +} + +.centerFooter{ + flex:5; + display: flex; + flex-direction:row; +} +.scoreItem { + flex: 1; + border: 1px solid; + aspect-ratio: 1 / 1; +} +.leftScore { + flex:1; + display:flex; + flex-direction:column; +} + +.rightScore { + flex: 1; + display: flex; + flex-direction: column; +} + +.infos { + flex:23; + display: flex; + flex-wrap:wrap; +} + +.building { + height: 100%; + aspect-ratio: 1 / 1; + flex: 0 0 auto; + background: lightblue; + border: 1px solid black; +} + +.turns { + flex: 1; + display: flex; + flex-direction: row; +} + +.turn { + flex: 1; +} + +.infos-row{ + height:50%; + width:100%; + background-color:blue; + display:flex; + flex-direction:row; +} + +.construction { + flex:1; +} + +.fields { + height: 100%; + aspect-ratio: 1 / 1; /* largeur = hauteur */ + flex: 0 0 auto; + background: lightblue; + border: 1px solid black; +} \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/LittleTown.Blazor.Client.csproj b/src/LittleTown.Blazor/LittleTown.Blazor.Client/LittleTown.Blazor.Client.csproj index 395d0ea..718a8a4 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/LittleTown.Blazor.Client.csproj +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/LittleTown.Blazor.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor new file mode 100644 index 0000000..748cb9c --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor @@ -0,0 +1,8 @@ +@page "/match" +@rendermode InteractiveAuto + +Match +
+ +
+ diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs new file mode 100644 index 0000000..2a85ea7 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs @@ -0,0 +1,16 @@ +using LittleTown.Blazor.Client.Services; +using LittleTown.Blazor.Client.ViewModels; +using Microsoft.AspNetCore.Components; + +namespace LittleTown.Blazor.Client.Pages; + +public partial class Match(IMatchService matchServices) +{ + public MatchViewModel MatchViewModel { get; private set; } + + public override Task SetParametersAsync(ParameterView parameters) + { + MatchViewModel = new MatchViewModel(matchServices.GetMatch()); + return base.SetParametersAsync(parameters); + } +} diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.css b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.css new file mode 100644 index 0000000..807e113 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.css @@ -0,0 +1,4 @@ +.board { + width: 100%; + height: 50vh; +} diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Program.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Program.cs index 519269f..4ff4b5b 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Program.cs +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Program.cs @@ -1,5 +1,12 @@ +using LittleTown.Blazor.Client.Services; +using LittleTown.Core.Ports; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); + await builder.Build().RunAsync(); diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/IMatchService.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/IMatchService.cs new file mode 100644 index 0000000..cb45412 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/IMatchService.cs @@ -0,0 +1,13 @@ +using LittleTown.Core; + +namespace LittleTown.Blazor.Client.Services +{ + public interface IMatchService + { + /// + /// Temporaire, recupere l'instance d'un match par défaut + /// + /// + Match GetMatch(); + } +} diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/MatchService.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/MatchService.cs new file mode 100644 index 0000000..159adad --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/MatchService.cs @@ -0,0 +1,26 @@ +using LittleTown.Core; +using LittleTown.Core.Ports; + +namespace LittleTown.Blazor.Client.Services +{ + public class MatchService : IMatchService + { + private readonly IStaticDataGetter _staticDataGetter; + private Match? _currentMatch; + + public MatchService(IStaticDataGetter staticDataGetter) + { + _staticDataGetter = staticDataGetter; + } + + /// > + public Match GetMatch() + { + if (null == _currentMatch) + { + _currentMatch = new Match(_staticDataGetter); + } + return _currentMatch; + } + } +} diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs new file mode 100644 index 0000000..de76970 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs @@ -0,0 +1,69 @@ +using System.Text.Json; +using LittleTown.Core; +using LittleTown.Core.Ports; + +namespace LittleTown.Blazor.Client.Services; + +/// +/// Implementation du getter de données static pour WebAssembly via HttpClient +/// +public class WasmStaticDataGetter : IStaticDataGetter +{ + private readonly HttpClient _httpClient; + private string _boardData = ""; + private string _buildingData = ""; + private string _objectivesData = ""; + private bool _isInitialized = false; + + public WasmStaticDataGetter(HttpClient httpClient) + { + _httpClient = httpClient; + } + + private async Task InitializeAsync() + { + if (_isInitialized) return; + + _boardData = await _httpClient.GetStringAsync("data/Board1.json"); + _buildingData = await _httpClient.GetStringAsync("data/Buildings.json"); + _objectivesData = await _httpClient.GetStringAsync("data/Objectives.json"); + + _isInitialized = true; + } + + /// + public async Task GetBoardAsync(int version) + { + // Synchronous wrapper - not ideal but matches interface + await InitializeAsync(); + + Board board = JsonSerializer.Deserialize(_boardData) + ?? throw new JsonException("Cannot deserialize Board"); + return board; + } + + public Board GetBoard(int version) + { + throw new NotImplementedException("Use the asynchronous version of GetBoard for WebAssembly."); + } + + /// + public ICollection GetBuildings() + { + InitializeAsync().GetAwaiter().GetResult(); + + List buildings = JsonSerializer.Deserialize>(_buildingData) + ?? throw new JsonException("Cannot deserialize Buildings"); + return buildings; + } + + /// + public ICollection GetObjectives() + { + InitializeAsync().GetAwaiter().GetResult(); + + List objectives = JsonSerializer.Deserialize>(_objectivesData) + ?? throw new JsonException("Cannot deserialize Objectives"); + return objectives; + } +} diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs new file mode 100644 index 0000000..bca9254 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs @@ -0,0 +1,19 @@ +using LittleTown.Core; + +namespace LittleTown.Blazor.Client.ViewModels; + +public class MatchViewModel(Match match) +{ + public List> Rows + { + get + { + List> rows = new List>(); + for(int i = 0; i < 6; i++) + { + rows.Add(Enumerable.Range(i * 6, 9).ToList()); + } + return rows; + } + } +} \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/_Imports.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/_Imports.razor index 4ab9008..8a36732 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/_Imports.razor +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/_Imports.razor @@ -1,4 +1,4 @@ -@using System.Net.Http +@using System.Net.Http @using System.Net.Http.Json @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @@ -7,3 +7,5 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop @using LittleTown.Blazor.Client +@using LittleTown.Blazor.Client.Components +@using LittleTown.StaticDataAcces; diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Board1.json b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Board1.json new file mode 100644 index 0000000..169a768 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Board1.json @@ -0,0 +1,276 @@ +{ + "Width": 9, + "Height": 6, + "Tiles": [ + { + "ResourceType": "None", + "PosX": 0, + "PosY": 0 + }, + { + "ResourceType": "Wood", + "PosX": 1, + "PosY": 0 + }, + { + "ResourceType": "Wood", + "PosX": 2, + "PosY": 0 + }, + { + "ResourceType": "None", + "PosX": 3, + "PosY": 0 + }, + { + "ResourceType": "Fish", + "PosX": 4, + "PosY": 0 + }, + { + "ResourceType": "Fish", + "PosX": 5, + "PosY": 0 + }, + { + "ResourceType": "None", + "PosX": 6, + "PosY": 0 + }, + { + "ResourceType": "None", + "PosX": 7, + "PosY": 0 + }, + { + "ResourceType": "Wood", + "PosX": 8, + "PosY": 0 + }, + { + "ResourceType": "None", + "PosX": 0, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 1, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 2, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 3, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 4, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 5, + "PosY": 1 + }, + { + "ResourceType": "Wood", + "PosX": 6, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 7, + "PosY": 1 + }, + { + "ResourceType": "None", + "PosX": 8, + "PosY": 1 + }, + { + "ResourceType": "Wood", + "PosX": 0, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 1, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 2, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 3, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 4, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 5, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 6, + "PosY": 2 + }, + { + "ResourceType": "None", + "PosX": 7, + "PosY": 2 + }, + { + "ResourceType": "Fish", + "PosX": 8, + "PosY": 2 + }, + { + "ResourceType": "Fish", + "PosX": 0, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 1, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 2, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 3, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 4, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 5, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 6, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 7, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 8, + "PosY": 3 + }, + { + "ResourceType": "None", + "PosX": 0, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 1, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 2, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 3, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 4, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 5, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 6, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 7, + "PosY": 4 + }, + { + "ResourceType": "None", + "PosX": 8, + "PosY": 4 + }, + { + "ResourceType": "Rock", + "PosX": 0, + "PosY": 5 + }, + { + "ResourceType": "None", + "PosX": 1, + "PosY": 5 + }, + { + "ResourceType": "Wood", + "PosX": 2, + "PosY": 5 + }, + { + "ResourceType": "Rock", + "PosX": 3, + "PosY": 5 + }, + { + "ResourceType": "None", + "PosX": 4, + "PosY": 5 + }, + { + "ResourceType": "Fish", + "PosX": 5, + "PosY": 5 + }, + { + "ResourceType": "None", + "PosX": 6, + "PosY": 5 + }, + { + "ResourceType": "Rock", + "PosX": 7, + "PosY": 5 + }, + { + "ResourceType": "Rock", + "PosX": 8, + "PosY": 5 + } + ] +} \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Buildings.json b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Buildings.json new file mode 100644 index 0000000..cf7dd73 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Buildings.json @@ -0,0 +1,183 @@ +[ + { + "Name": "Atelier", + "Price": { + "Rock": 2 + }, + "BeginnerBuilding": true + }, + { + "Name": "Bar", + "Price": { + "Rock": 2, + "Cereal": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Boulangerie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": true + }, + { + "Name": "Brasserie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Carriere", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": true + }, + { + "Name": "Champsdeble", + "Price": { + "Wood": 1 + }, + "BeginnerBuilding": false + }, + { + "Name": "Charpentier", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Epicerie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": true + }, + { + "Name": "Entrepot", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Eglise", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Foire", + "Price": { + "Wood": 4 + }, + "BeginnerBuilding": false + }, + { + "Name": "Fontaine", + "Price": { + "Rock": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Grenier", + "Price": { + "Wood": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Librairie", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": false + }, + { + "Name": "minedor", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": true + }, + { + "Name": "poissonnier", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": false + }, + { + "Name": "Ponton", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": false + }, + { + "Name": "Preteursurgage", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": true + }, + { + "Name": "puits", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": true + }, + { + "Name": "Restaurant", + "Price": { + "Wood": 2, + "Rock": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Statue", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Cathedrale", + "Price": { + "Rock": 6 + }, + "BeginnerBuilding": false + }, + { + "Name": "Residence", + "Price": { + "Piece": 6 + }, + "BeginnerBuilding": false + }, + { + "Name": "Chateau", + "Price": { + "Rock": 6 + }, + "BeginnerBuilding": true + }, + { + "Name": "Tourdegarde", + "Price": { + "Wood": 3, + "Rock": 3 + }, + "BeginnerBuilding": false + } +] \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Objectives.json b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Objectives.json new file mode 100644 index 0000000..ed666ae --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/wwwroot/data/Objectives.json @@ -0,0 +1,92 @@ +[ + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 2 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + }, + { + "Description": "desc", + "Formula": "formula", + "Points": 3 + } +] \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/Components/App.razor b/src/LittleTown.Blazor/LittleTown.Blazor/Components/App.razor index 3c60050..024f23d 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor/Components/App.razor +++ b/src/LittleTown.Blazor/LittleTown.Blazor/Components/App.razor @@ -1,4 +1,4 @@ - + diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/NavMenu.razor b/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/NavMenu.razor index 575db83..f7fb51b 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/NavMenu.razor +++ b/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/NavMenu.razor @@ -19,5 +19,10 @@ Counter + \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj b/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj index 936fa75..03296df 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj +++ b/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj @@ -12,4 +12,9 @@ + + + + + diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj.user b/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/src/LittleTown.Blazor/LittleTown.Blazor/LittleTown.Blazor.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/Program.cs b/src/LittleTown.Blazor/LittleTown.Blazor/Program.cs index 5b44698..b94ea23 100644 --- a/src/LittleTown.Blazor/LittleTown.Blazor/Program.cs +++ b/src/LittleTown.Blazor/LittleTown.Blazor/Program.cs @@ -1,5 +1,7 @@ -using LittleTown.Blazor.Client.Pages; +using LittleTown.Blazor.Client.Services; using LittleTown.Blazor.Components; +using LittleTown.Core.Ports; +using LittleTown.StaticDataAcces; var builder = WebApplication.CreateBuilder(args); @@ -8,6 +10,9 @@ builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -32,4 +37,4 @@ app.MapRazorComponents() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(LittleTown.Blazor.Client._Imports).Assembly); -app.Run(); +await app.RunAsync(); diff --git a/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs b/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs index 1b15716..01c6a25 100644 --- a/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs +++ b/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs @@ -44,7 +44,7 @@ public class Match { ArgumentNullException.ThrowIfNull(staticData); - _board = staticData.GetBoard(1); + _board = staticData.GetBoardAsync(1).GetAwaiter().GetResult(); _buildings = staticData.GetBuildings(); _objectives = staticData.GetObjectives(); } diff --git a/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs b/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs index 1e5f068..6829b43 100644 --- a/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs +++ b/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs @@ -5,6 +5,11 @@ namespace LittleTown.Core.Ports; /// public interface IStaticDataGetter { + /// Recuperer un plateau de jeu + /// la version du plateau (1 ou 2) + /// une instance du plateau avec les données statique + public Task GetBoardAsync(int version); + /// Recuperer un plateau de jeu /// la version du plateau (1 ou 2) /// une instance du plateau avec les données statique diff --git a/src/LittleTown.StaticDataAccess/LittleTown.StaticDataAccess.csproj b/src/LittleTown.StaticDataAccess/LittleTown.StaticDataAccess.csproj index 6241cd7..2748c16 100644 --- a/src/LittleTown.StaticDataAccess/LittleTown.StaticDataAccess.csproj +++ b/src/LittleTown.StaticDataAccess/LittleTown.StaticDataAccess.csproj @@ -1,4 +1,4 @@ - + net10.0 @@ -15,4 +15,11 @@ + + + + PreserveNewest + + + diff --git a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs index d985b56..2013fa6 100644 --- a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs +++ b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs @@ -26,12 +26,16 @@ public class StaticDataGetter : IStaticDataGetter _buildingData = buildingData; } - /// Constructeur avec les chemins par défaut, à utiliser pour les tests seulement + /// Constructeur avec les chemins par défaut public StaticDataGetter() { - string boardPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Board1.json"); - string buildingPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json"); - string objectivesPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Objectives.json"); + // Les fichiers JSON sont copiés dans le dossier de build via le .csproj + // Ils sont donc toujours relatifs à l'exécutable + var baseDirectory = AppContext.BaseDirectory; + string boardPath = Path.Combine(baseDirectory, "Data", "Board1.json"); + string buildingPath = Path.Combine(baseDirectory, "Data", "Buildings.json"); + string objectivesPath = Path.Combine(baseDirectory, "Data", "Objectives.json"); + ReadFiles(boardPath, buildingPath, objectivesPath); } @@ -49,6 +53,11 @@ public class StaticDataGetter : IStaticDataGetter return board; } + public Task GetBoardAsync(int version) + { + return Task.FromResult(GetBoard(version)); + } + /// public ICollection GetBuildings() { diff --git a/src/LittleTown.sln b/src/LittleTown.sln index 8f260b3..e5918a7 100644 --- a/src/LittleTown.sln +++ b/src/LittleTown.sln @@ -14,8 +14,14 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LittleTown.Blazor", "LittleTown.Blazor", "{5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Blazor", "LittleTown.Blazor\LittleTown.Blazor\LittleTown.Blazor.csproj", "{12579937-5A8E-44F9-AC45-B742B311102E}" + ProjectSection(ProjectDependencies) = postProject + {FA0DE9D0-F788-4734-BDA3-F89F71D757BA} = {FA0DE9D0-F788-4734-BDA3-F89F71D757BA} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Blazor.Client", "LittleTown.Blazor\LittleTown.Blazor.Client\LittleTown.Blazor.Client.csproj", "{83375A45-793A-462B-BAB8-AD432FA49350}" + ProjectSection(ProjectDependencies) = postProject + {FA0DE9D0-F788-4734-BDA3-F89F71D757BA} = {FA0DE9D0-F788-4734-BDA3-F89F71D757BA} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution