Add skybox system: admin management + client 3D application

- SkyboxDefinition entity (catalog schema) with static/animated support
- EF migration: catalog.skybox_definitions table
- content.get_skybox_config handler returns active skybox definition
- SkyboxManagerPage.razor: full CRUD admin UI with inline editing,
  activate/deactivate, and animated frame config
- NavMenu.razor: Skyboxes link under Content section
- game_screen.gd: fetches active skybox on ready; applies as
  PanoramaSkyMaterial on WorldEnvironment; animated skyboxes cycle
  frames via Timer; procedural sky kept as fallback when none active

Also fixes inverted camera pan (delta.x / -delta.y signs corrected).

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-21 08:55:45 -04:00
co-authored by Claude Happy
parent 7c0b0f1953
commit 5b66f459c0
11 changed files with 1173 additions and 6 deletions
@@ -0,0 +1,304 @@
@page "/content/skyboxes"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Entities.Catalog
@inject CatalogDbContext Db
<PageTitle>Skyboxes – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="mb-0">Skyboxes</h1>
<div class="text-muted small">
Configure 3D environment skyboxes displayed in gameplay scenes.
Only the active skybox is sent to clients.
</div>
</div>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync" disabled="@_loading">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
</div>
@if (_message is not null)
{
<div class="alert @(_isError ? "alert-danger" : "alert-success") alert-dismissible">
@_message
<button type="button" class="btn-close" @onclick="() => _message = null"></button>
</div>
}
<div class="card shadow-sm mb-4">
<div class="card-header fw-medium">Skybox Library</div>
<div class="card-body p-0">
@if (_loading)
{
<p class="p-3 text-muted">Loading…</p>
}
else if (_skyboxes.Count == 0)
{
<p class="p-3 text-muted fst-italic">No skyboxes defined yet. Add one below.</p>
}
else
{
<table class="table table-sm table-hover mb-0 align-middle">
<thead>
<tr>
<th>Name</th>
<th style="width:100px" class="text-center">Type</th>
<th>CDN Path</th>
<th style="width:90px" class="text-center">Frames</th>
<th style="width:80px" class="text-center">FPS</th>
<th style="width:80px" class="text-center">Active</th>
<th style="width:130px"></th>
</tr>
</thead>
<tbody>
@foreach (var s in _skyboxes.OrderByDescending(s => s.IsActive).ThenBy(s => s.Name))
{
var skybox = s;
<tr class="@(skybox.IsActive ? "table-success" : "")">
<td>
<input @bind="skybox.Name" class="form-control form-control-sm"
placeholder="e.g. Night Sky" />
</td>
<td class="text-center">
<div class="form-check form-switch d-flex justify-content-center">
<input @bind="skybox.IsAnimated" type="checkbox"
class="form-check-input" role="switch"
title="@(skybox.IsAnimated ? "Animated" : "Static")" />
<label class="form-check-label ms-2 small text-muted">
@(skybox.IsAnimated ? "Anim" : "Static")
</label>
</div>
</td>
<td>
<input @bind="skybox.CdnPath" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/skyboxes/…" />
</td>
<td class="text-center">
<input @bind="skybox.FrameCount" type="number" min="1"
class="form-control form-control-sm text-center"
disabled="@(!skybox.IsAnimated)" />
</td>
<td class="text-center">
<input @bind="skybox.Fps" type="number" min="1" max="60" step="1"
class="form-control form-control-sm text-center"
disabled="@(!skybox.IsAnimated)" />
</td>
<td class="text-center">
<span class="badge @(skybox.IsActive ? "bg-success" : "bg-secondary")">
@(skybox.IsActive ? "Active" : "Inactive")
</span>
</td>
<td>
<button class="btn btn-sm btn-outline-primary me-1"
@onclick="() => SaveAsync(skybox)" title="Save">
<i class="bi bi-floppy"></i>
</button>
@if (!skybox.IsActive)
{
<button class="btn btn-sm btn-outline-success me-1"
@onclick="() => SetActiveAsync(skybox)" title="Set Active">
<i class="bi bi-check-circle"></i>
</button>
}
else
{
<button class="btn btn-sm btn-outline-secondary me-1"
@onclick="() => DeactivateAsync(skybox)" title="Deactivate">
<i class="bi bi-x-circle"></i>
</button>
}
<button class="btn btn-sm btn-outline-danger"
@onclick="() => DeleteAsync(skybox)" title="Delete">
<i class="bi bi-trash"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
<div class="card shadow-sm">
<div class="card-header fw-medium">Add Skybox</div>
<div class="card-body">
<div class="row g-2 align-items-end">
<div class="col-md-2">
<label class="form-label small">Name</label>
<input @bind="_newName" class="form-control form-control-sm" placeholder="Night Sky" />
</div>
<div class="col-md-1 text-center">
<label class="form-label small d-block">Animated</label>
<div class="form-check form-switch d-flex justify-content-center pt-1">
<input @bind="_newIsAnimated" type="checkbox" class="form-check-input" role="switch" />
</div>
</div>
<div class="col-md-4">
<label class="form-label small">
CDN Path
@if (_newIsAnimated)
{
<span class="text-muted ms-1">(base folder — frames at /0.png, /1.png …)</span>
}
else
{
<span class="text-muted ms-1">(full URL to panoramic image)</span>
}
</label>
<input @bind="_newCdnPath" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/skyboxes/…" />
</div>
@if (_newIsAnimated)
{
<div class="col-md-1">
<label class="form-label small">Frames</label>
<input @bind="_newFrameCount" type="number" min="1"
class="form-control form-control-sm" />
</div>
<div class="col-md-1">
<label class="form-label small">FPS</label>
<input @bind="_newFps" type="number" min="1" max="60" step="1"
class="form-control form-control-sm" />
</div>
}
<div class="col-md-2">
<button class="btn btn-primary btn-sm w-100"
@onclick="AddAsync"
disabled="@(string.IsNullOrWhiteSpace(_newName) || string.IsNullOrWhiteSpace(_newCdnPath))">
<i class="bi bi-plus-lg me-1"></i>Add
</button>
</div>
</div>
<div class="text-muted small mt-2">
<strong>Static</strong>: Set CDN path to a single panoramic/equirectangular image (PNG/JPG recommended).<br />
<strong>Animated</strong>: Upload frames as <code>/0.png</code>, <code>/1.png</code>, … <code>/{FrameCount-1}.png</code>
inside the base folder, then set CDN path to that folder URL.
</div>
</div>
</div>
@code {
private List<SkyboxDefinition> _skyboxes = new();
private bool _loading;
private string? _message;
private bool _isError;
private string _newName = "";
private bool _newIsAnimated = false;
private string _newCdnPath = "";
private int _newFrameCount = 1;
private float _newFps = 24f;
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_loading = true;
_skyboxes = await Db.SkyboxDefinitions.OrderBy(s => s.CreatedAt).ToListAsync();
_loading = false;
}
private async Task SaveAsync(SkyboxDefinition skybox)
{
if (!skybox.IsAnimated) { skybox.FrameCount = 1; skybox.Fps = 0f; }
try
{
await Db.SaveChangesAsync();
_message = $"Skybox \"{skybox.Name}\" saved.";
_isError = false;
}
catch (Exception ex)
{
_message = $"Save failed: {ex.Message}";
_isError = true;
}
}
private async Task SetActiveAsync(SkyboxDefinition skybox)
{
// Deactivate all, then activate the chosen one.
foreach (var s in _skyboxes)
s.IsActive = false;
skybox.IsActive = true;
try
{
await Db.SaveChangesAsync();
_message = $"\"{skybox.Name}\" is now the active skybox.";
_isError = false;
}
catch (Exception ex)
{
_message = $"Activate failed: {ex.Message}";
_isError = true;
}
}
private async Task DeactivateAsync(SkyboxDefinition skybox)
{
skybox.IsActive = false;
try
{
await Db.SaveChangesAsync();
_message = $"\"{skybox.Name}\" deactivated. No skybox is now active (clients use procedural sky).";
_isError = false;
}
catch (Exception ex)
{
_message = $"Deactivate failed: {ex.Message}";
_isError = true;
}
}
private async Task DeleteAsync(SkyboxDefinition skybox)
{
Db.SkyboxDefinitions.Remove(skybox);
try
{
await Db.SaveChangesAsync();
_skyboxes.Remove(skybox);
_message = $"Skybox \"{skybox.Name}\" deleted.";
_isError = false;
}
catch (Exception ex)
{
_message = $"Delete failed: {ex.Message}";
_isError = true;
}
}
private async Task AddAsync()
{
var s = new SkyboxDefinition
{
Id = Guid.NewGuid(),
Name = _newName.Trim(),
IsAnimated = _newIsAnimated,
CdnPath = _newCdnPath.Trim(),
FrameCount = _newIsAnimated ? Math.Max(1, _newFrameCount) : 1,
Fps = _newIsAnimated ? Math.Max(1f, _newFps) : 0f,
IsActive = false,
CreatedAt = DateTimeOffset.UtcNow,
};
Db.SkyboxDefinitions.Add(s);
try
{
await Db.SaveChangesAsync();
_skyboxes.Add(s);
_newName = _newCdnPath = "";
_newIsAnimated = false;
_newFrameCount = 1;
_newFps = 24f;
_message = $"Skybox \"{s.Name}\" added.";
_isError = false;
}
catch (Exception ex)
{
_message = $"Add failed: {ex.Message}";
_isError = true;
}
}
}