Files
kronic a4edf7a03b UITK HUD rework + build palette (click-to-place ghost)
Rebuild the in-game HUD on UI Toolkit (HudUi/HudSystem, Aether palette) consistent with the menu; build-palette bar (BuildPaletteState) drives cursor->cell ground-ghost preview (green/red via BuildPreviewMath), left-click place / right-click cancel / rotate; fire suppressed in build mode; combat juice restyle. +4 BuildPreviewMath EditMode tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 15:05:49 -07:00

32 lines
1.4 KiB
C#

using Unity.Mathematics;
namespace ProjectM.Simulation
{
/// <summary>
/// Pure validity check for the client build-placement PREVIEW (the ground-ghost colour) — the same legality
/// the server re-validates authoritatively in BuildPlaceSystem, computed client-side so the ghost can read
/// green (valid) vs red (why-not). No managed types / RNG / wall-clock → unit-testable. The caller supplies
/// the live occupancy result + the affordability inputs (it owns the structure scan + the ledger read).
/// </summary>
public static class BuildPreviewMath
{
public const byte Valid = 0;
public const byte OutOfPlot = 1;
public const byte Occupied = 2;
public const byte Unaffordable = 3;
/// <summary>
/// Evaluate placement at <paramref name="cell"/>: must be in-plot, unoccupied, and affordable.
/// <paramref name="occupied"/> = the caller's live-structure cell check; <paramref name="have"/>/<paramref name="cost"/>
/// the resource on hand vs the catalog cost. Returns the first failing reason, else <see cref="Valid"/>.
/// </summary>
public static byte Evaluate(in BaseAnchor anchor, int2 cell, bool occupied, int have, int cost)
{
if (!BaseGridMath.IsCellInPlot(anchor, cell)) return OutOfPlot;
if (occupied) return Occupied;
if (have < cost) return Unaffordable;
return Valid;
}
}
}