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

View File

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

View File

@@ -52,6 +52,13 @@ module.exports = [
}) })
], ],
external, 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: { treeshake: {
moduleSideEffects: false, moduleSideEffects: false,
propertyReadSideEffects: false, propertyReadSideEffects: false,
@@ -78,6 +85,12 @@ module.exports = [
}) })
], ],
external, external,
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: { treeshake: {
moduleSideEffects: false moduleSideEffects: false
} }
@@ -103,6 +116,12 @@ module.exports = [
}) })
], ],
external: [], external: [],
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: { treeshake: {
moduleSideEffects: false moduleSideEffects: false
} }
@@ -157,6 +176,12 @@ module.exports = [
}) })
], ],
external: [], external: [],
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) {
return;
}
warn(warning);
},
treeshake: { treeshake: {
moduleSideEffects: false moduleSideEffects: false
} }

View File

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

View File

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

View File

@@ -1,7 +1,6 @@
import { IScene } from './IScene'; import { IScene } from './IScene';
import { ECSFluentAPI, createECSAPI } from './Core/FluentAPI'; import { ECSFluentAPI, createECSAPI } from './Core/FluentAPI';
import { Time } from '../Utils/Time'; import { Time } from '../Utils/Time';
import { Core } from '../Core';
import { createLogger } from '../Utils/Logger'; import { createLogger } from '../Utils/Logger';
import type { IService } from '../Core/ServiceContainer'; import type { IService } from '../Core/ServiceContainer';
@@ -68,6 +67,21 @@ export class SceneManager implements IService {
*/ */
private _logger = createLogger('SceneManager'); 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(); Time.sceneChanged();
// 通知调试管理器 // 通知调试管理器(通过回调)
const coreInstance = Core.Instance; if (this._onSceneChangedCallback) {
if (coreInstance && coreInstance._debugManager) { this._onSceneChangedCallback();
coreInstance._debugManager.onSceneChanged();
} }
this._logger.info(`Scene changed to: ${scene.name}`); this._logger.info(`Scene changed to: ${scene.name}`);

View File

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