mm_os 4.3.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -84
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -704
  46. package/com/mqtt/index.js +0 -1052
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/script.tpl.js +0 -719
  49. package/com/nav/README.md +0 -2
  50. package/com/nav/com.json +0 -5
  51. package/com/nav/config.tpl.json +0 -84
  52. package/com/nav/drive.js +0 -702
  53. package/com/nav/index.js +0 -228
  54. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  55. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  56. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  57. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  58. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  59. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  60. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  61. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  62. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  63. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  64. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  67. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  68. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  69. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  70. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  71. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  74. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  75. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  76. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  77. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  78. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  81. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  82. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  83. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  84. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  85. package/com/nav/viewmodel.js +0 -446
  86. package/com/param/README.md +0 -2
  87. package/com/param/com.json +0 -5
  88. package/com/param/config.tpl.json +0 -136
  89. package/com/param/drive.js +0 -502
  90. package/com/param/index.js +0 -158
  91. package/com/param/script.tpl.js +0 -12
  92. package/com/pendant/README.md +0 -3
  93. package/com/pendant/com.json +0 -5
  94. package/com/pendant/config.tpl.json +0 -32
  95. package/com/pendant/drive.js +0 -204
  96. package/com/pendant/index.js +0 -467
  97. package/com/pendant/pendant.html +0 -16
  98. package/com/pendant/script.tpl.js +0 -18
  99. package/com/socket/README.md +0 -47
  100. package/com/socket/com.json +0 -5
  101. package/com/socket/config.tpl.json +0 -12
  102. package/com/socket/drive.js +0 -679
  103. package/com/socket/index.js +0 -402
  104. package/com/socket/script.tpl.js +0 -41
  105. package/com/sql/README.md +0 -3
  106. package/com/sql/com.json +0 -5
  107. package/com/sql/config.tpl.json +0 -74
  108. package/com/sql/drive.js +0 -1328
  109. package/com/sql/index.js +0 -152
  110. package/com/sql/script.tpl.js +0 -47
  111. package/com/static/README.md +0 -2
  112. package/com/static/com.json +0 -5
  113. package/com/static/config.tpl.json +0 -24
  114. package/com/static/drive.js +0 -194
  115. package/com/static/index.js +0 -237
  116. package/com/static/script.tpl.js +0 -28
  117. package/com/task/README.md +0 -3
  118. package/com/task/com.json +0 -5
  119. package/com/task/config.tpl.json +0 -24
  120. package/com/task/drive.js +0 -428
  121. package/com/task/index.js +0 -159
  122. package/com/task/script.tpl.js +0 -40
  123. package/com/template/com.json +0 -5
  124. package/com/template/config.tpl.json +0 -16
  125. package/com/template/drive.js +0 -81
  126. package/com/template/index.js +0 -141
  127. package/com.js +0 -237
  128. package/common/README.md +0 -2
  129. package/common/middleware/web_after/index.js +0 -26
  130. package/common/middleware/web_after/middleware.json +0 -9
  131. package/common/middleware/web_base/index.js +0 -113
  132. package/common/middleware/web_base/middleware.json +0 -19
  133. package/common/middleware/web_before/index.js +0 -33
  134. package/common/middleware/web_before/middleware.json +0 -9
  135. package/common/middleware/web_cors/index.js +0 -87
  136. package/common/middleware/web_cors/middleware.json +0 -24
  137. package/common/middleware/web_error/index.js +0 -131
  138. package/common/middleware/web_error/middleware.json +0 -19
  139. package/common/middleware/web_ip/index.js +0 -15
  140. package/common/middleware/web_ip/middleware.json +0 -14
  141. package/common/middleware/web_logger/index.js +0 -156
  142. package/common/middleware/web_logger/middleware.json +0 -14
  143. package/common/middleware/web_main/index.js +0 -26
  144. package/common/middleware/web_main/middleware.json +0 -9
  145. package/common/middleware/web_static/index.js +0 -73
  146. package/common/middleware/web_static/middleware.json +0 -54
  147. package/common/middleware/web_waf/index.js +0 -395
  148. package/common/middleware/web_waf/middleware.json +0 -13
  149. package/core/app/config.tpl.json +0 -67
  150. package/core/app/index.js +0 -711
  151. package/core/app/script.tpl.js +0 -52
  152. package/core/channel/index.js +0 -899
  153. package/core/channel/matcher.js +0 -585
  154. package/core/com/config.tpl.json +0 -16
  155. package/core/com/index.js +0 -77
  156. package/core/com/script.tpl.js +0 -5
  157. package/core/component/component.js +0 -42
  158. package/core/component/config.tpl.json +0 -63
  159. package/core/component/index.js +0 -273
  160. package/core/component/script.tpl.js +0 -19
  161. package/core/controller/config.tpl.json +0 -14
  162. package/core/controller/index.js +0 -371
  163. package/core/controller/script.tpl.js +0 -27
  164. package/core/factory/config.tpl.json +0 -14
  165. package/core/factory/entity.js +0 -275
  166. package/core/factory/index.js +0 -241
  167. package/core/factory/script.tpl.js +0 -16
  168. package/core/game/bat/index.js +0 -137
  169. package/core/game/bat/world.js +0 -622
  170. package/core/game/config.tpl.json +0 -16
  171. package/core/game/entity_admin.js +0 -230
  172. package/core/game/index.js +0 -186
  173. package/core/handler/config.tpl.json +0 -22
  174. package/core/handler/index.js +0 -181
  175. package/core/handler/script.tpl.js +0 -23
  176. package/core/logic/config.tpl.json +0 -14
  177. package/core/logic/index.js +0 -59
  178. package/core/logic/script.tpl.js +0 -19
  179. package/core/middleware/config.tpl.json +0 -16
  180. package/core/middleware/index.js +0 -117
  181. package/core/middleware/script.tpl.js +0 -37
  182. package/core/mod/config.tpl.json +0 -22
  183. package/core/mod/index.js +0 -136
  184. package/core/mod/script.tpl.js +0 -34
  185. package/core/model/config.tpl.json +0 -219
  186. package/core/model/index.js +0 -272
  187. package/core/model/model.js +0 -27
  188. package/core/model/script.tpl.js +0 -20
  189. package/core/notifier/config.tpl.json +0 -14
  190. package/core/notifier/index.js +0 -77
  191. package/core/notifier/script.tpl.js +0 -20
  192. package/core/plugin/config.tpl.json +0 -36
  193. package/core/plugin/index.js +0 -267
  194. package/core/plugin/script.tpl.js +0 -51
  195. package/core/pusher/config.tpl.json +0 -14
  196. package/core/pusher/index.js +0 -158
  197. package/core/pusher/script.tpl.js +0 -20
  198. package/core/room/bat/index.js +0 -170
  199. package/core/room/bat/room.js +0 -524
  200. package/core/room/config.tpl.json +0 -20
  201. package/core/room/index.js +0 -249
  202. package/core/room/room.js +0 -61
  203. package/core/scene/config.tpl.json +0 -14
  204. package/core/scene/index.js +0 -467
  205. package/core/scene/loop.js +0 -1306
  206. package/core/scene/map.js +0 -28
  207. package/core/scene/script.tpl.js +0 -22
  208. package/core/sender/config.tpl.json +0 -14
  209. package/core/sender/index.js +0 -79
  210. package/core/sender/script.tpl.js +0 -20
  211. package/core/service/config.tpl.json +0 -14
  212. package/core/service/index.js +0 -100
  213. package/core/service/script.tpl.js +0 -25
  214. package/core/store/config.tpl.json +0 -26
  215. package/core/store/index.js +0 -1794
  216. package/core/store/script.tpl.js +0 -22
  217. package/core/system/config.tpl.json +0 -18
  218. package/core/system/index.js +0 -312
  219. package/core/system/script.tpl.js +0 -77
  220. package/core/view/config.tpl.json +0 -14
  221. package/core/view/index.js +0 -91
  222. package/core/view/script.tpl.js +0 -20
  223. package/core/zone/bat/index.js +0 -744
  224. package/core/zone/config.tpl.json +0 -54
  225. package/core/zone/index.js +0 -655
  226. package/core/zone/script.tpl.js +0 -10
  227. package/core/zone/zone_bat.js +0 -136
  228. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  229. package/os.js +0 -53
  230. package/server.js +0 -602
  231. package/ulits/id_gen.js +0 -134
  232. package/ulits/word.js +0 -206
@@ -1,467 +0,0 @@
1
- const {
2
- Drive
3
- } = require('mm_machine');
4
-
5
- /**
6
- * 场景基类
7
- * 负责管理游戏场景中的实体和图层,处理场景生命周期
8
- * 场景是Entity实例的容器,管理实体的生命周期
9
- */
10
- class Scene extends Drive {
11
- static config = {
12
- // 场景名称
13
- name: 'default',
14
- // 场景描述
15
- desc: '',
16
- // 场景优先级
17
- priority: 0,
18
- // 是否激活场景
19
- active: true
20
- };
21
- /**
22
- * 构造函数
23
- * @param {object} config 配置参数
24
- * @param {object} parent 父场景对象
25
- */
26
- constructor(config, parent) {
27
- super({ ...Scene.config, ...config || {} }, parent);
28
- // 系统实例集合,主要调用场景系统SceneSystem
29
- this._system = {};
30
- // 图层映射集合
31
- this._layers = {};
32
- // 地图实例集合
33
- this.map = {};
34
- // /**
35
- // * 地图集合
36
- // * @type {object} 地图对象
37
- // */
38
- // this.maps = new Map();
39
- // // 实体集合
40
- // this._entities = new Map();
41
- }
42
- }
43
-
44
- /**
45
- * 预设
46
- */
47
- Scene.prototype._preset = function () {
48
- // 是否激活场景
49
- this.active = this.config.active;
50
- };
51
-
52
- /**
53
- * 获取模板目录
54
- * @returns {string} 模板目录
55
- */
56
- Scene.prototype.getTplDir = function () {
57
- return __dirname;
58
- };
59
-
60
- /**
61
- * 初始化核心
62
- * @override
63
- * @param {object} system 系统对象
64
- * @param {object} eventer 事件对象
65
- * @param {object} logger 日志对象
66
- * @returns {Promise<void>}
67
- */
68
- Scene.prototype._initCore = async function (system, eventer, logger) {
69
- // 初始化依赖项
70
- if (logger) {
71
- this.setLogger(logger);
72
- }
73
- if (eventer) {
74
- this.getEventer = function () {
75
- return eventer;
76
- };
77
- }
78
- if (system) {
79
- this._system = system;
80
- }
81
-
82
- // 初始化场景
83
- await this._loadSources();
84
- // 初始化地图
85
- await this._initMap();
86
- // 初始化实体
87
- await this._initEntities();
88
-
89
- // 触发场景加载事件
90
- this.emitEvent('scene_load', {
91
- scene_id: this.scene_id,
92
- scene_name: this.config.name,
93
- timestamp: Date.now()
94
- });
95
- };
96
-
97
- /**
98
- * 初始化地图
99
- * @private
100
- */
101
- Scene.prototype._initMap = async function () {
102
- // 子类应重写此方法初始化地图
103
- };
104
-
105
- /**
106
- * 加载场景资源
107
- * @private
108
- * @returns {Promise<void>}
109
- */
110
- Scene.prototype._loadSources = async function () {
111
- // 子类应重写此方法加载场景所需资源
112
- };
113
-
114
- /**
115
- * 添加实体到场景
116
- * @param {object} entity 实体对象
117
- * @returns {boolean} 添加是否成功
118
- */
119
- Scene.prototype.addEntity = function (entity) {
120
- // 参数校验
121
- if (!entity || typeof entity !== 'object') {
122
- this.log('error', '实体必须是非空对象');
123
- return false;
124
- }
125
-
126
- // 检查实体是否已存在
127
- if (this._entities.has(entity.entity_id)) {
128
- return true; // 已存在,返回成功
129
- }
130
-
131
- // 添加实体
132
- this._entities.set(entity.entity_id, entity);
133
-
134
- // 设置实体的场景引用
135
- if (entity.setScene && typeof entity.setScene === 'function') {
136
- entity.setScene(this);
137
- }
138
-
139
- this.log('info', `实体 [${entity.entity_id}] 添加到场景`);
140
-
141
- return true;
142
- };
143
-
144
- /**
145
- * 从场景移除实体
146
- * @param {object|string} entity 实体对象或实体ID
147
- * @returns {boolean} 移除是否成功
148
- */
149
- Scene.prototype.delEntity = function (entity) {
150
- // 参数校验
151
- if (!entity) {
152
- this.log('error', '实体参数不能为空');
153
- return false;
154
- }
155
-
156
- // 如果是ID,直接从Map中移除
157
- if (typeof entity === 'string') {
158
- if (!this._entities.has(entity)) {
159
- return false; // 实体不存在
160
- }
161
- this._entities.delete(entity);
162
- this.log('info', `实体 [${entity}] 从场景移除`);
163
- return true;
164
- }
165
-
166
- // 如果是对象,使用实体ID移除
167
- if (!entity.entity_id || !this._entities.has(entity.entity_id)) {
168
- return false; // 实体不存在于场景中
169
- }
170
-
171
- this._entities.delete(entity.entity_id);
172
-
173
- this.log('info', `实体 [${entity.entity_id}] 从场景移除`);
174
-
175
- return true;
176
- };
177
-
178
- /**
179
- * 根据ID或属性查找实体
180
- * @param {string | number | object} query 查询条件
181
- * @returns {object|null} 找到的实体或null
182
- */
183
- Scene.prototype.findEntity = function (query) {
184
- if (!query) {
185
- return null;
186
- }
187
-
188
- if (typeof query === 'string' || typeof query === 'number') {
189
- return this._findById(query);
190
- }
191
-
192
- if (query.prototype && typeof query === 'function') {
193
- return this._findByType(query);
194
- }
195
-
196
- if (typeof query === 'object') {
197
- return this._findByProps(query);
198
- }
199
-
200
- return null;
201
- };
202
-
203
- /**
204
- * 根据ID查找实体
205
- * @param {string | number} id 实体ID
206
- * @returns {object|null} 找到的实体或null
207
- */
208
- Scene.prototype._findById = function (id) {
209
- return this._entities.get(id) || null;
210
- };
211
-
212
- /**
213
- * 根据构造函数类型查找实体
214
- * @param {Function} type 构造函数
215
- * @returns {object|null} 找到的实体或null
216
- */
217
- Scene.prototype._findByType = function (type) {
218
- for (let entity of this._entities.values()) {
219
- if (entity instanceof type) {
220
- return entity;
221
- }
222
- }
223
- return null;
224
- };
225
-
226
- /**
227
- * 根据属性对象查找实体
228
- * @param {object} props 属性对象
229
- * @returns {object|null} 找到的实体或null
230
- */
231
- Scene.prototype._findByProps = function (props) {
232
- for (let entity of this._entities.values()) {
233
- if (this._matchProps(entity, props)) {
234
- return entity;
235
- }
236
- }
237
- return null;
238
- };
239
-
240
- /**
241
- * 检查实体属性是否匹配
242
- * @param {object} entity 实体
243
- * @param {object} props 属性对象
244
- * @returns {boolean} 是否匹配
245
- */
246
- Scene.prototype._matchProps = function (entity, props) {
247
- for (let key in props) {
248
- if (entity[key] !== props[key]) {
249
- return false;
250
- }
251
- }
252
- return true;
253
- };
254
-
255
- /**
256
- * 查找符合条件的所有实体
257
- * @param {object} query 查询条件
258
- * @returns {Array} 符合条件的实体数组
259
- */
260
- Scene.prototype.findEntities = function (query = {}) {
261
- if (!query || typeof query !== 'object') {
262
- return [...this._entities.values()];
263
- }
264
-
265
- let result = [];
266
- for (let entity of this._entities.values()) {
267
- let match = true;
268
- for (let key in query) {
269
- if (entity[key] !== query[key]) {
270
- match = false;
271
- break;
272
- }
273
- }
274
- if (match) {
275
- result.push(entity);
276
- }
277
- }
278
- return result;
279
- };
280
-
281
- /**
282
- * 添加图层
283
- * @param {string} name 图层名称
284
- * @param {object} layer 图层对象
285
- * @returns {boolean} 添加是否成功
286
- */
287
- Scene.prototype.addLayer = function (name, layer) {
288
- // 参数校验
289
- if (!name || typeof name !== 'string') {
290
- this.log('error', '图层名称必须是非空字符串');
291
- return false;
292
- }
293
-
294
- if (!layer || typeof layer !== 'object') {
295
- this.log('error', '图层对象必须是非空对象');
296
- return false;
297
- }
298
-
299
- // 添加图层
300
- this._layers[name] = layer;
301
-
302
- return true;
303
- };
304
-
305
- /**
306
- * 获取图层
307
- * @param {string} name 图层名称
308
- * @returns {object | null} 图层对象或null
309
- */
310
- Scene.prototype.getLayer = function (name) {
311
- if (!name || typeof name !== 'string') {
312
- this.log('error', '图层名称必须是非空字符串');
313
- return null;
314
- }
315
-
316
- return this._layers[name] || null;
317
- };
318
-
319
- /**
320
- * 更新场景
321
- * @param {number} delta 时间间隔(毫秒)
322
- */
323
- Scene.prototype.set = function (delta) {
324
- // 如果场景不活跃,不更新
325
- if (!this.active) {
326
- return;
327
- }
328
-
329
- // 更新所有实体
330
- for (let entity of this._entities.values()) {
331
- try {
332
- if (entity.update && typeof entity.update === 'function') {
333
- entity.update(delta);
334
- }
335
- } catch (error) {
336
- this.log('error', '更新实体时出错:', error);
337
- // 可以选择移除出错的实体
338
- // this.delEntity(entity);
339
- }
340
- }
341
- };
342
-
343
- /**
344
- * 渲染场景
345
- */
346
- Scene.prototype.render = function () {
347
- // 如果场景不活跃,不渲染
348
- if (!this.active) {
349
- return;
350
- }
351
-
352
- // 渲染所有图层
353
- Object.values(this._layers).forEach(layer => {
354
- try {
355
- if (layer.render && typeof layer.render === 'function') {
356
- layer.render();
357
- }
358
- } catch (error) {
359
- this.log('error', '渲染图层时出错:', error);
360
- }
361
- });
362
- };
363
-
364
- /**
365
- * 清理场景资源
366
- * @override
367
- */
368
- Scene.prototype._destroy = function () {
369
- try {
370
- // 触发场景卸载事件
371
- this.emitEvent('scene_unload', {
372
- scene_id: this.scene_id,
373
- scene_name: this.config.name,
374
- timestamp: Date.now()
375
- });
376
-
377
- // 清理所有实体
378
- for (let entity of this.map._entities.values()) {
379
- try {
380
- if (entity.destroy && typeof entity.destroy === 'function') {
381
- entity.destroy();
382
- }
383
- } catch (error) {
384
- this.log('error', '销毁实体时出错:', error);
385
- }
386
- }
387
-
388
- // 清空引用
389
- this.map._entities = null;
390
- } catch (error) {
391
- this.log('error', '场景销毁失败:', error);
392
- }
393
- };
394
-
395
- /**
396
- * 实体进入场景
397
- * @param {object} entity 实体对象
398
- * @returns {boolean} 是否成功进入
399
- */
400
- Scene.prototype.enter = async function (entity) {
401
- // 参数校验
402
- if (!entity || typeof entity !== 'object') {
403
- throw new TypeError('实体对象必须是非空对象');
404
- }
405
-
406
- // 添加实体到场景
407
- this._entities.set(entity.entity_id, entity);
408
-
409
- // 触发实体进入场景事件(如果事件总线存在)
410
- this.emitEvent('entity_enter_scene', {
411
- scene_id: this.scene_id,
412
- scene_name: this.config.name,
413
- entity_id: entity.entity_id,
414
- timestamp: Date.now()
415
- });
416
-
417
- return true;
418
- };
419
-
420
- /**
421
- * 实体离开场景
422
- * @param {object} entity 实体对象
423
- * @returns {boolean} 是否成功离开
424
- */
425
- Scene.prototype.leave = async function (entity) {
426
- // 参数校验
427
- if (!entity || typeof entity !== 'object') {
428
- throw new TypeError('实体对象必须是非空对象');
429
- }
430
-
431
- // 从场景移除实体
432
- if (!entity.entity_id || !this._entities.has(entity.entity_id)) {
433
- throw new Error('实体不在场景中');
434
- }
435
- this._entities.delete(entity.entity_id);
436
-
437
- // 触发实体离开场景事件(如果事件总线存在)
438
- this.emitEvent('entity_leave_scene', {
439
- scene_id: this.scene_id,
440
- scene_name: this.config.name,
441
- entity_id: entity.entity_id,
442
- timestamp: Date.now()
443
- });
444
- return true;
445
- };
446
-
447
- /**
448
- * 更新场景
449
- * @param {number} delta 时间间隔(毫秒)
450
- */
451
- Scene.prototype.update = function (delta) {
452
- // 如果场景不活跃,不更新
453
- if (!this.isRunning()) {
454
- return;
455
- }
456
-
457
- // 触发场景更新事件
458
- this.emitEvent('scene_update', {
459
- scene_id: this.scene_id,
460
- scene_name: this.config.name,
461
- delta: delta,
462
- timestamp: Date.now()
463
- });
464
- };
465
-
466
- // 导出模块
467
- exports.Scene = Scene;