Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character movement #77

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<EquipmentPopup>(_equipmentPopupParameters)">
<img src="assets/infobutton.svg" />

</div>
</div>
</div>
Expand Down Expand Up @@ -85,7 +86,7 @@
<div class="journal">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<JournalPopup>()"></div><img src="assets/infobutton.svg" />
<div @onclick="() => _popup.ShowComponent<JournalPopup>()" ></div><img src="assets/infobutton.svg" />
</div>
</div>

Expand Down Expand Up @@ -130,7 +131,6 @@
</div>
</div>


@code {
private User _user = new();
private readonly ObservableCollection<Item> _equipment = new();
Expand Down
8 changes: 7 additions & 1 deletion Server/Components/Popups/MapPopup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
@using Fracture.Server.Modules.MapGenerator.UI
@using Fracture.Server.Modules.MapGenerator.UI.Models

@inject NavigationManager NavigationManager

@page "/map"

<div class="row">
<MapView Map="Map" MapDisplayData="MapDisplayData" Path="null" IsMiniMap="false"></MapView>
<MapView Map="Map" MapDisplayData="MapDisplayData" Path="null" IsMiniMap="false" CharacterX="x" CharacterY="y"></MapView>
</div>

@code {
[Parameter] public required MapData Map { get; set; }
[Parameter] public required MapDisplayData MapDisplayData { get; set; }
int x = MapView.CharacterXX;
int y = MapView.CharacterYY;
}
3 changes: 2 additions & 1 deletion Server/Components/UI/PopupContainer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<DynamicComponent Type="@_componentType" Parameters="@_parameters" @ref="Component" />
}
<div>
<button class="closeBtn" @onclick="() => IsVisible = false"><img src="assets/closebutton.svg" /></button>
<button class="closeBtn" @onclick="() => IsVisible=false"><img src="assets/closebutton.svg" /></button>
</div>
</div>

Expand All @@ -23,6 +23,7 @@
StateHasChanged();
}


public DynamicComponent? Component = null;
private Type? _componentType = null;
private IDictionary<string, object>? _parameters;
Expand Down
88 changes: 81 additions & 7 deletions Server/Modules/MapGenerator/UI/MapView.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@using Fracture.Server.Modules.MapGenerator.Models
@using Fracture.Server.Modules.MapGenerator.UI.Models
@using Fracture.Server.Modules.Pathfinding.Models
@using Microsoft.AspNetCore.Components.Web

<div id="map">


<div id="map" tabindex="0" @onkeydown="HandleKeyDown">
@if (Map != null && MapDisplayData != null)
{
<table class="@(IsMiniMap ? "miniMapTable" : "mapTable")">
Expand All @@ -11,26 +14,34 @@
<tr>
@for (int x = 0; x < Map.Grid.GetLength(0); x++)
{
@if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position)
@if (x == CharacterXX && y == CharacterYY)
{


<td style='background: @GetTileColor(@Map.Grid[x, y])'>
C
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position)
{
<td style='background: @GetTileColor(@Map.Grid[x,y])'>
x:@x<br />y:@y
<td style='background: @GetTileColor(@Map.Grid[x, y])'>
x:@x<br/>y:@y
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Noise)
{
<td style="background: @GetTileColor(@Map.Grid[x,y])">
<td style="background: @GetTileColor(@Map.Grid[x, y])">
@Math.Round(Map.Grid[x, y].NoiseValue, 2)
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.None)
{
<td style='background: @GetTileColor(@Map.Grid[x,y])'>
<td style='background: @GetTileColor(@Map.Grid[x, y])'>
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Path)
{
<td style='font-size: 16px; background: @GetTileColor(@Map.Grid[x,y])'>
<td style='font-size: 16px; background: @GetTileColor(@Map.Grid[x, y])'>
@GetPathForTile(Map.Grid[x, y])
</td>
}
Expand All @@ -53,7 +64,19 @@

[Parameter]
public bool IsMiniMap { get; set; } = true;

private bool isMoving = false;
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<string> _blockingColors = new HashSet<string>
{
"#21618C","#2E86C1"
};

private string GetTileColor(Node node)
{
if (MapDisplayData!.ShowColorMap)
Expand Down Expand Up @@ -101,4 +124,55 @@
_ => ""
};
}

private void HandleKeyDown(KeyboardEventArgs e)
{
if (IsMiniMap==false)
{
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++;

Check warning on line 142 in Server/Modules/MapGenerator/UI/MapView.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
break;
case "ArrowLeft":
if (CharacterXX > 0) newX--;
break;
case "ArrowRight":
if (CharacterXX < Map.Grid.GetLength(0)-1 ) newX++;

Check warning on line 148 in Server/Modules/MapGenerator/UI/MapView.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
break;
}

if (CanMoveToTile(newX, newY))
{
CharacterXX = newX;
CharacterYY = newY;
StateHasChanged();
}

Task.Delay(100).ContinueWith(_ =>
{
isMoving = false;
});
}


}

private bool CanMoveToTile(int x, int y)
{
Node targetNode = Map.Grid[x, y];

Check warning on line 170 in Server/Modules/MapGenerator/UI/MapView.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
string tileColor = GetTileColor(targetNode);

return !_blockingColors.Contains(tileColor);
}


}

Loading