Adding big batch of structural code provided by Claude to start designing levels

This commit is contained in:
Matt F 2026-04-27 22:55:23 -07:00
parent 0ed4df8bc9
commit a4e28bc93f
26 changed files with 1951 additions and 0 deletions

View file

@ -0,0 +1,88 @@
namespace TD.Core
{
/// <summary>
/// Identifies a player slot in a match. Backed by byte to keep grid arrays compact.
/// </summary>
/// <remarks>
/// <c>None</c> is a sentinel value used in <c>OwnerGrid</c> to mark tiles not owned by any player zone.
/// Player1..Player9 cover the maximum supported player count. Maps using fewer players use a
/// contiguous prefix (e.g., a 3-player map uses Player1, Player2, Player3 only).
/// </remarks>
public enum PlayerSlot : byte
{
None = 0,
Player1 = 1,
Player2 = 2,
Player3 = 3,
Player4 = 4,
Player5 = 5,
Player6 = 6,
Player7 = 7,
Player8 = 8,
Player9 = 9,
}
/// <summary>
/// Whether a volume permits tower placement on the tiles it covers.
/// </summary>
/// <remarks>
/// Defaults: <c>Allowed</c> for <see cref="TD.Levels.PlayerZoneVolume"/>, <c>Invalid</c> for
/// <see cref="TD.Levels.SpawnerVolume"/>, <see cref="TD.Levels.LeakExitVolume"/>, and
/// <see cref="TD.Levels.GoalVolume"/>.
/// Composition rule when volumes overlap: "Invalid wins" — any tile covered by an Invalid volume
/// becomes <see cref="PlacementState.Restricted"/> regardless of other volumes covering it.
/// </remarks>
public enum PlacementValidity
{
Invalid = 0,
Allowed = 1,
}
/// <summary>
/// Cardinal direction for spawner facing. Used by gizmos (direction arrow) and may be used
/// at runtime to bias initial enemy movement direction out of a spawner.
/// </summary>
public enum Direction
{
North,
South,
East,
West,
}
/// <summary>
/// Per-tile placement state in the baked <c>PlacementGrid</c>.
/// </summary>
/// <remarks>
/// Backed by byte so default-initialized arrays (all zero) start as <c>Outside</c>, which is
/// the correct default for any tile not covered by an authoring volume.
/// </remarks>
public enum PlacementState : byte
{
/// <summary>Tile is not covered by any authoring volume. Towers cannot be placed.</summary>
Outside = 0,
/// <summary>Tile is inside a player zone and not covered by any Invalid-validity volume.
/// Towers can be placed here (subject to runtime checks: ownership, footprint, gold, path).</summary>
Buildable = 1,
/// <summary>Tile is covered by at least one Invalid-validity volume (spawner, leak exit, goal).
/// Towers cannot be placed here. Note: this affects placement only; pathfinding still treats
/// the tile as walkable.</summary>
Restricted = 2,
}
/// <summary>
/// Outcome of a bake operation, recorded on the baked <see cref="TD.Levels.LevelData"/> asset.
/// </summary>
/// <remarks>
/// Failure is not represented here because failed bakes do not persist any state to the asset —
/// the previous successful bake (if any) remains on disk untouched. Failure state lives in
/// editor-only memory and is not part of the data schema.
/// </remarks>
public enum BakeOutcome
{
Success,
SuccessWithWarnings,
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7dd18da945084fc4fb2b403cf1557515

View file

@ -0,0 +1,82 @@
using UnityEngine;
namespace TD.Core
{
/// <summary>
/// Canonical color palette for player slots, used by editor gizmos to color volumes by owner.
/// </summary>
/// <remarks>
/// Color names follow the 9-player map design doc (red, green, blue, purple, yellow, gray,
/// teal, olive, dark gray). The exact RGB values have been tuned for readability when drawn
/// as translucent gizmos against Unity's default scene-view background. Tweak the constants
/// below if any color reads poorly in practice.
///
/// The "ErrorPink" color is reserved for diagnostic use: if a volume's owner is
/// <see cref="PlayerSlot.None"/> (which should never happen on a valid volume), the gizmo
/// renders in error pink to make the bug obvious.
/// </remarks>
public static class PlayerColors
{
// Player colors. Hex values are RGB; alpha is set per-gizmo at draw time.
// Values are tuned to be saturated enough to read against Unity's default scene background.
private static readonly Color Player1Red = HexRGB(0xE0, 0x3A, 0x3A); // red
private static readonly Color Player2Green = HexRGB(0x3A, 0xC0, 0x4A); // green
private static readonly Color Player3Blue = HexRGB(0x3A, 0x7A, 0xE0); // blue
private static readonly Color Player4Purple = HexRGB(0xA0, 0x4A, 0xC0); // purple
private static readonly Color Player5Yellow = HexRGB(0xE0, 0xC8, 0x3A); // yellow
private static readonly Color Player6Gray = HexRGB(0xB0, 0xB0, 0xB8); // gray (slightly cool)
private static readonly Color Player7Teal = HexRGB(0x3A, 0xC0, 0xB8); // teal
private static readonly Color Player8Olive = HexRGB(0x9A, 0x9A, 0x3A); // olive
private static readonly Color Player9DarkGray = HexRGB(0x60, 0x60, 0x68); // dark gray (slightly cool)
// Non-player colors.
private static readonly Color GoalGold = HexRGB(0xE0, 0xB0, 0x20); // gold
private static readonly Color ErrorPink = HexRGB(0xFF, 0x4A, 0xC8); // diagnostic
/// <summary>
/// Returns the canonical color for a player slot. Returns the diagnostic error pink if
/// <paramref name="slot"/> is <see cref="PlayerSlot.None"/> or out of range.
/// </summary>
/// <param name="slot">The player slot to look up.</param>
public static Color Get(PlayerSlot slot)
{
switch (slot)
{
case PlayerSlot.Player1: return Player1Red;
case PlayerSlot.Player2: return Player2Green;
case PlayerSlot.Player3: return Player3Blue;
case PlayerSlot.Player4: return Player4Purple;
case PlayerSlot.Player5: return Player5Yellow;
case PlayerSlot.Player6: return Player6Gray;
case PlayerSlot.Player7: return Player7Teal;
case PlayerSlot.Player8: return Player8Olive;
case PlayerSlot.Player9: return Player9DarkGray;
case PlayerSlot.None:
default:
return ErrorPink;
}
}
/// <summary>The canonical color used for goal volumes. Not tied to any player.</summary>
public static Color Goal => GoalGold;
/// <summary>Diagnostic color used when a volume has an invalid/missing owner.</summary>
public static Color Error => ErrorPink;
/// <summary>
/// Returns a copy of <paramref name="color"/> with its alpha channel replaced by
/// <paramref name="alpha"/>. Convenience for translucent gizmo fills.
/// </summary>
public static Color WithAlpha(Color color, float alpha)
{
color.a = alpha;
return color;
}
// Helper: build a Color from 0-255 RGB byte channels (alpha defaults to 1.0).
private static Color HexRGB(byte r, byte g, byte b)
{
return new Color(r / 255f, g / 255f, b / 255f, 1f);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7d03e9552345e7c4098b141ac5f587e2