63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
buildCombatFeedbackEvents,
|
|
type CombatFeedbackHealthSample,
|
|
} from './combatFeedback';
|
|
|
|
function toSample(key: string, hp: number): CombatFeedbackHealthSample {
|
|
return {
|
|
key,
|
|
kind: key.startsWith('hostile') ? 'hostile' : 'player',
|
|
hp,
|
|
};
|
|
}
|
|
|
|
describe('combatFeedback', () => {
|
|
it('creates red damage and green healing deltas from committed hp changes', () => {
|
|
const previous = new Map([
|
|
['player', toSample('player', 20)],
|
|
['hostile:npc-liu', toSample('hostile:npc-liu', 8)],
|
|
]);
|
|
|
|
const result = buildCombatFeedbackEvents(
|
|
previous,
|
|
[
|
|
toSample('player', 11),
|
|
toSample('hostile:npc-liu', 9),
|
|
],
|
|
4,
|
|
);
|
|
|
|
expect(result.events).toEqual([
|
|
{
|
|
id: 'player:5',
|
|
targetKey: 'player',
|
|
kind: 'player',
|
|
delta: -9,
|
|
},
|
|
{
|
|
id: 'hostile:npc-liu:6',
|
|
targetKey: 'hostile:npc-liu',
|
|
kind: 'hostile',
|
|
delta: 1,
|
|
},
|
|
]);
|
|
expect(result.nextSequence).toBe(6);
|
|
});
|
|
|
|
it('ignores first render samples and unchanged hp', () => {
|
|
const result = buildCombatFeedbackEvents(
|
|
new Map([['player', toSample('player', 20)]]),
|
|
[
|
|
toSample('player', 20),
|
|
toSample('companion:npc-chen', 6),
|
|
],
|
|
0,
|
|
);
|
|
|
|
expect(result.events).toEqual([]);
|
|
expect(result.nextSequence).toBe(0);
|
|
});
|
|
});
|