import { describe, it, expect } from 'vitest' import { MONSTER_COMPONENTS, findMonsterLayerSprite } from '../src/game/monster-art.ts' describe('monster-art', () => { it('covers all 16 monster composite component folders', () => { expect(MONSTER_COMPONENTS.length).toBe(16) expect(MONSTER_COMPONENTS[0]).toBe('hd') expect(MONSTER_COMPONENTS[1]).toBe('tr') expect(MONSTER_COMPONENTS[8]).toBe('s1') expect(MONSTER_COMPONENTS[15]).toBe('s8') }) it('finds monster layer sprites by convention', () => { const names = [ 'data\\global\\monsters\\fa\\tr\\fatrlitwlhth.dcc', 'data\\global\\monsters\\fa\\s1\\fas1litwlhth.dcc', 'data\\global\\monsters\\fa\\rh\\farhaxewlhth.dcc', 'data\\global\\monsters\\fa\\sh\\fashbucwlhth.dcc', ] const root = 'data\\global\\monsters\\fa\\' const hit = findMonsterLayerSprite(names, root, 'fa', 'wl', 'hth', 'tr') expect(hit).toBe('data\\global\\monsters\\fa\\tr\\fatrlitwlhth.dcc') const missing = findMonsterLayerSprite(names, root, 'fa', 'wl', 'hth', 'hd') expect(missing).toBeUndefined() }) it('correctly maps 8 COF directions to permuted DCC directions via dir64ToDcc', async () => { const { dir64ToDcc } = await import('../src/game/character.ts') // In D2 DCC files with 8 directions, order is permuted: [4, 0, 5, 1, 6, 2, 7, 3] const cofDirections = 8 const dccDirs = Array.from({ length: cofDirections }, (_, dir) => { const dir64 = Math.round((dir * 64) / cofDirections) return dir64ToDcc(dir64, 8) }) expect(dccDirs).toEqual([4, 0, 5, 1, 6, 2, 7, 3]) }) it('calculates 8-direction facing correctly from dx, dy in combat.ts', async () => { const { facingOf } = await import('../src/game/combat.ts') // 0: South (dx=0, dy>0) expect(facingOf(0, 10)).toBe(0) // 1: South-West (dx<0, dy>0) expect(facingOf(-10, 10)).toBe(1) // 2: West (dx<0, dy=0) expect(facingOf(-10, 0)).toBe(2) // 3: North-West (dx<0, dy<0) expect(facingOf(-10, -10)).toBe(3) // 4: North (dx=0, dy<0) expect(facingOf(0, -10)).toBe(4) // 5: North-East (dx>0, dy<0) expect(facingOf(10, -10)).toBe(5) // 6: East (dx>0, dy=0) expect(facingOf(10, 0)).toBe(6) // 7: South-East (dx>0, dy>0) expect(facingOf(10, 10)).toBe(7) // Stationary expect(facingOf(0, 0)).toBe(0) }) })