Skip to content

Commit

Permalink
feat: add catalogue editor draft with name editing
Browse files Browse the repository at this point in the history
  • Loading branch information
amis92 committed Nov 27, 2023
1 parent ff76d7b commit 1538065
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/Phalanx.GodMode.NativeApp/Infrastructure/WorkspaceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using WarHub.ArmouryModel.Concrete;
using WarHub.ArmouryModel.Workspaces.BattleScribe;

namespace Phalanx.GodMode.NativeApp.Infrastructure;
internal class WorkspaceManager
{
public XmlWorkspace? CurrentXmlWorkspace { get; set; }

public WhamCompilation? CurrentCompilation { get; set; }
}
2 changes: 2 additions & 0 deletions src/Phalanx.GodMode.NativeApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Fast.Components.FluentUI;
using Microsoft.Fast.Components.FluentUI.Infrastructure;
using Phalanx.GodMode.NativeApp.Infrastructure;

namespace Phalanx.GodMode.NativeApp;
public static class MauiProgram
Expand Down Expand Up @@ -29,6 +30,7 @@ public static MauiApp CreateMauiApp()
});
builder.Services.AddScoped<IStaticAssetService, FileBasedStaticAssetService>();
builder.Services.AddSingleton<StaticAssetCache>();
builder.Services.AddSingleton<WorkspaceManager>();

return builder.Build();
}
Expand Down
57 changes: 57 additions & 0 deletions src/Phalanx.GodMode.NativeApp/Pages/CatalogueEdit.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@page "/editor"

@using Phalanx.GodMode.NativeApp.Infrastructure;
@using WarHub.ArmouryModel;
@using WarHub.ArmouryModel.Source;

@inject WorkspaceManager Manager

@if (CatalogueId is null)
{
<h3>no catalogue selected</h3>
}
else
{
var node = (CatalogueBaseNode) catalogue!.GetDeclaration()!;
<h3>Catalogue Edit</h3>

<h4>name: @catalogue!.Name</h4>
<h5>id: @catalogue!.Id</h5>

<div>
<label>
Name:
<FluentTextField @bind-Value:get=catalogue.Name @bind-Value:set="x => Update(node, node.WithName(x))"></FluentTextField>
</label>
</div>
}

@code {

[Parameter, SupplyParameterFromQuery(Name = "id")]
public string? CatalogueId { get; set; }

ICatalogueSymbol? catalogue;

protected override void OnParametersSet()
{
base.OnParametersSet();
if (CatalogueId is { } id && Manager.CurrentCompilation is { } compilation)
{
catalogue = compilation.GlobalNamespace.Catalogues.Single(x => x.Id == id);
}
}

void Update(CatalogueBaseNode oldNode, CatalogueBaseNode newNode)
{
var compilation = Manager.CurrentCompilation!;
var oldTree = compilation.SourceTrees.Single(x => x.GetRoot() == oldNode);
var newCompilation = compilation.ReplaceSourceTree(oldTree, oldTree.WithRoot(newNode));
Manager.CurrentCompilation = newCompilation;
}

class CatalogueVm
{

}
}
6 changes: 3 additions & 3 deletions src/Phalanx.GodMode.NativeApp/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Welcome to GodMode, the data editor by Project Phalanx. The one with blackjack a
</p>
}

@if (compilation is not null)
@if (Manager.CurrentCompilation is { } compilation)
{
@foreach (var root in compilation.GlobalNamespace.Catalogues)
{
<FluentCard Style="padding: 8px; margin: 6px;">
<FluentCard Style="padding: 8px; margin: 6px;" @onclick="() => Edit(root)">
<div>
<h4>
@root.Name
Expand All @@ -31,4 +31,4 @@ Welcome to GodMode, the data editor by Project Phalanx. The one with blackjack a
</div>
</FluentCard>
}
}
}
22 changes: 16 additions & 6 deletions src/Phalanx.GodMode.NativeApp/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
using WarHub.ArmouryModel;
using WarHub.ArmouryModel.Workspaces.BattleScribe;
using WarHub.ArmouryModel.Source;
using WarHub.ArmouryModel.ProjectModel;
using System;
using Microsoft.AspNetCore.Components;
using Phalanx.GodMode.NativeApp.Infrastructure;

namespace Phalanx.GodMode.NativeApp.Pages;

public partial class Index
{
[Inject]
NavigationManager Nav { get; set; } = null!;
[Inject]
WorkspaceManager Manager { get; set; } = null!;

string? selectedFolder;
private XmlWorkspace? xmlws;
private WhamCompilation? compilation;
private string? loadingStatus;

void Edit(ICatalogueSymbol root)
{
Nav.NavigateTo(Nav.GetUriWithQueryParameters("/editor", new Dictionary<string, object?> { ["id"] = root.Id }));
}

public async Task OpenFolder()
{
var result =
Expand All @@ -36,11 +44,13 @@ public async Task OpenFolder()
progress.Report("listing files");
await Task.Run(async () =>
{
xmlws = XmlWorkspace.CreateFromDirectory(selectedFolder);
var xmlws = XmlWorkspace.CreateFromDirectory(selectedFolder);
Manager.CurrentXmlWorkspace = xmlws;
progress.Report("loading files");
var roots = await LoadFiles(xmlws.GetDocuments(SourceKind.Catalogue, SourceKind.Gamesystem)).ToListAsync();
progress.Report("compiling data");
compilation = WhamCompilation.Create(roots.ToImmutableArray());
var compilation = WhamCompilation.Create(roots.ToImmutableArray());
Manager.CurrentCompilation = compilation;
progress.Report("generating data diagnostics");
var diags = compilation.GetDiagnostics();
progress.Report($"Found {diags.Length} diagnostics (issues).");
Expand Down
14 changes: 8 additions & 6 deletions src/Phalanx.GodMode.NativeApp/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<div>
<img src="~/appicon.svg" />
GodMode
</div>
<h2 style="display: flex;">
<a href="/" style="display: flex; align-items: center; padding: 6px">
<object data="appicon.svg" type="image/svg+xml" style="height: 1.2em; margin: 4px"/>
GodMode
</a>
</h2>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>

@*
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
Expand All @@ -28,7 +30,7 @@
</NavLink>
</div>
</nav>
</div>
</div>*@

@code {
private bool collapseNavMenu = true;
Expand Down

0 comments on commit 1538065

Please sign in to comment.