/** * Builds a Voyager Story system the way StoryApplication does, without its UI. * Graph updates don't run on their own: call `update()` to process pending property changes. */ import System from "@ff/graph/System"; import TypeRegistry from "@ff/core/TypeRegistry"; import CPulse from "@ff/graph/components/CPulse"; import coreTypes from "client/applications/coreTypes"; import explorerTypes from "client/applications/explorerTypes"; import storyTypes from "client/applications/storyTypes"; import NVEngine from "client/nodes/NVEngine"; import NVTools from "client/nodes/NVTools"; import NVDocuments from "client/nodes/NVDocuments"; import NVoyagerStory from "client/nodes/NVoyagerStory"; import NVTasks from "client/nodes/NVTasks"; import CVDocumentProvider from "client/components/CVDocumentProvider"; import CVAssetReader from "client/components/CVAssetReader"; import CVAssetWriter from "client/components/CVAssetWriter"; import CVMediaManager from "client/components/CVMediaManager"; import CVDocument from "client/components/CVDocument"; import CVModel2 from "client/components/CVModel2"; import CVTask from "client/components/CVTask"; import CVTaskProvider from "client/components/CVTaskProvider"; import { ETaskMode } from "client/applications/taskSets"; import { IDocument } from "client/schema/document"; import { TypeOf } from "@ff/core/types"; import documentTemplate from "client/templates/default.svx.json"; // happy-dom has no Web Audio API, which CVAudioManager creates a context of if (!globalThis.AudioContext) { globalThis.AudioContext = class { close() {} decodeAudioData() {} } as any; } export interface IStory { system: System; document: CVDocument; /** Runs one graph update, the given number of seconds after the previous one. */ update: (seconds?: number) => void; } export function createStory(data: IDocument): IStory { const registry = new TypeRegistry(); registry.add(coreTypes); registry.add(explorerTypes); registry.add(storyTypes); const system = new System(registry); system.graph.createCustomNode(NVEngine); system.graph.createCustomNode(NVTools); system.graph.createCustomNode(NVDocuments); system.graph.createCustomNode(NVoyagerStory, "Story"); system.graph.createCustomNode(NVTasks, "Tasks"); // no server: text assets (articles) are empty, writes and listings succeed system.getMainComponent(CVAssetReader).getText = () => Promise.resolve(""); system.getMainComponent(CVAssetWriter).putText = () => Promise.resolve(); system.getMainComponent(CVMediaManager).refresh = () => Promise.resolve(); const document = system.getMainComponent(CVDocumentProvider).createDocument(data); // Explorer's shadow DOM elements some components look up const root = window.document.createElement("div"); root.attachShadow({ mode: "open" }).innerHTML = `
`; document.setup.viewer.rootElement = root; // generating an environment map needs a WebGL renderer document.setup.environment.ins.enabled.setValue(false); // there is no geometry to load document.innerComponents.getArray(CVModel2).forEach(model => model.ins.autoLoad.setValue(false)); const pulse = system.getMainComponent(CPulse); let milliseconds = Date.now(); const update = (seconds = 1 / 60) => pulse.pulse(milliseconds += seconds * 1000); update(); return { system, document, update }; } /** * Creates the authoring tasks and makes the given one active, as clicking its tab does. */ export function activateTask