mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-18 06:41:27 +02:00
56 lines
2.2 KiB
JavaScript
56 lines
2.2 KiB
JavaScript
const scene = require('../html/js/render/sceneModel');
|
|
|
|
describe('sceneFromTavern (render kit adapter)', () => {
|
|
test('maps layout chars to tile kinds and occupants to entities', () => {
|
|
const appearance = {
|
|
avatar: 'char-ranger',
|
|
tint: 'teal',
|
|
equipment: { body: 'mail', head: 'hood', shield: 'round', weapon: 'bow' }
|
|
};
|
|
const state = {
|
|
cols: 3, rows: 2,
|
|
layout: ['#=@', 'o..'],
|
|
occupants: [{ id: 'a', x: 2, y: 0, avatar: 'green', appearance, facing: 'left', name: 'Al' }]
|
|
};
|
|
const s = scene.sceneFromTavern(state, 'a');
|
|
expect(s.cols).toBe(3);
|
|
expect(s.rows).toBe(2);
|
|
expect(s.grid[0]).toEqual(['wall', 'bar', 'floor']); // '@' is walkable floor
|
|
expect(s.grid[1]).toEqual(['table', 'floor', 'floor']);
|
|
expect(s.entities).toHaveLength(1);
|
|
expect(s.entities[0]).toMatchObject({ id: 'a', x: 2, y: 0, kind: 'avatar', avatar: 'char-ranger', appearance, facing: 'left', label: 'Al', you: true });
|
|
expect(s.entities[0].color).toBe(scene.AVATAR_COLORS.default);
|
|
});
|
|
|
|
test('you-flag is false for other occupants and unknown avatars fall back to default', () => {
|
|
const s = scene.sceneFromTavern(
|
|
{ cols: 1, rows: 1, layout: ['.'], occupants: [{ id: 'b', x: 0, y: 0, avatar: 'zzz' }] },
|
|
'a'
|
|
);
|
|
expect(s.entities[0].you).toBe(false);
|
|
expect(s.entities[0].color).toBe(scene.AVATAR_COLORS.default);
|
|
});
|
|
|
|
test('unknown / out-of-legend characters are treated as walls (solid)', () => {
|
|
const s = scene.sceneFromTavern({ cols: 2, rows: 1, layout: ['?~'], occupants: [] });
|
|
expect(s.grid[0]).toEqual(['wall', 'wall']);
|
|
});
|
|
|
|
test('uses walkability when a designed room has no ASCII layout', () => {
|
|
const s = scene.sceneFromTavern({
|
|
cols: 3,
|
|
rows: 2,
|
|
layout: null,
|
|
walkable: [
|
|
[true, false, true],
|
|
[false, true, true]
|
|
],
|
|
occupants: []
|
|
});
|
|
expect(s.grid).toEqual([
|
|
['floor', 'wall', 'floor'],
|
|
['wall', 'floor', 'floor']
|
|
]);
|
|
});
|
|
});
|