Initial commit

This commit is contained in:
2026-03-14 00:32:26 +01:00
commit 70a35f3985
109 changed files with 62554 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
@page "/api"
<PageTitle>API Surface</PageTitle>
<section class="hero-panel">
<span class="eyebrow">Minimal API</span>
<h1 class="page-title">Endpoints for attack and critical lookups.</h1>
<p class="lede">The Blazor UI uses the same lookup service that the API exposes, so this page doubles as the first integration contract.</p>
</section>
<div class="api-grid">
<section class="panel">
<h2 class="panel-title">Reference data</h2>
<p class="panel-copy"><code>GET /api/reference-data</code></p>
<pre class="code-block">{
"attackTables": [
{ "key": "broadsword", "label": "Broadsword" }
]
}</pre>
</section>
<section class="panel">
<h2 class="panel-title">Attack lookup</h2>
<p class="panel-copy"><code>POST /api/lookup/attack</code></p>
<pre class="code-block">{
"attackTable": "broadsword",
"armorType": "AT10",
"roll": 111,
"criticalRoll": 72
}</pre>
</section>
<section class="panel">
<h2 class="panel-title">Critical lookup</h2>
<p class="panel-copy"><code>POST /api/lookup/critical</code></p>
<pre class="code-block">{
"criticalType": "slash",
"column": "B",
"roll": 72,
"group": null
}</pre>
</section>
</div>

View File

@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}

View File

@@ -0,0 +1,309 @@
@page "/"
@rendermode InteractiveServer
@inject LookupService LookupService
<PageTitle>Lookup Desk</PageTitle>
@if (referenceData is null)
{
<section class="hero-panel">
<h1 class="page-title">Summoning tables...</h1>
<p class="lede">Loading the starter attack and critical data from SQLite.</p>
</section>
}
else
{
<section class="hero-panel">
<span class="eyebrow">Rolemaster Lookup Desk</span>
<h1 class="page-title">Resolve the attack roll, then the critical, from one place.</h1>
<p class="lede">
This starter app seeds a small SQLite dataset and exposes the same lookup flow through Blazor and minimal APIs.
The current data is intentionally limited to a first pass so the import pipeline can grow from a working base.
</p>
<div class="tag-row">
<span class="tag">@referenceData.AttackTables.Count attack tables</span>
<span class="tag">@referenceData.CriticalTables.Count critical tables</span>
<span class="tag">@referenceData.ArmorTypes.Count armor types</span>
<span class="tag">SQLite file: <code>rolemaster.db</code></span>
</div>
</section>
<div class="dashboard-grid">
<section class="panel">
<h2 class="panel-title">Automatic Attack Lookup</h2>
<p class="panel-copy">Choose an attack table, armor type, and attack roll. If the attack produces a critical and you provide the critical roll, the app resolves that follow-up automatically.</p>
<div class="lookup-form">
<div class="form-grid">
<div class="field-shell">
<label for="attack-table">Attack table</label>
<select id="attack-table" class="input-shell" @bind="attackInput.AttackTable">
@foreach (var attackTable in referenceData.AttackTables)
{
<option value="@attackTable.Key">@attackTable.Label</option>
}
</select>
</div>
<div class="field-shell">
<label for="armor-type">Armor type</label>
<select id="armor-type" class="input-shell" @bind="attackInput.ArmorType">
@foreach (var armorType in referenceData.ArmorTypes)
{
<option value="@armorType.Key">@armorType.Label</option>
}
</select>
</div>
<div class="field-shell">
<label for="attack-roll">Attack roll</label>
<input id="attack-roll" class="input-shell" type="number" min="1" max="300" @bind="attackInput.AttackRoll" />
</div>
<div class="field-shell">
<label for="critical-roll">Critical roll</label>
<input id="critical-roll" class="input-shell" type="number" min="1" max="100" @bind="attackInput.CriticalRollText" />
</div>
</div>
<div class="action-row">
<button class="btn-ritual" @onclick="RunAttackLookupAsync">Resolve attack</button>
<span class="muted">Leave critical roll blank to stop after the attack table result.</span>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(attackError))
{
<p class="error-text">@attackError</p>
}
@if (attackResult is not null)
{
<div class="result-shell">
<div class="result-card">
<h3>@attackResult.AttackTableName vs @attackResult.ArmorTypeLabel</h3>
<div class="result-stats">
<span class="stat-pill">Roll band: @attackResult.RollBand</span>
<span class="stat-pill">Hits: @attackResult.Hits</span>
@if (!string.IsNullOrWhiteSpace(attackResult.CriticalSeverity))
{
<span class="stat-pill">@attackResult.CriticalSeverity @attackResult.CriticalType critical</span>
}
else
{
<span class="stat-pill">No critical</span>
}
</div>
<p><strong>Table notation:</strong> @attackResult.RawNotation</p>
@if (!string.IsNullOrWhiteSpace(attackResult.Notes))
{
<p class="muted">@attackResult.Notes</p>
}
@if (attackResult.AutoCritical is not null)
{
<div class="callout">
<h4>Automatic critical resolution</h4>
<div class="result-stats">
<span class="stat-pill">@attackResult.AutoCritical.CriticalTableName</span>
<span class="stat-pill">Column: @attackResult.AutoCritical.Column</span>
<span class="stat-pill">Band: @attackResult.AutoCritical.RollBand</span>
</div>
<p><strong>@attackResult.AutoCritical.Description</strong></p>
@if (!string.IsNullOrWhiteSpace(attackResult.AutoCritical.AffixText))
{
<p class="muted">@attackResult.AutoCritical.AffixText</p>
}
</div>
}
else if (!string.IsNullOrWhiteSpace(attackResult.CriticalSeverity))
{
<div class="callout">The attack produced a critical. Add a critical roll to resolve it automatically.</div>
}
</div>
</div>
}
</section>
<section class="panel">
<h2 class="panel-title">Direct Critical Lookup</h2>
<p class="panel-copy">Use this when you already know the critical table, column, and roll.</p>
<div class="lookup-form">
<div class="form-grid">
<div class="field-shell">
<label for="critical-table">Critical table</label>
<select id="critical-table" class="input-shell" value="@criticalInput.CriticalType" @onchange="HandleCriticalTableChanged">
@foreach (var criticalTable in referenceData.CriticalTables)
{
<option value="@criticalTable.Key">@criticalTable.Label</option>
}
</select>
</div>
<div class="field-shell">
<label for="critical-column">Column</label>
<select id="critical-column" class="input-shell" @bind="criticalInput.Column">
@foreach (var column in SelectedCriticalTable?.Columns ?? [])
{
<option value="@column.Key">@column.Label</option>
}
</select>
</div>
<div class="field-shell">
<label for="critical-roll-direct">Critical roll</label>
<input id="critical-roll-direct" class="input-shell" type="number" min="1" max="100" @bind="criticalInput.Roll" />
</div>
</div>
<div class="action-row">
<button class="btn-ritual" @onclick="RunCriticalLookupAsync">Resolve critical</button>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(criticalError))
{
<p class="error-text">@criticalError</p>
}
@if (criticalResult is not null)
{
<div class="result-shell">
<div class="result-card">
<h3>@criticalResult.CriticalTableName</h3>
<div class="result-stats">
<span class="stat-pill">Column: @criticalResult.Column</span>
<span class="stat-pill">Band: @criticalResult.RollBand</span>
<span class="stat-pill">Roll: @criticalResult.Roll</span>
</div>
<p><strong>@criticalResult.Description</strong></p>
@if (!string.IsNullOrWhiteSpace(criticalResult.AffixText))
{
<p class="muted">@criticalResult.AffixText</p>
}
</div>
</div>
}
</section>
<section class="panel">
<h2 class="panel-title">Seeded Reference Data</h2>
<p class="panel-copy">The schema supports much more than what is seeded today. These are the initial tables standing up the flow.</p>
<div class="table-list">
@foreach (var attackTable in referenceData.AttackTables)
{
<div class="table-list-item">
<strong>@attackTable.Label</strong>
<span class="muted">Attack table key: <code>@attackTable.Key</code></span>
</div>
}
@foreach (var criticalTable in referenceData.CriticalTables)
{
<div class="table-list-item">
<strong>@criticalTable.Label</strong>
<span class="muted">Critical key: <code>@criticalTable.Key</code>, columns: @string.Join(", ", criticalTable.Columns.Select(column => column.Label))</span>
</div>
}
</div>
</section>
</div>
}
@code {
private LookupReferenceData? referenceData;
private AttackLookupForm attackInput = new();
private CriticalLookupForm criticalInput = new();
private AttackLookupResponse? attackResult;
private CriticalLookupResponse? criticalResult;
private string? attackError;
private string? criticalError;
private CriticalTableReference? SelectedCriticalTable =>
referenceData?.CriticalTables.FirstOrDefault(table => table.Key == criticalInput.CriticalType);
protected override async Task OnInitializedAsync()
{
referenceData = await LookupService.GetReferenceDataAsync();
attackInput.AttackTable = referenceData.AttackTables.FirstOrDefault()?.Key ?? string.Empty;
attackInput.ArmorType = referenceData.ArmorTypes.FirstOrDefault()?.Key ?? string.Empty;
var initialCriticalTable = referenceData.CriticalTables.FirstOrDefault();
criticalInput.CriticalType = initialCriticalTable?.Key ?? string.Empty;
criticalInput.Column = initialCriticalTable?.Columns.FirstOrDefault()?.Key ?? string.Empty;
}
private async Task RunAttackLookupAsync()
{
attackError = null;
attackResult = null;
if (!int.TryParse(attackInput.CriticalRollText, out var criticalRoll) && !string.IsNullOrWhiteSpace(attackInput.CriticalRollText))
{
attackError = "Critical roll must be empty or a whole number.";
return;
}
var response = await LookupService.LookupAttackAsync(new AttackLookupRequest(
attackInput.AttackTable,
attackInput.ArmorType,
attackInput.AttackRoll,
string.IsNullOrWhiteSpace(attackInput.CriticalRollText) ? null : criticalRoll));
if (response is null)
{
attackError = "No seeded attack result matched that table, armor type, and roll.";
return;
}
attackResult = response;
}
private async Task RunCriticalLookupAsync()
{
criticalError = null;
criticalResult = null;
var response = await LookupService.LookupCriticalAsync(new CriticalLookupRequest(
criticalInput.CriticalType,
criticalInput.Column,
criticalInput.Roll,
null));
if (response is null)
{
criticalError = "No seeded critical result matched that table, column, and roll.";
return;
}
criticalResult = response;
}
private void HandleCriticalTableChanged(ChangeEventArgs args)
{
criticalInput.CriticalType = args.Value?.ToString() ?? string.Empty;
var table = referenceData?.CriticalTables.FirstOrDefault(item => item.Key == criticalInput.CriticalType);
criticalInput.Column = table?.Columns.FirstOrDefault()?.Key ?? string.Empty;
criticalResult = null;
criticalError = null;
}
private sealed class AttackLookupForm
{
public string AttackTable { get; set; } = string.Empty;
public string ArmorType { get; set; } = string.Empty;
public int AttackRoll { get; set; } = 66;
public string? CriticalRollText { get; set; } = "72";
}
private sealed class CriticalLookupForm
{
public string CriticalType { get; set; } = string.Empty;
public string Column { get; set; } = string.Empty;
public int Roll { get; set; } = 72;
}
}

View File

@@ -0,0 +1,5 @@
@page "/not-found"
@layout MainLayout
<h3>Not Found</h3>
<p>Sorry, the content you are looking for does not exist.</p>