MCPcopy Create free account
hub / github.com/esengine/esengine / createWorld

Method createWorld

packages/core/src/ECS/WorldManager.ts:93–118  ·  view source on GitHub ↗

* 创建新World

(worldName: string, config?: IWorldConfig)

Source from the content-addressed store, hash-verified

91 * 创建新World
92 */
93 public createWorld(worldName: string, config?: IWorldConfig): World {
94 if (!worldName || typeof worldName !== 'string' || worldName.trim() === '') {
95 throw new Error('World name不能为空');
96 }
97
98 if (this._worlds.has(worldName)) {
99 throw new Error(`World name '${worldName}' 已存在`);
100 }
101
102 if (this._worlds.size >= this._config.maxWorlds!) {
103 throw new Error(`已达到最大World数量限制: ${this._config.maxWorlds}`);
104 }
105
106 // 优先级:config.debug > WorldManager.debug > 默认
107 const worldConfig: IWorldConfig = {
108 name: worldName,
109 debug: config?.debug ?? this._config.debug ?? false,
110 ...(config?.maxScenes !== undefined && { maxScenes: config.maxScenes }),
111 ...(config?.autoCleanup !== undefined && { autoCleanup: config.autoCleanup })
112 };
113
114 const world = new World(worldConfig);
115 this._worlds.set(worldName, world);
116
117 return world;
118 }
119
120 /**
121 * 移除World

Callers 3

Calls 2

hasMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected