从 tslib 导入辅助函数

This commit is contained in:
YHH
2025-10-11 10:36:59 +08:00
parent f45af34614
commit a0177c9163
7 changed files with 58 additions and 15 deletions

4
package-lock.json generated
View File

@@ -14515,7 +14515,6 @@
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"dev": true,
"license": "0BSD"
},
"node_modules/tuf-js": {
@@ -15560,7 +15559,8 @@
"version": "2.2.0",
"license": "MIT",
"dependencies": {
"msgpack-lite": "^0.1.26"
"msgpack-lite": "^0.1.26",
"tslib": "^2.8.1"
},
"devDependencies": {
"@babel/core": "^7.28.3",

View File

@@ -78,6 +78,7 @@
"directory": "packages/core"
},
"dependencies": {
"msgpack-lite": "^0.1.26"
"msgpack-lite": "^0.1.26",
"tslib": "^2.8.1"
}
}

View File

@@ -52,6 +52,13 @@ module.exports = [
})
],
external,
onwarn(warning, warn) {
// 忽略 msgpack-lite 的循环依赖警告
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
@@ -78,6 +85,12 @@ module.exports = [
})
],
external,
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: {
moduleSideEffects: false
}
@@ -103,6 +116,12 @@ module.exports = [
})
],
external: [],
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: {
moduleSideEffects: false
}
@@ -157,6 +176,12 @@ module.exports = [
})
],
external: [],
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: {
moduleSideEffects: false
}

View File

@@ -173,6 +173,13 @@ export class Core {
this._sceneManager = new SceneManager();
this._serviceContainer.registerInstance(SceneManager, this._sceneManager);
// 设置场景切换回调,通知调试管理器
this._sceneManager.setSceneChangedCallback(() => {
if (this._debugManager) {
this._debugManager.onSceneChanged();
}
});
// 初始化插件管理器
this._pluginManager = new PluginManager();
this._pluginManager.initialize(this, this._serviceContainer);

View File

@@ -14,7 +14,6 @@ import { SceneSerializer, SceneSerializationOptions, SceneDeserializationOptions
import { IncrementalSerializer, IncrementalSnapshot, IncrementalSerializationOptions } from './Serialization/IncrementalSerializer';
import { ComponentPoolManager } from './Core/ComponentPool';
import { PerformanceMonitor } from '../Utils/PerformanceMonitor';
import { Core } from '../Core';
import { ServiceContainer, type ServiceType } from '../Core/ServiceContainer';
import { createInstance, isInjectable } from '../Core/DI';
import { isUpdatable, getUpdatableMetadata } from '../Core/DI/Decorators';
@@ -183,11 +182,9 @@ export class Scene implements IScene {
this._services = new ServiceContainer();
this.logger = createLogger('Scene');
if (config?.performanceMonitor) {
this._performanceMonitor = config.performanceMonitor;
} else {
this._performanceMonitor = Core.services.resolve(PerformanceMonitor);
}
// 从配置获取 PerformanceMonitor,如果未提供则创建一个新实例
// Scene 应该是独立的,不依赖于 Core通过构造函数参数明确依赖关系
this._performanceMonitor = config?.performanceMonitor || new PerformanceMonitor();
if (config?.name) {
this.name = config.name;

View File

@@ -1,7 +1,6 @@
import { IScene } from './IScene';
import { ECSFluentAPI, createECSAPI } from './Core/FluentAPI';
import { Time } from '../Utils/Time';
import { Core } from '../Core';
import { createLogger } from '../Utils/Logger';
import type { IService } from '../Core/ServiceContainer';
@@ -68,6 +67,21 @@ export class SceneManager implements IService {
*/
private _logger = createLogger('SceneManager');
/**
* 场景切换回调函数
*/
private _onSceneChangedCallback?: () => void;
/**
* 设置场景切换回调
*
* @param callback 场景切换时的回调函数
* @internal
*/
public setSceneChangedCallback(callback: () => void): void {
this._onSceneChangedCallback = callback;
}
/**
* 设置当前场景(立即切换)
*
@@ -104,10 +118,9 @@ export class SceneManager implements IService {
// 触发场景切换回调
Time.sceneChanged();
// 通知调试管理器
const coreInstance = Core.Instance;
if (coreInstance && coreInstance._debugManager) {
coreInstance._debugManager.onSceneChanged();
// 通知调试管理器(通过回调)
if (this._onSceneChangedCallback) {
this._onSceneChangedCallback();
}
this._logger.info(`Scene changed to: ${scene.name}`);

View File

@@ -28,7 +28,7 @@
"noUncheckedIndexedAccess": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": false,
"importHelpers": true,
"downlevelIteration": true,
"isolatedModules": false,
"allowJs": true,