phantasmal-world/src/viewer/index.ts

56 lines
1.8 KiB
TypeScript
Raw Normal View History

import { ViewerView } from "./gui/ViewerView";
import { GuiStore } from "../core/stores/GuiStore";
import { HttpClient } from "../core/HttpClient";
import { DisposableThreeRenderer } from "../core/rendering/Renderer";
import { Disposable } from "../core/observable/Disposable";
import { Disposer } from "../core/observable/Disposer";
export function initialize_viewer(
http_client: HttpClient,
gui_store: GuiStore,
create_three_renderer: () => DisposableThreeRenderer,
): { view: ViewerView } & Disposable {
const disposer = new Disposer();
const view = new ViewerView(
async () => {
const { Model3DStore } = await import("./stores/Model3DStore");
const { Model3DView } = await import("./gui/model_3d/Model3DView");
const { CharacterClassAssetLoader } = await import(
"./loading/CharacterClassAssetLoader"
);
const asset_loader = disposer.add(new CharacterClassAssetLoader(http_client));
const store = new Model3DStore(asset_loader);
if (disposer.disposed) {
store.dispose();
} else {
disposer.add(store);
}
return new Model3DView(gui_store, store, create_three_renderer());
},
async () => {
const { TextureStore } = await import("./stores/TextureStore");
const { TextureView } = await import("./gui/TextureView");
const store = new TextureStore();
if (disposer.disposed) {
store.dispose();
} else {
disposer.add(store);
}
return new TextureView(gui_store, store, create_three_renderer());
},
);
return {
view,
dispose(): void {
disposer.dispose();
},
};
}