feat(web): render bgm setups as a 3D table
Wire the tabletop library into the setup detail route: seed the store from the setup, resolve the surface mount tree, and render world and HUD surfaces. Add serializedToPackage to convert the vite-emitted package.
This commit is contained in:
@@ -11,6 +11,9 @@ export {
|
||||
} from './part.js';
|
||||
export { resolveAssetUrl, assetUrl, traceImage } from './http.js';
|
||||
|
||||
// Serialized package -> Package conversion.
|
||||
export { serializedToPackage } from './package.js';
|
||||
|
||||
// State store + derived render state.
|
||||
export {
|
||||
useTabletopStore,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { serializedToPackage } from './package.js';
|
||||
|
||||
describe('serializedToPackage', () => {
|
||||
it('converts plain-object maps to Map instances', () => {
|
||||
const serialized = {
|
||||
meta: { id: 'harbor' },
|
||||
parts: { 'token#wood': { type: 'token', id: 'wood' } },
|
||||
surfaces: { 'board#harbor': { type: 'board', id: 'harbor', layout: [] } },
|
||||
setups: { 'game#main': { type: 'game', id: 'main', setup: {} } },
|
||||
};
|
||||
const pkg = serializedToPackage(serialized);
|
||||
expect(pkg.meta.id).toBe('harbor');
|
||||
expect(pkg.parts).toBeInstanceOf(Map);
|
||||
expect(pkg.parts.get('token#wood')).toEqual({ type: 'token', id: 'wood' });
|
||||
expect(pkg.surfaces.get('board#harbor')).toMatchObject({ type: 'board' });
|
||||
expect(pkg.setups.get('game#main')).toMatchObject({ type: 'game' });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Convert a serialized package (plain objects, as emitted by the bgm vite
|
||||
* plugin) into a `Package` (Maps). Consumers that load a package from
|
||||
* `virtual:bgm/*` get the serialized form; the tabletop components take the
|
||||
* `Package` form.
|
||||
*/
|
||||
import type { Package, SerializedPackage } from '@tts/bgm';
|
||||
|
||||
export function serializedToPackage(serialized: SerializedPackage): Package {
|
||||
return {
|
||||
meta: serialized.meta,
|
||||
parts: new Map(Object.entries(serialized.parts)),
|
||||
surfaces: new Map(Object.entries(serialized.surfaces)),
|
||||
setups: new Map(Object.entries(serialized.setups)),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user