import { describe, expect, it } from 'vitest'; import { IDENTITY } from '../../src/core/model/matrix'; import type { PropertyBag } from '../../src/core/model/Properties'; import { colliderShape } from '../../src/core/properties/collider'; import { Theme } from '../../src/ui'; import { Graphics } from 'pixi.js'; import type { DrawItem } from '../../src/viewport/items'; import { COLLIDER_FILL_ALPHA, colliderColor, drawItem } from '../../src/viewport/symbols'; const colorOf = (props: PropertyBag) => colliderColor(colliderShape(props, IDENTITY), props); describe('the colour of a collider in the scene view, outline and icon alike', () => { it('is the collider colour, the trigger colour for a trigger, red for a shape that collides with nothing', () => { expect(colorOf({ shape: 'box', width: 40, height: 40 })).toBe(Theme.colors.collider); expect(colorOf({ shape: 'circle', radius: 20, isTrigger: true })).toBe(Theme.colors.trigger); const bowtie = [ { x: -10, y: -10 }, { x: 10, y: 10 }, { x: 10, y: -10 }, { x: -10, y: 10 }, ]; expect(colorOf({ shape: 'polygon', points: bowtie })).toBe(Theme.colors.danger); expect(colorOf({ shape: 'polygon', points: bowtie, isTrigger: true })).toBe(Theme.colors.danger); }); }); describe('the area of a collider in the scene view', () => { const item = { id: 'c', type: 'collider', m: IDENTITY, props: { shape: 'box', width: 40, height: 20 }, frame: null, } as unknown as DrawItem; const actions = (selected: boolean) => { const node = new Graphics(); drawItem(node, item, { w: 40, h: 20 }, 1, selected); return node.context.instructions.map((i) => ({ action: i.action, alpha: (i.data.style as { alpha: number }).alpha, })); }; it('is only an outline while the collider is not selected', () => { expect(actions(false)).toEqual([{ action: 'stroke', alpha: 1 }]); }); it('is filled, more strongly than before, once the collider itself is selected', () => { expect(COLLIDER_FILL_ALPHA).toBeGreaterThan(0.12); expect(actions(true)).toEqual([ { action: 'fill', alpha: COLLIDER_FILL_ALPHA }, { action: 'stroke', alpha: 1 }, ]); }); });