Game/3D/CellPanel.razor

A UI Razor component for a grid cell in the game. It renders the cell root element, icon, hit counter, and bomb label, computes CSS class from the associated GridCellPanel component, forwards clicks to the component, and implements BuildHash for re-render triggers.

Reflection
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent

@* ─────────────────────────────────────────────────────────────
   CellPanel.razor
   Lives on the same GameObject as GridCellPanel.
   GridCellPanel calls StateHasChanged() to trigger re-render.
   ─────────────────────────────────────────────────────────── *@

<root class="cell @CssClass" onclick=@OnClick>
	<div class="icon">@Cell?.Icon</div>
	@if ( Cell?.HitsLeft > 1 )
	{
		<div class="hits">@Cell.HitsLeft♥</div>
	}
	@if ( Cell?.IsBomb == true )
	{
		<div class="bomb-label">@Cell.Label</div>
	}
</root>

@code {
	GridCellPanel Cell => GameObject.GetComponent<GridCellPanel>();

	string CssClass => Cell == null ? "" :
		Cell.IsBomb  ? "has-bomb" :
		Cell.IsChest && Cell.Danger ? "chest danger" :
		Cell.IsChest ? "chest" : "empty";

	void OnClick() => Cell?.OnClicked?.Invoke();

	// Rebuild whenever GridCellPanel calls StateHasChanged
	protected override int BuildHash()
		=> System.HashCode.Combine(
			Cell?.Icon, Cell?.IsBomb, Cell?.IsChest,
			Cell?.HitsLeft, Cell?.Danger );
}