You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.0 KiB
88 lines
3.0 KiB
import { reactive } from 'vue';
|
|
|
|
import type {
|
|
AssetPreviewData,
|
|
AssetTreeNode,
|
|
CatalogTreeResult,
|
|
IndexProgress,
|
|
SelectionRefResult,
|
|
UnusedAssetsResult,
|
|
} from '../shared/types.js';
|
|
|
|
function cloneTree(nodes: AssetTreeNode[]): AssetTreeNode[] {
|
|
return nodes.map((node) => ({
|
|
...node,
|
|
children: node.children ? cloneTree(node.children) : undefined,
|
|
}));
|
|
}
|
|
|
|
export const panelState = reactive({
|
|
activeTab: 'incoming' as 'incoming' | 'outgoing' | 'unused' | 'organize',
|
|
catalogTree: [] as AssetTreeNode[],
|
|
catalogReady: false,
|
|
selectedNodeId: '',
|
|
selectedFolderUuid: null as string | null,
|
|
asset: null as SelectionRefResult['asset'],
|
|
referencedByTree: [] as AssetTreeNode[],
|
|
referencesTree: [] as AssetTreeNode[],
|
|
referencedByCount: 0,
|
|
referencesCount: 0,
|
|
unusedTree: [] as AssetTreeNode[],
|
|
unusedTotal: 0,
|
|
unusedScopeLabel: '全部资源',
|
|
indexReady: false,
|
|
indexProgress: 0,
|
|
indexing: false,
|
|
catalogIndexing: false,
|
|
queryLoading: false,
|
|
unusedCheckedUuids: [] as string[],
|
|
unusedExtFilter: '.prefab;.ts;.js;.json',
|
|
preview: null as AssetPreviewData | null,
|
|
});
|
|
|
|
export function applySelectionResult(result: SelectionRefResult) {
|
|
panelState.asset = result.asset ? { ...result.asset } : null;
|
|
panelState.referencedByTree = cloneTree(result.referencedByTree);
|
|
panelState.referencesTree = cloneTree(result.referencesTree);
|
|
panelState.referencedByCount = result.referencedBy.length;
|
|
panelState.referencesCount = result.references.length;
|
|
panelState.indexReady = result.indexReady;
|
|
panelState.indexProgress = result.indexProgress;
|
|
panelState.indexing = result.indexing;
|
|
panelState.catalogIndexing = result.catalogIndexing;
|
|
}
|
|
|
|
export function applyUnusedResult(result: UnusedAssetsResult) {
|
|
panelState.unusedTree = cloneTree(result.tree);
|
|
panelState.unusedTotal = result.total;
|
|
panelState.unusedScopeLabel = result.scopeLabel;
|
|
panelState.unusedCheckedUuids = [];
|
|
panelState.indexReady = result.indexReady;
|
|
panelState.indexProgress = result.indexProgress;
|
|
panelState.indexing = result.indexing;
|
|
panelState.catalogIndexing = result.catalogIndexing;
|
|
}
|
|
|
|
export function applyCatalogResult(result: CatalogTreeResult) {
|
|
panelState.catalogTree = cloneTree(result.tree);
|
|
panelState.catalogReady = result.catalogReady;
|
|
panelState.indexReady = result.indexReady;
|
|
panelState.indexProgress = result.indexProgress;
|
|
panelState.indexing = result.indexing;
|
|
panelState.catalogIndexing = result.catalogIndexing;
|
|
}
|
|
|
|
export function applyIndexProgress(progress: IndexProgress) {
|
|
panelState.indexReady = progress.ready;
|
|
panelState.indexProgress = progress.progress;
|
|
panelState.indexing = progress.indexing;
|
|
panelState.catalogIndexing = progress.catalogIndexing;
|
|
}
|
|
|
|
export function clearSelectionResult() {
|
|
panelState.asset = null;
|
|
panelState.referencedByTree = [];
|
|
panelState.referencesTree = [];
|
|
panelState.referencedByCount = 0;
|
|
panelState.referencesCount = 0;
|
|
}
|
|
|