weapon-colors.ts

PURPOSE

Signature color tables and lookup helpers for the additive lighting system. One color per weapon serves as both the projectile body tint and the additive glow color, so the projectile and its light read as a single cohesive object (“Geometry Wars in space” aesthetic). Also defines per-rarity player ship aura colors and per-planet boss aura colors.

OWNS

  • RGBHex interface — { r, g, b, hex } where r/g/b are 0–1 floats for the WebGL sprite batch and hex is a CSS string for any Canvas 2D draw paths.
  • WEAPON_COLOR — record of weapon id to RGBHex. Covers 13 weapon ids grouped into four signature buckets:
    • Bullet (white/silver, #f5f5f5): rifle, shotgun, disc, revolver.
    • Energy (electric blue, #22aaff): railgun, lightning, sweep, barrier, line.
    • Fire (bright orange-yellow, #ff8800): flame.
    • Bomb (dark red, #cc2200): cannon, mortar, missile.
  • WEAPON_COLOR_DEFAULT — white fallback #ffffff for unknown or missing weapon ids.
  • getWeaponColor(weaponId) — lookup; empty string returns the default white (enemy projectiles without a weapon id); unknown ids also fall back to default white.
  • SHIP_RARITY_GLOW_COLOR — record of rarity name to RGBHex for the steady additive halo under the player ship sticker:
    • common — soft white-cyan #99ccff.
    • uncommon — green #66ff99.
    • rare — blue #66b3ff.
    • epic — purple #cc66ff.
    • legendary — orange #ff9900.
  • BOSS_PLANET_GLOW_COLOR — record of numeric planet id to RGBHex for boss auras, derived from biome identity rather than per-boss-def color:
    • 3 voidstar — violet #cc66ff.
    • 12 landing site — warm orange #ff8033.
    • 21 sunrise city — yellow #ffd966.
  • BOSS_GLOW_DEFAULT — red-orange #ff4d1a fallback for unknown planets.
  • getBossGlowColor(planetId) — lookup; null/undefined returns the default; unknown numeric ids also fall back to the default.

READS FROM

Nothing. Pure data module with two lookup functions and no imports.

PUSHES TO

  • engine/rendering/draw.ts imports getWeaponColor and resolves a weapon color for projectile body tint and additive glow during draw.
  • engine/bridge.ts imports getWeaponColor and SHIP_RARITY_GLOW_COLOR to wire weapon and ship-aura colors through the engine bridge.

DOES NOT

  • Does not allocate per-frame; tables are module-level constants.
  • Does not own a per-boss-def color field; boss aura color is derived from planetId so the aura matches the biome.
  • Does not throw on unknown ids despite the docstring on getWeaponColor mentioning “throws”; both lookups return their default constant via nullish-coalescing.
  • Does not drive light intensity, radius, falloff, or any non-color glow parameter — only the RGB tint.
  • Does not list or validate against the weapon id catalog; ids are assumed to match data/weapons/index.ts.

Signals

None. The module exports static data plus two synchronous pure lookups; no events, observers, or callbacks.

Entry points

  • getWeaponColor(weaponId: string): RGBHex — empty string short-circuits to WEAPON_COLOR_DEFAULT; unknown id also returns the default.
  • getBossGlowColor(planetId: number | null | undefined): RGBHex — null/undefined short-circuits to BOSS_GLOW_DEFAULT; unknown id also returns the default.
  • Direct record reads of WEAPON_COLOR, SHIP_RARITY_GLOW_COLOR, BOSS_PLANET_GLOW_COLOR are also valid use; consumers currently use the helper for weapons and read SHIP_RARITY_GLOW_COLOR directly.

Pattern notes

  • One RGBHex shape carries both 0–1 floats (for the WebGL sprite batch) and a hex string (for Canvas 2D paths) so consumers on either renderer path can use the same constants without conversion.
  • Weapons are grouped into four color buckets rather than per-weapon hues so distinct weapon families read as distinct light sources while related weapons stay visually coherent.
  • Boss aura is keyed by planet id rather than boss def so adding a new boss in an existing biome inherits the right color automatically; new biomes require adding a row.
  • v5.60.0 ships with only the iron_throne boss (red biome); the planet-id table is sparse with three named planets and a red-orange default that covers the rest.
  • Defaults are returned (not thrown) so missing data degrades to white/red-orange rather than crashing the render path.