Implement phase-3 board template client integration

Server:
- Add GetBoardTemplatesRequest/Response + BoardTemplateDto to ContentMessages.cs
- ContentBoardTemplatesHandler: content.board_templates → returns all enabled
  templates (id, name, dimensions, player range, flags, tilesJson, startingZonesJson)
- Register AddGameDatabase + ContentBoardTemplatesHandler in SOR.Content

Client:
- BoardTemplateCache.gd autoload: fetches content.board_templates on demand,
  exposes get_templates_for_custom(), get_templates_for_ranked(), get_template_by_id()
- rules_editor_dialog.gd: add Board Template OptionButton in the BOARD section;
  uses _option_ids map so confirmed() emits the template GUID (not label text)
- project.godot: register BoardTemplateCache autoload

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-27 21:12:49 -04:00
co-authored by Claude Happy
parent 1368083405
commit 5b836a8e7f
6 changed files with 191 additions and 2 deletions
+24
View File
@@ -186,6 +186,30 @@ public sealed record HighlightTypeConfigDto(
float Fps,
string FallbackHex);
// ── Board templates ───────────────────────────────────────────────────────────
/// <summary>Fetch all enabled board templates.</summary>
public sealed record GetBoardTemplatesRequest;
public sealed record GetBoardTemplatesResponse(IEnumerable<BoardTemplateDto> Templates);
/// <summary>
/// Lightweight descriptor for an admin-defined board template.
/// TilesJson and StartingZonesJson are forwarded verbatim for the client to cache;
/// the client only needs to decode them when loading a game.
/// </summary>
public sealed record BoardTemplateDto(
Guid Id,
string Name,
int Width,
int Height,
int MinPlayers,
int MaxPlayers,
bool IsAvailableForRanked,
bool IsAvailableForCustom,
string TilesJson,
string StartingZonesJson);
// ── BGM config ───────────────────────────────────────────────────────────────
/// <summary>Fetch all active background music tracks (keyed by game context).</summary>
@@ -0,0 +1,51 @@
namespace SOR.Content.Handlers;
using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
/// <summary>
/// content.board_templates — returns all enabled board templates.
///
/// The client caches the full list (including TilesJson and StartingZonesJson) so
/// it can populate the board-template dropdown in the custom-lobby rules editor and,
/// later, render the board preview before a game starts.
/// </summary>
internal sealed class ContentBoardTemplatesHandler : IMessageHandler
{
private readonly GameDbContext _gameDb;
public ContentBoardTemplatesHandler(GameDbContext gameDb) => _gameDb = gameDb;
public string MessageType => "content.board_templates";
public async Task<IServerMessage?> HandleAsync(
IClientMessage message,
AuthenticatedConnection connection,
CancellationToken ct)
{
var templates = await _gameDb.BoardTemplates
.AsNoTracking()
.Where(t => t.IsEnabled)
.OrderBy(t => t.Name)
.Select(t => new BoardTemplateDto(
t.Id,
t.Name,
t.Width,
t.Height,
t.MinPlayers,
t.MaxPlayers,
t.IsAvailableForRanked,
t.IsAvailableForCustom,
t.TilesJson,
t.StartingZonesJson))
.ToListAsync(ct);
return ServerMessage.Reply(
"content.board_templates.ack",
message.Seq,
new GetBoardTemplatesResponse(templates));
}
}
@@ -17,6 +17,7 @@ public static class ServiceRegistration
IConfiguration configuration)
{
services.AddCatalogDatabase(configuration);
services.AddGameDatabase(configuration);
services.AddTransient<IMessageHandler, ContentSyncHandler>();
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
@@ -26,6 +27,7 @@ public static class ServiceRegistration
services.AddTransient<IMessageHandler, ContentGetAudioConfigHandler>();
services.AddTransient<IMessageHandler, ContentGetSkyboxConfigHandler>();
services.AddTransient<IMessageHandler, ContentGetHighlightConfigHandler>();
services.AddTransient<IMessageHandler, ContentBoardTemplatesHandler>();
return services;
}