12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import { diffArrayChange, mount, shallowWatchArray } from "@/utils";
- import TaggingComponent from "@/components/path/list.vue";
- import { Path as PathData, paths } from "@/store/path";
- import { Path, SDK } from "../sdk";
- import { reactive, watch } from "vue";
- import { groupProxy } from "@/store/group";
- import { isScenePlayRun, pauseScene, playScene } from "@/utils/full";
- // -----------------导览线关联--------------------
- export type PathNode = Path;
- export type PathsNode = { node: PathNode; id: PathData["id"] }[];
- const pathNodes = reactive(new Map<PathData, PathNode>());
- export const getPathNode = (
- path: PathData | PathData["id"]
- ): undefined | PathNode => {
- if (typeof path !== "object") {
- path = paths.value.find((item) => item.id === path)!;
- if (!path) return void 0;
- }
- return pathNodes.get(path);
- };
- export const taggingsGroup = groupProxy(() => {
- const nodes = [] as PathNode[];
- for (const path of paths.value) {
- const node = getPathNode(path);
- if (node) {
- nodes.push(node);
- }
- }
- return nodes;
- });
- export const playScenePath = (
- path: PathData,
- forceFull = false
- ) => {
- const node = getPathNode(path)
- if (!node) return null;
- playScene({
- play: () => {
- return new Promise(resolve => {
- node.play(resolve)
- })
- },
- pause: () => {
- node.pause();
- }
- }, forceFull)
- }
- export const pauseScenePath = pauseScene
- export const isScenePathPlayIng = isScenePlayRun
- export const associationPaths = (sdk: SDK, el: HTMLDivElement) => {
- mount<PathsNode>(el, TaggingComponent, { paths }, (pathsNode) => {
- watch(
- () => {
- pathsNode.forEach(i => !!i?.id)
- return pathsNode
- },
- (nodes, oldNodes = []) => {
- const { added, deleted } = diffArrayChange<PathsNode>(
- nodes,
- oldNodes as PathsNode
- );
- for (const add of added) {
- if (add) {
- const path = paths.value.find((item) => item.id === add.id)!;
- pathNodes.set(path, add.node);
- }
- }
- for (const del of deleted) {
- if (del) {
- const path = paths.value.find((item) => item.id === del.id)!;
- pathNodes.delete(path);
- }
- }
- },
- {immediate: true}
- );
- });
- };
|