From a22559e96a8ba460d521e65b6a54269f892851e7 Mon Sep 17 00:00:00 2001 From: Barsol6 Date: Sun, 3 Nov 2024 20:05:19 +0100 Subject: [PATCH 1/5] feat: added character movement on the minimap using arrow keys --- Server/Modules/MapGenerator/UI/MapView.razor | 79 ++++++++++++++++++-- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/Server/Modules/MapGenerator/UI/MapView.razor b/Server/Modules/MapGenerator/UI/MapView.razor index 6fdea5d..c3b821a 100644 --- a/Server/Modules/MapGenerator/UI/MapView.razor +++ b/Server/Modules/MapGenerator/UI/MapView.razor @@ -1,8 +1,9 @@ @using Fracture.Server.Modules.MapGenerator.Models @using Fracture.Server.Modules.MapGenerator.UI.Models @using Fracture.Server.Modules.Pathfinding.Models +@using Microsoft.AspNetCore.Components.Web -
+
@if (Map != null && MapDisplayData != null) { @@ -11,26 +12,32 @@ @for (int x = 0; x < Map.Grid.GetLength(0); x++) { - @if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position) + @if (x == CharacterX && y == CharacterY) + { + + } + else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position) { - } else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Noise) { - } else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.None) { - } else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Path) { - } @@ -53,7 +60,16 @@ [Parameter] public bool IsMiniMap { get; set; } = true; - + + private bool isMoving = false; + private int CharacterX { get; set; } = 16; + private int CharacterY { get; set; } = 16; + + private readonly HashSet _blockingColors = new HashSet + { + "#21618C","#2E86C1" + }; + private string GetTileColor(Node node) { if (MapDisplayData!.ShowColorMap) @@ -101,4 +117,51 @@ _ => "" }; } + + private void HandleKeyDown(KeyboardEventArgs e) + { + if (isMoving) return; + isMoving = true; + int newX = CharacterX; + int newY = CharacterY; + switch (e.Key) + { + case "ArrowUp": + if (CharacterY > 0) newY--;; + break; + case "ArrowDown": + if (CharacterY < Map.Grid.GetLength(1) ) newY++; + break; + case "ArrowLeft": + if (CharacterX > 0) newX--; + break; + case "ArrowRight": + if (CharacterX < Map.Grid.GetLength(0) ) newX++; + break; + } + + if (CanMoveToTile(newX, newY)) + { + CharacterX = newX; + CharacterY = newY; + + } + + Task.Delay(100).ContinueWith(_ => + { + isMoving = false; + InvokeAsync(StateHasChanged); + }); + + } + + private bool CanMoveToTile(int x, int y) + { + Node targetNode = Map.Grid[x, y]; + string tileColor = GetTileColor(targetNode); + + return !_blockingColors.Contains(tileColor); + } + +} } From 07a07930bb66999c83bb3d03906098857db0dc55 Mon Sep 17 00:00:00 2001 From: Barsol6 Date: Sun, 3 Nov 2024 20:30:13 +0100 Subject: [PATCH 2/5] feat: Added synchronisation with popup --- Server/Components/Popups/MapPopup.razor | 2 +- Server/Modules/MapGenerator/UI/MapView.razor | 30 +++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Server/Components/Popups/MapPopup.razor b/Server/Components/Popups/MapPopup.razor index 1bb2efd..7001031 100644 --- a/Server/Components/Popups/MapPopup.razor +++ b/Server/Components/Popups/MapPopup.razor @@ -3,7 +3,7 @@ @using Fracture.Server.Modules.MapGenerator.UI.Models
- +
@code { diff --git a/Server/Modules/MapGenerator/UI/MapView.razor b/Server/Modules/MapGenerator/UI/MapView.razor index c3b821a..cb93eb6 100644 --- a/Server/Modules/MapGenerator/UI/MapView.razor +++ b/Server/Modules/MapGenerator/UI/MapView.razor @@ -12,7 +12,7 @@
@for (int x = 0; x < Map.Grid.GetLength(0); x++) { - @if (x == CharacterX && y == CharacterY) + @if (x == CharacterXX && y == CharacterYY) { - } + + } else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position) {
+ C + - x:@x
y:@y +
+ x:@x
y:@y
+ @Math.Round(Map.Grid[x, y].NoiseValue, 2) + + @GetPathForTile(Map.Grid[x, y])
C @@ -62,9 +62,12 @@ public bool IsMiniMap { get; set; } = true; private bool isMoving = false; - private int CharacterX { get; set; } = 16; - private int CharacterY { get; set; } = 16; - + public static int CharacterXX { get; set; } = 16; + public static int CharacterYY { get; set; } = 16; + [Parameter] public int CharacterX { get; set; } = CharacterXX; + [Parameter] public int CharacterY { get; set; } = CharacterXX; + + private readonly HashSet _blockingColors = new HashSet { "#21618C","#2E86C1" @@ -122,35 +125,34 @@ { if (isMoving) return; isMoving = true; - int newX = CharacterX; - int newY = CharacterY; + int newX = CharacterXX; + int newY = CharacterYY; switch (e.Key) { case "ArrowUp": - if (CharacterY > 0) newY--;; + if (CharacterYY > 0) newY--;; break; case "ArrowDown": - if (CharacterY < Map.Grid.GetLength(1) ) newY++; + if (CharacterYY < Map.Grid.GetLength(1)-1 ) newY++; break; case "ArrowLeft": - if (CharacterX > 0) newX--; + if (CharacterXX > 0) newX--; break; case "ArrowRight": - if (CharacterX < Map.Grid.GetLength(0) ) newX++; + if (CharacterXX < Map.Grid.GetLength(0)-1 ) newX++; break; } if (CanMoveToTile(newX, newY)) { - CharacterX = newX; - CharacterY = newY; - + CharacterXX = newX; + CharacterYY = newY; + StateHasChanged(); } Task.Delay(100).ContinueWith(_ => { isMoving = false; - InvokeAsync(StateHasChanged); }); } From 619fd2d64f52aec36b2905ba6f5131965f99996f Mon Sep 17 00:00:00 2001 From: Barsol6 Date: Wed, 6 Nov 2024 18:30:02 +0100 Subject: [PATCH 3/5] feat: synchronisation between popup and GamePage --- Server/Components/Popups/MapPopup.razor | 14 +++- Server/Modules/MapGenerator/UI/MapView.razor | 75 +++++++++++--------- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/Server/Components/Popups/MapPopup.razor b/Server/Components/Popups/MapPopup.razor index 7001031..dbf3468 100644 --- a/Server/Components/Popups/MapPopup.razor +++ b/Server/Components/Popups/MapPopup.razor @@ -2,11 +2,23 @@ @using Fracture.Server.Modules.MapGenerator.UI @using Fracture.Server.Modules.MapGenerator.UI.Models +@inject NavigationManager NavigationManager + +@page "/map" +
- + + @update_map
@code { [Parameter] public required MapData Map { get; set; } [Parameter] public required MapDisplayData MapDisplayData { get; set; } + int x = MapView.CharacterXX; + int y = MapView.CharacterYY; + + private void update_map() + { + NavigationManager.NavigateTo("/map"); + } } \ No newline at end of file diff --git a/Server/Modules/MapGenerator/UI/MapView.razor b/Server/Modules/MapGenerator/UI/MapView.razor index cb93eb6..9682163 100644 --- a/Server/Modules/MapGenerator/UI/MapView.razor +++ b/Server/Modules/MapGenerator/UI/MapView.razor @@ -3,6 +3,8 @@ @using Fracture.Server.Modules.Pathfinding.Models @using Microsoft.AspNetCore.Components.Web + +
@if (Map != null && MapDisplayData != null) { @@ -13,11 +15,13 @@ @for (int x = 0; x < Map.Grid.GetLength(0); x++) { @if (x == CharacterXX && y == CharacterYY) - { -
+ { + + + C - @@ -123,37 +127,41 @@ private void HandleKeyDown(KeyboardEventArgs e) { - if (isMoving) return; - isMoving = true; - int newX = CharacterXX; - int newY = CharacterYY; - switch (e.Key) + if (IsMiniMap==false) { - case "ArrowUp": - if (CharacterYY > 0) newY--;; - break; - case "ArrowDown": - if (CharacterYY < Map.Grid.GetLength(1)-1 ) newY++; - break; - case "ArrowLeft": - if (CharacterXX > 0) newX--; - break; - case "ArrowRight": - if (CharacterXX < Map.Grid.GetLength(0)-1 ) newX++; - break; - } + if (isMoving) return; + isMoving = true; + int newX = CharacterXX; + int newY = CharacterYY; + switch (e.Key) + { + case "ArrowUp": + if (CharacterYY > 0) newY--;; + break; + case "ArrowDown": + if (CharacterYY < Map.Grid.GetLength(1)-1 ) newY++; + break; + case "ArrowLeft": + if (CharacterXX > 0) newX--; + break; + case "ArrowRight": + if (CharacterXX < Map.Grid.GetLength(0)-1 ) newX++; + break; + } - if (CanMoveToTile(newX, newY)) - { - CharacterXX = newX; - CharacterYY = newY; - StateHasChanged(); - } + if (CanMoveToTile(newX, newY)) + { + CharacterXX = newX; + CharacterYY = newY; + StateHasChanged(); + } - Task.Delay(100).ContinueWith(_ => - { - isMoving = false; - }); + Task.Delay(100).ContinueWith(_ => + { + isMoving = false; + }); + } + } @@ -164,6 +172,7 @@ return !_blockingColors.Contains(tileColor); } + } -} + From 30919a32079b81fd8c913c6892cd886460969932 Mon Sep 17 00:00:00 2001 From: Barsol6 Date: Thu, 7 Nov 2024 12:37:53 +0100 Subject: [PATCH 4/5] refactor: fixed a bit of mess I've accidentally created --- Server/Components/Pages/GamePage.razor | 4 ++-- Server/Components/UI/PopupContainer.razor | 3 ++- Server/Fracture.Server.csproj | 1 + Server/Modules/MapGenerator/Services/MapGeneratorService.cs | 4 ++-- Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs | 2 +- Server/wwwroot/css/game.css | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Server/Components/Pages/GamePage.razor b/Server/Components/Pages/GamePage.razor index ae11af0..1b0f09a 100644 --- a/Server/Components/Pages/GamePage.razor +++ b/Server/Components/Pages/GamePage.razor @@ -45,6 +45,7 @@
+
@@ -84,7 +85,7 @@
-
+
@@ -129,7 +130,6 @@
- @code { private User _user = new(); private readonly ObservableCollection _equipment = new(); diff --git a/Server/Components/UI/PopupContainer.razor b/Server/Components/UI/PopupContainer.razor index 900339b..26b5993 100644 --- a/Server/Components/UI/PopupContainer.razor +++ b/Server/Components/UI/PopupContainer.razor @@ -7,7 +7,7 @@ }
- +
@@ -23,6 +23,7 @@ StateHasChanged(); } + public DynamicComponent? Component = null; private Type? _componentType = null; private IDictionary? _parameters; diff --git a/Server/Fracture.Server.csproj b/Server/Fracture.Server.csproj index 5201e62..d24a161 100644 --- a/Server/Fracture.Server.csproj +++ b/Server/Fracture.Server.csproj @@ -26,6 +26,7 @@ + diff --git a/Server/Modules/MapGenerator/Services/MapGeneratorService.cs b/Server/Modules/MapGenerator/Services/MapGeneratorService.cs index 082d462..dd6e319 100644 --- a/Server/Modules/MapGenerator/Services/MapGeneratorService.cs +++ b/Server/Modules/MapGenerator/Services/MapGeneratorService.cs @@ -10,9 +10,9 @@ public class MapGeneratorService : IMapGeneratorService private MapData _mapData = default!; private readonly float _persistence = 0.5f; - private readonly float _lacunarity = 2f; + private readonly float _lacunarity = 1f; private readonly int _octaves = 5; - private readonly float _scale = 5f; + private readonly float _scale = 4.5f; private Random _rnd = new Random(); diff --git a/Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs b/Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs index 35364a7..491b5ad 100644 --- a/Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs +++ b/Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs @@ -24,7 +24,7 @@ public static class FalloffGenerator private static float Evaluate(float value) { const float a = 3; - const float b = 4.2f; + const float b = 5f; return (float)(Math.Pow(value, a) / (Math.Pow(value, a) + Math.Pow(b - b * value, a))); } diff --git a/Server/wwwroot/css/game.css b/Server/wwwroot/css/game.css index a2189b1..ce17421 100644 --- a/Server/wwwroot/css/game.css +++ b/Server/wwwroot/css/game.css @@ -406,7 +406,7 @@ body { scroll-snap-type: y mandatory; scroll-behavior: smooth; } -.eqCiolumn span { +.eqColumn span { font-size: 1.1em; font-weight: bolder; } From 3cf7e03c670b48096a0f8a02b61a71206752694e Mon Sep 17 00:00:00 2001 From: Barsol6 Date: Thu, 7 Nov 2024 14:47:08 +0100 Subject: [PATCH 5/5] refactor: removed empty folder --- Server/Fracture.Server.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/Fracture.Server.csproj b/Server/Fracture.Server.csproj index d24a161..5201e62 100644 --- a/Server/Fracture.Server.csproj +++ b/Server/Fracture.Server.csproj @@ -26,7 +26,6 @@ -