Skip to content
Merged
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
21 changes: 5 additions & 16 deletions Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@using Fracture.Server.Modules.MapGenerator.UI.Models
@using Fracture.Server.Modules.Pathfinding.Models
@using Fracture.Server.Modules.Shared
@using Fracture.Server.Modules.UI
@using Fracture.Server.Modules.Users
@using Fracture.Server.Modules.Users.Services
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
Expand All @@ -26,6 +27,8 @@
@inject UserService UserService
@inject MovementService MovementService
@inject ILogger<GamePage> Logger
@inject IsVisibleService IsVisibleService


<link rel="icon" type="image/png" href="assets/icons/favicon.png" />

Expand All @@ -38,7 +41,7 @@
<div class="stats">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<StatsPopup>()">

Check warning on line 44 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.

Check warning on line 44 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
<img src="assets/icons/infobutton.svg" />
</div>
</div>
Expand All @@ -48,7 +51,7 @@
<div class="equipment">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<EquipmentPopup>()">

Check warning on line 54 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
<img src="assets/icons/infobutton.svg" />

</div>
Expand Down Expand Up @@ -98,33 +101,19 @@
<div class="journal">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<JournalPopup>()"></div>

Check warning on line 104 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
<img src="assets/icons/infobutton.svg" />
</div>
</div>

<div class="journalPage">
<p>
<span>Log1:<br></span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum numquam
quaerat officiis placeat ipsa cupiditate nobis dolore perferendis, odit culpa perspiciatis, vero
delectus ex omnis ad magni, deserunt quae? Ex.
</p>
<p>
<span>Log2:<br></span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum numquam
quaerat officiis placeat ipsa cupiditate nobis dolore perferendis, odit culpa perspiciatis, vero
delectus ex omnis ad magni, deserunt quae? Ex.
</p>
<p>
<span>Log3:<br></span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum numquam
quaerat officiis placeat ipsa cupiditate nobis dolore perferendis, odit culpa perspiciatis, vero
delectus ex omnis ad magni, deserunt quae? Ex.
</p>
<RequestPopupContainer @ref="_requestPopup"></RequestPopupContainer>
</div>
</div>
<div class="miniMap">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<MapPopup>(_mapPopupParameters)">

Check warning on line 116 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
<img src="assets/icons/infobutton.svg" />
</div>
</div>
Expand All @@ -134,12 +123,12 @@
<div class="settings">
<div class="settingsBtn">
<div class="settingsBtn-content">
<img @onclick="() => _popup.ShowComponent<SettingsPopup>()" src="assets/icons/settingsbutton.svg" />

Check warning on line 126 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
</div>
</div>
<div class="settingsBtn">
<div class="settingsBtn-content">
<img @onclick="() => _popup.ShowComponent<TestPopup>()" src="assets/icons/hourglassbutton.svg" />
<img @onclick="() => { if (MovementService.IsMovementLocked) { return; } if (IsVisibleService.IsVisible == false) { IsVisibleService.Show<GameLogsPopup>();} else{ IsVisibleService?.Hide(); StateHasChanged();} }" src="assets/icons/hourglassbutton.svg" />
</div>
</div>
<div class="settingsBtn">
Expand Down
16 changes: 12 additions & 4 deletions Server/Components/Pages/GamePage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
using Fracture.Server.Modules.MapGenerator.Models.Map;
using Fracture.Server.Modules.MapGenerator.UI.Models;
using Fracture.Server.Modules.Pathfinding.Models;
using Fracture.Server.Modules.UI;
using Fracture.Server.Modules.Users.Models;
using Fracture.Server.Modules.Users.Services;
using Microsoft.AspNetCore.Components;

namespace Fracture.Server.Components.Pages;

public partial class GamePage : IAsyncDisposable
{
private Dictionary<string, object> _mapPopupParameters = null!;
private PopupContainer _popup = null!;
private PopupContainer? _popup = null!;
private RequestPopupContainer? _requestPopup;

[Inject]
public IsVisibleService _isVisibleService { get; set; } = default!;

public string BackgroundImage { get; set; } = string.Empty;
private readonly MapDisplayOptions _mapDisplayOptions = new();
private List<IPathfindingNode>? Path { get; set; }
Expand Down Expand Up @@ -50,6 +57,7 @@ protected override async Task OnInitializedAsync()

MovementService.OnItemPickupRequested += async (sender, item) =>
{
await MovementService.RequestItemPickup();
var parameters = new Dictionary<string, object>
{
{ "Item", item },
Expand All @@ -59,7 +67,7 @@ protected override async Task OnInitializedAsync()
async () =>
{
await MovementService.ConfirmPickupAsync();
_popup.Hide();
_isVisibleService?.Hide();
}
)
},
Expand All @@ -69,13 +77,13 @@ protected override async Task OnInitializedAsync()
async () =>
{
await MovementService.CancelPickupAsync();
_popup.Hide();
_isVisibleService?.Hide();
}
)
},
};

_popup.ShowComponent<ItemPickupRequest>(parameters);
_isVisibleService?.Show<ItemPickupRequest>(parameters);
};

_mapDisplayOptions.ShowColorMap = true;
Expand Down
13 changes: 13 additions & 0 deletions Server/Components/Popups/GameLogsPopup.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum laoreet est eu dolor cursus mattis. Sed ut nisi scelerisque, cursus elit eget, vehicula metus. Ut risus velit, volutpat sed dictum id, efficitur non leo. Donec vitae ligula nec sem lobortis imperdiet. Phasellus lacinia vulputate arcu, id hendrerit sem commodo non. Nulla ante turpis, blandit sed viverra nec, tempus nec metus. Ut sit amet diam commodo, consectetur eros at, suscipit erat. Sed ac ultrices felis. Nunc velit augue, placerat ut ipsum a, semper lacinia lorem. Proin lacinia, mi a congue placerat, metus sem scelerisque ex, sit amet efficitur sem purus non ipsum. Vestibulum efficitur commodo augue, nec luctus odio vestibulum at. Pellentesque efficitur nisl sit amet magna rutrum, blandit ultrices nisl lobortis. Cras in consectetur nibh. Ut malesuada mi ut lacinia aliquam. Vivamus suscipit posuere diam, eget sodales nisl faucibus et. Vestibulum posuere erat magna, nec rutrum enim tempus vel.

Nam feugiat ex id placerat ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec tortor sapien, feugiat rutrum lacus nec, volutpat euismod elit. Ut tincidunt, odio at pulvinar luctus, nulla arcu porttitor ante, ut lobortis leo ligula nec ex. Suspendisse fringilla, massa ac blandit faucibus, velit purus scelerisque felis, quis eleifend metus velit eu quam. Integer at porttitor enim. Sed tincidunt porttitor vulputate. Pellentesque nibh libero, malesuada et maximus volutpat, congue eu nunc. Cras rutrum justo purus, id iaculis ligula ultricies vel. Praesent in auctor elit. Duis pulvinar, velit at sodales cursus, nunc urna eleifend nulla, nec fringilla sem nibh ut nisi. Integer vestibulum turpis ac lacus congue, in iaculis ipsum blandit.

Sed fermentum est mauris, in condimentum dolor maximus eu. Quisque condimentum, purus quis congue dignissim, metus nunc facilisis mi, a suscipit ante enim eget dui. Nunc eu aliquet turpis. Nam dapibus orci ornare, mattis ante id, maximus felis. In a gravida tellus. Donec aliquet urna vitae aliquam gravida. Integer luctus sapien quis ante tincidunt feugiat. Nulla eu dui ex. Suspendisse porttitor tincidunt nulla. Aenean non ultricies leo, euismod dictum elit. Morbi eget sem in lorem viverra aliquam at mollis erat.
</div>

@code {

}
2 changes: 1 addition & 1 deletion Server/Components/Popups/ItemPickupRequest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="item-popup">
<h3>You found a new item, Do you want to pick it up?</h3>
<div class="item-title">
<strong>@Item.Name</strong> (@Item.Type) - @Item.Rarity

Check warning on line 7 in Server/Components/Popups/ItemPickupRequest.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.

Check warning on line 7 in Server/Components/Popups/ItemPickupRequest.razor

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
</div>

<div class="item-stats">
Expand All @@ -18,7 +18,7 @@
</div>

@code {
[Parameter] public Item Item { get; set; } = null!;
[Parameter] public Item? Item { get; set; }
[Parameter] public Func<Task>? OnConfirm { get; set; }
[Parameter] public Func<Task>? OnCancel { get; set; }

Expand Down
1 change: 0 additions & 1 deletion Server/Components/UI/PopupContainer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</div>

@code {
GamePage _gamePage = new();
public bool IsVisible { get; set; }

public void ShowComponent<T>(IDictionary<string, object>? parameters = null)
Expand Down
30 changes: 30 additions & 0 deletions Server/Components/UI/RequestPopupContainer.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@using Fracture.Server.Modules.UI
@rendermode InteractiveServer

@inject IsVisibleService IsVisibleService

@implements IDisposable

<div class="@(IsVisibleService.IsVisible ? "" : "hidden")">
@if (IsVisibleService.ComponentType is not null)
{
<DynamicComponent Type="@IsVisibleService.ComponentType" Parameters="@IsVisibleService.Parameters" />
}
<div>
</div>
</div>

@code {


protected override void OnInitialized()
{
IsVisibleService.OnChange += StateHasChanged;
}

public void Dispose()
{
IsVisibleService.OnChange -= StateHasChanged;
}

}
31 changes: 31 additions & 0 deletions Server/Modules/UI/IsVisibleService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Fracture.Server.Modules.UI;

public class IsVisibleService
{
public event Action? OnChange;

public bool IsVisible { get; private set; }
public Type? ComponentType { get; private set; }
public IDictionary<string, object>? Parameters { get; private set; }

public void Show<T>(IDictionary<string, object>? parameters = null)
{
ComponentType = typeof(T);
Parameters = parameters;
IsVisible = true;
NotifyStateChanged();
}

public void Hide()
{
IsVisible = false;
ComponentType = null;
Parameters = null;
NotifyStateChanged();
}

private void NotifyStateChanged()
{
OnChange?.Invoke();
}
}
13 changes: 13 additions & 0 deletions Server/Modules/Users/Services/MovementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

public int CurrentX { get; private set; }
public int CurrentY { get; private set; }
public bool IsMovementLocked { get; private set; }

public event EventHandler<Position>? OnMoved;
public event EventHandler<(Map, Position)>? OnMapEntered;
Expand Down Expand Up @@ -102,7 +103,7 @@
else
{
// Pozycja nie jest walkable - losuj nową
var randomPos = CurrentMap.GetRandomWalkableNode();

Check warning on line 106 in Server/Modules/Users/Services/MovementService.cs

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.

Check warning on line 106 in Server/Modules/Users/Services/MovementService.cs

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
CurrentX = randomPos.X;
CurrentY = randomPos.Y;
_lastSavedX = randomPos.X;
Expand Down Expand Up @@ -178,6 +179,11 @@

public bool CanMove(int x, int y)
{
if (IsMovementLocked)
{
return false;
}

return CurrentMap != null
&& x >= 0
&& y >= 0
Expand Down Expand Up @@ -244,6 +250,7 @@
_userService.Inventory.Add(item);

OnItemEncountered?.Invoke(this, position);
IsMovementLocked = false;
return true;
}

Expand All @@ -263,5 +270,11 @@
position.X,
position.Y
);
IsMovementLocked = false;
}

public async Task RequestItemPickup()
{
IsMovementLocked = true;
}
}
3 changes: 3 additions & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Fracture.Server.Modules.Shared;
using Fracture.Server.Modules.Shared.Configuration;
using Fracture.Server.Modules.Shared.NameGenerators;
using Fracture.Server.Modules.UI;
using Fracture.Server.Modules.Users.Services;
using Hangfire;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -64,6 +65,8 @@
builder.Services.AddSingleton<MapDataImportService>();
builder.Services.AddSingleton<MapManagerService>();

builder.Services.AddScoped<IsVisibleService>();

builder.Services.AddSingletonIfFeatureEnabled<IChatClient>(
FeatureFlags.USE_AI,
sp =>
Expand Down
Loading