Drawing every icon in code

Every item and skill icon is procedural SVG drawn to D2 inventory footprints, inside a pure, mock-tested UI kit built before the game existed.

A sheet of 44 weapon and armor icons in brass-framed cells of different sizes, from a one-by-one ring to two-by-four greatswords
Contents
  1. Why draw icons in code
  2. A glyph is a viewBox and a draw function
  3. Footprints, not squares
  4. The fuzzy resolver
  5. Skill medallions
  6. The UI kit, built before the game
  7. Materials, not flat fills
  8. Type and voice
  9. Parametric glyphs
  10. Related posts

There are no icon image files. Every item and skill icon is a React component returning SVG: 28 item glyphs and 33 skill glyphs, coloured by rarity and element at render time, drawn to Diablo II's inventory footprints.

Why draw icons in code

Flat 2D icon packs don't provide painted metal, leather and gems at several footprints. Code does, and:

  • Scales: --gr-cell is 38 px, 33 px under 880 px of window height, 29 px under 700; sharp on a 3× phone too
  • Recolours free: gem glow, medallion background and glyph gradient come from rarity or element
  • Small: all item glyphs are one 589-line TSX file

A glyph is a viewBox and a draw function

32 units per inventory cell; draw functions use material names, not colours:

src/game/ui/icons/itemGlyphs.tsxTypeScript
export interface ItemGlyph {
  vb: readonly [number, number]
  draw: (p: Paint) => ReactNode
}
src/game/ui/icons/itemGlyphs.tsxTSX
sword: {
  vb: [32, 96],
  draw: (p) => (
    <>
      <path d="M16 3 L20.5 11 L20.5 60 L16 63.5 L11.5 60 L11.5 11 Z" fill={p.steel} />
      <path d="M16 5 L19.3 11.3 L19.3 59.4 L16 62 Z" fill={p.highlight} stroke="none" opacity={0.45} />
      <path d="M16 13 V56" stroke="rgba(0,0,0,.45)" strokeWidth={1.4} />
      <path d="M3 63 Q3 59.5 6.5 59.5 L25.5 59.5 Q29 59.5 29 63 Q29 66.5 25.5 66.5 L6.5 66.5 Q3 66.5 3 63 Z" fill={p.gold} />
      <circle cx={16} cy={63} r={2.2} fill={p.gem} />
      <rect x={13} y={66.5} width={6} height={16.5} rx={1.5} fill={p.leather} />
      {/* grip wraps and pommel */}
    </>
  ),
},
  • Each material is a gradient in the icon's own <defs>, ids from useId so a hundred icons don't collide
  • Steel: cool three-stop; gold: cream to bronze and back; gem: radial in the rarity's two colours
  • A wrapping <g> gives every path the same near-black 1.3-unit outline, the inked look
  • The ghost paint (faint transparent gold) draws the equipment doll's empty-slot outlines from the same glyphs
Twenty-eight glyph keys in a grid, from sword and axe to potions, gold, a lantern, an egg and a question mark, and a row of gems and runes below
The whole item vocabulary: 28 glyph keys, including unknown, the fallback. The bottom row is the endgame's gems and runes, which have their own component. Gems change shape by grade, and each rune shows its initial carved into a stone.

Footprints, not squares

Footprint Bases Examples
2×3 36 body armor, big shields, crossbows
2×2 28 helms, gloves, boots, buckler
2×4 16 greatswords, greataxes, long bows
1×3 12 short swords, hand axes, clubs
1×2 12 daggers, wands, orbs
2×1 8 belts
1×4 4 staves
1×1 2 ring, amulet

Glyphs never stretch: a 1×3 sword in a 2×3 Kingsblade cell stays centred at its own width.

The in-game inventory: an equipment doll with a sword, helm, armor and shield, and a bag holding eggs, potions, runes, a shield and a bow in their footprints
A level-75 Warden's inventory in the game. Items keep their footprints in the bag, stackable runes and gems show a count, and the empty ring-slot outlines are the same glyphs drawn with the ghost paint.

The fuzzy resolver

Data authors write an iconKey like item_kite_shield; one resolver, shared by items and skills, maps it to a glyph:

src/game/ui/icons/resolve.tsTypeScript
const resolve = (k: string): K => {
  const tokens = k.split(/[^a-z0-9]+/).filter(Boolean)
  for (let i = 0; i < tokens.length; i++) {
    const hit = lookup(tokens.slice(i).join('_'))
    if (hit !== undefined) return hit
  }
  for (let i = tokens.length - 1; i >= 0; i--) {
    const hit = lookup(tokens[i] ?? '')
    if (hit !== undefined) return hit
  }
  for (const t of tokens) {
    const w = weak[t]
    if (w !== undefined) return w
  }
  return keys.find((g) => g !== fallback && k.includes(g)) ?? fallback
}
  1. Longest suffix that's a key or alias (heart_of_winter, of_winter, winter)
  2. Single tokens, last first: the noun usually comes last
  3. Weak tokens like potion, which lose to specific siblings
  4. Substrings, then unknown; cached per key

Aliases cover lore names: kingsblade, oathcleaver, zweihander → sword; cudgel, morning_star → mace; cowl → helm; eye → orb; ledger → tome. The ui.md rule: add an alias, not a glyph, when a new id doesn't resolve.

iconKey Glyph Resolved by
item_leather_gloves gloves longest suffix (gloves is a key)
item_kite_shield shield longest suffix
item_zweihander sword alias
item_spire_aegis shield alias on the suffix aegis
item_heart_of_the_lantern orb alias on the whole suffix, before the token lantern
item_lantern_of_saint_vey lantern single token, last first (vey, saint, of, lantern)
item_mana_potion_2 potion_blue single token mana beats the weak token potion
skill_heart_of_winter snowflake alias on a suffix
skill_rain_of_barbs multishot alias on a suffix

A silent fallback needs a loud check: a test that resolves every iconKey in ALL_BASES and every skill icon and fails on unknown is a few lines, since the resolver is pure.

Skill medallions

64×64: element-coloured radial background, dotted ring, the glyph drawn twice (blurred glow, then sharp), glass sheen:

src/game/ui/icons/SkillIcon.tsxTSX
<g filter={`url(#${id('blur')})`} opacity=".85" stroke={gd} strokeWidth="1.2">
  {glyph.draw({ ...paint, f: gd, c: gm, s: gd })}
</g>
<g stroke={outline} strokeWidth="1.3" strokeLinejoin="round">
  {glyph.draw(paint)}
</g>

Each element has a six-colour palette; skills can override a glyph's default element. Locked = CSS grayscale at 45% brightness.

All 54 skills in nine trees, three per class: Steel, Bulwark and Wrath for the Warden; Marksman, Venom and Shadow for the Stalker; Flame, Frost and Storm for the Emberwright
All 54 skills, rendered straight from the skill data through SkillIcon. Look closely and you'll see repeats: Firebolt and Fireball, Shield Bash and Shieldbreaker, Barbed and Seeker Arrow.

The limitation is repeats:

  • 54 skills → 30 glyphs (aura is Steel Discipline, Hallowed Ground and Conduit; barrier is Iron Skin, Aegis of Saint Vey and Rime Ward)
  • 118 bases → 17 glyphs; all 12 swords are one drawing at different footprints

The UI kit, built before the game

Kit components are pure: view models in, callbacks out, no store, network or engine imports. ui.md is the contract.

  • /dev/ui renders the whole HUD on mock data: sheet, inventory, stash, vendor, skill tree, quest log, waypoints, chat, minimap, orbs, belt, death screen, level-up toast
  • The connected scene drives the real GameHud with dev/localSim.ts, a fake server reducer on real shared code (inventory moves, stat derivation, vendor stock)
  • Pure adapters (itemToUi, skillTabsFor, hudFromSheet…) map the server sheet to view models, with unit tests in bun test src/game/ui
A dev scene with the stash and inventory panels open side by side over a dark background, with the chat and the hotbar at the bottom
The stash scene at /dev/ui: mock items, the real components. Every panel renders here without a server or an engine.

Materials, not flat fills

Every surface gets a gradient, noise, inner shadow and brass border. The panel frame is five 1 px box-shadow rings:

src/styles/game.cssCSS
box-shadow:
  0 0 0 1px #000,
  0 0 0 2px #5a4526,
  0 0 0 3px #b8914f,
  0 0 0 4px #3b2c17,
  0 0 0 5px #000,
  inset 0 0 0 1px rgba(0, 0, 0, 0.9),
  inset 0 0 0 2px rgba(255, 214, 150, 0.07),
  inset 0 0 50px rgba(0, 0, 0, 0.75),
  0 24px 60px -10px rgba(0, 0, 0, 0.85),
  0 0 90px rgba(0, 0, 0, 0.5);

game.css: ~1,900 lines, 256 .gr-* rules. The kit: 51 components, ~12,000 lines of TSX.

No per-frame React: orb levels are CSS-transitioned transforms with a keyframed SVG wave, hotbar cooldowns a conic gradient. Taking damage is one style write.

The bottom HUD bar: a red life orb, eight skill slots with key labels and point counts, a right-click skill, four belt potions and a blue mana orb
The HUD bar. Every icon here is procedural, and the orbs are SVG with CSS-animated liquid. The small numbers are skill points and potion counts.

Type and voice

  • Cinzel 700–900: titles, item names, labels, buttons; uppercase, wide tracking, gold gradient
  • Alegreya Sans: body, stats, chat, with tabular numerals; flavour text in italic unique-tan
  • Copy: in-world and terse; Title Case for names; short verbs ("Rise in town", "Deposit", "Sell"); plain system lines ("Not enough mana"); no exclamation marks, no emoji, no eyebrows, no periods on headings
Two overlays side by side: a red "You have died" screen with a Rise in town button, and a gold "Level 18" burst over a dark map
The two big overlays. Death uses Cinzel 900 in blood red with a glow; level-up uses the gold gradient with a ray burst. Both are pure CSS and SVG.

Parametric glyphs

Next: one sword draw function with blade length, guard and pommel picked by a hash of the base id, the way procgen picks props from a seed. 118 distinct silhouettes, same visual language, zero asset cost.