refactor: reorganize package structure and decouple framework packages (#338)
* refactor: reorganize package structure and decouple framework packages ## Package Structure Reorganization - Reorganized 55 packages into categorized subdirectories: - packages/framework/ - Generic framework (Laya/Cocos compatible) - packages/engine/ - ESEngine core modules - packages/rendering/ - Rendering modules (WASM dependent) - packages/physics/ - Physics modules - packages/streaming/ - World streaming - packages/network-ext/ - Network extensions - packages/editor/ - Editor framework and plugins - packages/rust/ - Rust WASM engine - packages/tools/ - Build tools and SDK ## Framework Package Decoupling - Decoupled behavior-tree and blueprint packages from ESEngine dependencies - Created abstracted interfaces (IBTAssetManager, IBehaviorTreeAssetContent) - ESEngine-specific code moved to esengine/ subpath exports - Framework packages now usable with Cocos/Laya without ESEngine ## CI Configuration - Updated CI to only type-check and lint framework packages - Added type-check:framework and lint:framework scripts ## Breaking Changes - Package import paths changed due to directory reorganization - ESEngine integrations now use subpath imports (e.g., '@esengine/behavior-tree/esengine') * fix: update es-engine file path after directory reorganization * docs: update README to focus on framework over engine * ci: only build framework packages, remove Rust/WASM dependencies * fix: remove esengine subpath from behavior-tree and blueprint builds ESEngine integration code will only be available in full engine builds. Framework packages are now purely engine-agnostic. * fix: move network-protocols to framework, build both in CI * fix: update workflow paths from packages/core to packages/framework/core * fix: exclude esengine folder from type-check in behavior-tree and blueprint * fix: update network tsconfig references to new paths * fix: add test:ci:framework to only test framework packages in CI * fix: only build core and math npm packages in CI * fix: exclude test files from CodeQL and fix string escaping security issue
This commit is contained in:
96
packages/editor/editor-app/src/utils/idGenerator.ts
Normal file
96
packages/editor/editor-app/src/utils/idGenerator.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* ID Generator Utility
|
||||
* 提供安全可靠的ID生成机制
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates unique sequential IDs for textures and other resources
|
||||
* 为纹理和其他资源生成唯一的顺序ID
|
||||
*/
|
||||
export class IdGenerator {
|
||||
private static counters = new Map<string, number>();
|
||||
private static usedIds = new Map<string, Set<number>>();
|
||||
|
||||
/**
|
||||
* Generate next sequential ID for a given namespace
|
||||
* 为给定的命名空间生成下一个顺序ID
|
||||
*/
|
||||
static nextId(namespace: string): number {
|
||||
const current = this.counters.get(namespace) || 1000;
|
||||
const next = current + 1;
|
||||
this.counters.set(namespace, next);
|
||||
|
||||
// Track used IDs
|
||||
if (!this.usedIds.has(namespace)) {
|
||||
this.usedIds.set(namespace, new Set());
|
||||
}
|
||||
this.usedIds.get(namespace)!.add(next);
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate UUID v4
|
||||
* 生成 UUID v4
|
||||
*/
|
||||
static uuid(): string {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ID is already used
|
||||
* 检查ID是否已被使用
|
||||
*/
|
||||
static isUsed(namespace: string, id: number): boolean {
|
||||
return this.usedIds.get(namespace)?.has(id) || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a specific ID
|
||||
* 保留特定的ID
|
||||
*/
|
||||
static reserve(namespace: string, id: number): void {
|
||||
if (!this.usedIds.has(namespace)) {
|
||||
this.usedIds.set(namespace, new Set());
|
||||
}
|
||||
this.usedIds.get(namespace)!.add(id);
|
||||
|
||||
// Update counter if needed
|
||||
const current = this.counters.get(namespace) || 1000;
|
||||
if (id >= current) {
|
||||
this.counters.set(namespace, id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release an ID for reuse
|
||||
* 释放ID以供重用
|
||||
*/
|
||||
static release(namespace: string, id: number): void {
|
||||
this.usedIds.get(namespace)?.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a namespace
|
||||
* 重置命名空间
|
||||
*/
|
||||
static reset(namespace: string): void {
|
||||
this.counters.delete(namespace);
|
||||
this.usedIds.delete(namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics for a namespace
|
||||
* 获取命名空间的统计信息
|
||||
*/
|
||||
static getStats(namespace: string): { nextId: number; usedCount: number } {
|
||||
return {
|
||||
nextId: (this.counters.get(namespace) || 1000) + 1,
|
||||
usedCount: this.usedIds.get(namespace)?.size || 0
|
||||
};
|
||||
}
|
||||
}
|
||||
75
packages/editor/editor-app/src/utils/updater.ts
Normal file
75
packages/editor/editor-app/src/utils/updater.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { check, Update } from '@tauri-apps/plugin-updater';
|
||||
|
||||
export interface UpdateCheckResult {
|
||||
available: boolean;
|
||||
version?: string;
|
||||
currentVersion?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// 全局存储更新对象,以便后续安装
|
||||
let pendingUpdate: Update | null = null;
|
||||
|
||||
/**
|
||||
* 检查应用更新(仅检查,不安装)
|
||||
*
|
||||
* 自动检查 GitHub Releases 是否有新版本
|
||||
* 返回检查结果,由调用者决定是否安装
|
||||
*/
|
||||
export async function checkForUpdates(): Promise<UpdateCheckResult> {
|
||||
try {
|
||||
const update = await check();
|
||||
|
||||
if (update?.available) {
|
||||
pendingUpdate = update;
|
||||
return {
|
||||
available: true,
|
||||
version: update.version,
|
||||
currentVersion: update.currentVersion
|
||||
};
|
||||
} else {
|
||||
pendingUpdate = null;
|
||||
return { available: false };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查更新失败:', error);
|
||||
pendingUpdate = null;
|
||||
return {
|
||||
available: false,
|
||||
error: error instanceof Error ? error.message : '检查更新失败'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装待处理的更新
|
||||
* 需要先调用 checkForUpdates 检测到更新
|
||||
*/
|
||||
export async function installUpdate(): Promise<boolean> {
|
||||
if (!pendingUpdate) {
|
||||
console.error('没有待安装的更新');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await pendingUpdate.downloadAndInstall();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('安装更新失败:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时静默检查更新
|
||||
* 返回 Promise 以便调用者可以获取结果
|
||||
*/
|
||||
export async function checkForUpdatesOnStartup(): Promise<UpdateCheckResult> {
|
||||
// 延迟 2 秒后检查,避免影响启动速度
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(async () => {
|
||||
const result = await checkForUpdates();
|
||||
resolve(result);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user