Files
ccc-devtools/packages/cccdev-template-3x/src/store.ts
2026-03-15 19:21:04 +08:00

41 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { signal, computed } from '@preact/signals';
/** 当前选中的 cc.Node */
export const selectedNode = signal<any>(null);
/** 每帧 toggle1 / -1驱动属性面板重渲 */
export const updateTick = signal<number>(1);
/** DevTools 面板是否展开 */
export const devtoolsOpen = signal<boolean>(!!localStorage.getItem('cc_devtools_show'));
/** Profiler 浮窗是否展开 */
export const profilerOpen = signal<boolean>(false);
/** 节点树数据(每帧重建) */
export interface TreeNode {
uuid: string;
name: string;
active: boolean;
children: TreeNode[];
path: string[];
}
export const treeData = signal<TreeNode[]>([]);
/** 已展开节点的 uuid 集合 */
export const expandedUuids = signal<Set<string>>(new Set());
/** 是否有节点被选中且有效 */
export const hasSelection = computed(() => selectedNode.value !== null);
/** 节点搜索关键词 */
export const searchQuery = signal<string>('');
devtoolsOpen.subscribe((val) => {
if (val) {
localStorage.setItem('cc_devtools_show', '1');
} else {
localStorage.removeItem('cc_devtools_show');
}
});