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,22 +0,0 @@
1
- /**
2
- * 仓储
3
- */
4
- module.exports = {
5
- /**
6
- * 初始化
7
- * @param {object} db 数据库管理器
8
- * @param {object} cache 缓存管理器
9
- */
10
- async _init(db, cache) {
11
- // 初始化代码写在这
12
- this.log('debug', 'store _init 被调用');
13
- },
14
- /**
15
- * 主要逻辑
16
- * @param {...any} args 参数列表
17
- */
18
- async main(...args) {
19
- // 主要代码写在这
20
- this.log('debug', 'store main 被调用', { args });
21
- }
22
- };
@@ -1,18 +0,0 @@
1
- {
2
- // 名称
3
- "name": "${name}",
4
- // 标题
5
- "title": "${title || 'XXX系统'}",
6
- // 描述
7
- "description": "${description || 'XXX系统介绍'}",
8
- // 主文件
9
- "main": "${main || 'index.js'}",
10
- // 状态 0:禁用 1:启用
11
- "state": 1,
12
- // 排序,越小越靠前
13
- "sort": 100,
14
- // 逻辑列表
15
- "logics": [],
16
- // 工厂
17
- "factorys": []
18
- }
@@ -1,312 +0,0 @@
1
- const { Drive } = require('mm_machine');
2
-
3
- /**
4
- * 系统基类
5
- * 负责处理包含特定组件组合的实体
6
- * 实现业务逻辑和游戏规则
7
- */
8
- class System extends Drive {
9
- static config = {
10
- // 系统名称
11
- 'name': 'default',
12
- // 系统标题
13
- 'title': '系统',
14
- // 系统描述
15
- 'description': '系统基类,负责处理实体和组件的业务逻辑',
16
- // 系统执行优先级
17
- 'sort': 100,
18
- // 依赖逻辑列表
19
- 'logics': [],
20
- // 依赖工厂列表
21
- 'factorys': []
22
- };
23
-
24
- /**
25
- * 构造函数
26
- * @param {object} config 配置参数
27
- * @param {object} parent 父对象
28
- */
29
- constructor(config, parent) {
30
- super({ ...System.config, ...config || {} }, parent);
31
-
32
- // 消息通道
33
- this._channel = null;
34
- // 工厂
35
- this._factory = {};
36
- // 逻辑管理
37
- this._logic = {};
38
- // 实体管理
39
- this._entityAdmin = null;
40
- // 系统是否启用
41
- this._enabled = true;
42
- }
43
- }
44
-
45
- /**
46
- * 预设
47
- */
48
- System.prototype._preset = function () {
49
- // 系统执行优先级
50
- this._priority = this.config.sort || 100;
51
- };
52
-
53
- /**
54
- * 获取模板目录
55
- * @returns {string} 模板目录
56
- */
57
- System.prototype.getTplDir = function () {
58
- return __dirname;
59
- };
60
-
61
- /**
62
- * 初始化系统核心
63
- * @param {object} channel 消息通道
64
- * @param {object} eventer 事件管理器
65
- * @param {object} logger 日志管理器
66
- */
67
- System.prototype._initCore = async function (channel, eventer, logger) {
68
- if (logger) {
69
- this.setLogger(logger);
70
- }
71
- if (eventer) {
72
- this.getEventer = function () {
73
- return eventer;
74
- };
75
- }
76
- // 初始化依赖项
77
- if (channel) {
78
- this._channel = channel;
79
- this._factory = channel.factory;
80
- this._logic = channel.logic;
81
- this._entityAdmin = channel.entityAdmin;
82
- }
83
- // 检测依赖
84
- this._checkDeps();
85
- };
86
-
87
- /**
88
- * 检测依赖
89
- */
90
- System.prototype._checkDeps = function () {
91
- let { logics, factorys } = this.config;
92
- logics = logics || [];
93
- factorys = factorys || [];
94
- // 检查逻辑依赖
95
- for (let logic of logics) {
96
- if (!this._logic[logic]) {
97
- throw new Error(`系统 ${this.config.name} 依赖逻辑 ${logic} 未注册`);
98
- }
99
- }
100
- // 检查工厂依赖
101
- for (let factory of factorys) {
102
- if (!this._factory[factory]) {
103
- throw new Error(`系统 ${this.config.name} 依赖工厂 ${factory} 未注册`);
104
- }
105
- }
106
- };
107
-
108
- /**
109
- * 获取系统依赖的逻辑对象
110
- * @param {string} name 逻辑名称
111
- * @returns {object} 逻辑对象
112
- */
113
- System.prototype.getLogic = function (name) {
114
- return this._logic[name];
115
- };
116
-
117
- /**
118
- * 获取系统依赖的工厂对象
119
- * @param {string} name 工厂名称
120
- * @returns {object} 工厂对象
121
- */
122
- System.prototype.getFactory = function (name) {
123
- return this._factory[name];
124
- };
125
-
126
- /**
127
- * 获取系统实体对象
128
- * @param {string} name 实体名称
129
- * @returns {object} 实体对象
130
- */
131
- System.prototype.getEntity = function (name) {
132
- return this._entityAdmin.get(name);
133
- };
134
-
135
- /**
136
- * 获取系统执行优先级
137
- * @returns {number} 优先级数值
138
- */
139
- System.prototype.getPriority = function () {
140
- return this._priority;
141
- };
142
-
143
- /**
144
- * 设置系统执行优先级
145
- * @param {number} priority 优先级数值
146
- */
147
- System.prototype.setPriority = function (priority) {
148
- // 参数校验
149
- if (typeof priority !== 'number') {
150
- throw new TypeError('优先级必须是数字');
151
- }
152
-
153
- this._priority = priority;
154
- };
155
-
156
- /**
157
- * 检查系统是否启用
158
- * @returns {boolean} 是否启用
159
- */
160
- System.prototype.isEnabled = function () {
161
- return this.status === 'running' && this._enabled;
162
- };
163
-
164
- /**
165
- * 启用系统
166
- */
167
- System.prototype.enable = function () {
168
- this._enabled = true;
169
- // 触发系统启用事件
170
- this.emitEvent('system_enable', {
171
- system_name: this.config.name,
172
- timestamp: Date.now()
173
- });
174
- };
175
-
176
- /**
177
- * 禁用系统
178
- */
179
- System.prototype.disable = function () {
180
- this._enabled = false;
181
- // 触发系统禁用事件
182
- this.emitEvent('system_disable', {
183
- system_name: this.config.name,
184
- timestamp: Date.now()
185
- });
186
- };
187
-
188
- /**
189
- * 系统更新方法
190
- * 子类必须重写此方法来实现具体的业务逻辑
191
- * @param {number} delta_time 时间增量(毫秒)
192
- */
193
- System.prototype.update = function (delta_time) {
194
- if (typeof delta_time !== 'number') {
195
- throw new TypeError('时间增量必须是数字');
196
- }
197
-
198
- // 触发系统更新事件
199
- this.emitEvent('system_update', {
200
- system_name: this.config.name,
201
- delta_time: delta_time,
202
- timestamp: Date.now()
203
- });
204
-
205
- let entities = this._entityAdmin.getByComponents(this.config.components);
206
-
207
- for (let entity of entities) {
208
- this._processEntity(entity, delta_time);
209
- }
210
- };
211
-
212
- /**
213
- * 处理单个实体
214
- * 子类必须重写此方法来实现具体的实体处理逻辑
215
- * @param {object} entity 实体对象
216
- * @param {number} delta_time 时间增量(毫秒)
217
- */
218
- System.prototype._processEntity = function (entity, delta_time) {
219
- // 参数校验
220
- if (!entity || typeof entity !== 'object') {
221
- throw new TypeError('实体对象必须是有效的对象');
222
- }
223
-
224
- if (typeof delta_time !== 'number') {
225
- throw new TypeError('时间增量必须是数字');
226
- }
227
-
228
- // 默认实现:记录实体处理
229
- this.log('info', `系统 ${this.config.name} 处理实体 ${entity.entity_id}`);
230
- };
231
-
232
- /**
233
- * 获取系统处理的实体数量
234
- * @returns {number} 实体数量
235
- */
236
- System.prototype.getEntityCount = function () {
237
- let entities = this._entityAdmin.getByComponents(this.config.components);
238
- return entities.length;
239
- };
240
-
241
- /**
242
- * 系统清理方法
243
- * 子类可以重写此方法来实现系统清理逻辑
244
- */
245
- System.prototype.cleanup = function () {
246
- // 默认实现:记录系统清理
247
- this.log('info', `系统 ${this.config.name} 清理完成`);
248
- };
249
-
250
- /**
251
- * 获取系统状态信息
252
- * @returns {object} 系统状态信息
253
- */
254
- System.prototype.getStatus = function () {
255
- return {
256
- name: this.config.name,
257
- title: this.config.title,
258
- description: this.config.description,
259
- enabled: this._enabled,
260
- priority: this._priority,
261
- entitys: this.getEntityCount()
262
- };
263
- };
264
-
265
- /**
266
- * 处理实体事件
267
- * 子类可以重写此方法来实现事件处理逻辑
268
- * @param {string} event_type 事件类型
269
- * @param {object} event_data 事件数据
270
- * @param {object} entity 实体对象
271
- */
272
- System.prototype.handleEvent = function (event_type, event_data, entity) {
273
- // 参数校验
274
- if (typeof event_type !== 'string') {
275
- throw new TypeError('事件类型必须是字符串');
276
- }
277
-
278
- if (typeof event_data !== 'object' || Array.isArray(event_data)) {
279
- throw new TypeError('事件数据必须是对象');
280
- }
281
-
282
- if (!this.isEnabled()) {
283
- return;
284
- }
285
-
286
- this.log('info', `系统 ${this.config.name} 处理事件 ${event_type} 实体 ${entity ? entity.entity_id : 'null'}`);
287
- };
288
-
289
- /**
290
- * 系统预更新方法
291
- * 在系统更新前调用,用于准备数据
292
- * @param {number} delta_time 时间增量(毫秒)
293
- */
294
- System.prototype.preUpdate = function (delta_time) {
295
- if (typeof delta_time !== 'number') {
296
- throw new TypeError('时间增量必须是数字');
297
- }
298
- };
299
-
300
- /**
301
- * 系统后更新方法
302
- * 在系统更新后调用,用于清理数据
303
- * @param {number} delta_time 时间增量(毫秒)
304
- */
305
- System.prototype.postUpdate = function (delta_time) {
306
- if (typeof delta_time !== 'number') {
307
- throw new TypeError('时间增量必须是数字');
308
- }
309
- };
310
-
311
- // 导出模块
312
- exports.System = System;
@@ -1,77 +0,0 @@
1
- /**
2
- * 游戏系统
3
- */
4
- module.exports = {
5
- /**
6
- * 初始化
7
- * @param {object} world 游戏世界类
8
- * @param {object} eventer 事件总线
9
- * @returns {Promise<void>}
10
- */
11
- async _init(world, eventer) {
12
- // this.log('debug', `初始化!`);
13
- // 监听事件写在这
14
- // eventer.on('事件名', this._方法名);
15
- },
16
- /**
17
- * 启动
18
- */
19
- async _start() {
20
- // this.log('debug', `启动!`);
21
- },
22
- /**
23
- * 停止
24
- */
25
- async _stop() {
26
- this.log('debug', `停止!`);
27
- },
28
- /**
29
- * 销毁
30
- * @param {...any} args 参数列表
31
- */
32
- async _destroy(...args) {
33
- this.log('debug', `销毁!`, { args });
34
- },
35
- /**
36
- * 更新,用于游戏循环
37
- */
38
- async update() {
39
- // 循环更新的代码逻辑写在这
40
- await this.main();
41
- },
42
- /**
43
- * 主要逻辑
44
- * @param {...any} args 参数列表
45
- */
46
- async main(...args) {
47
- // 主要代码写在这
48
- this.log('debug', `主要逻辑被调用`, { args });
49
- },
50
- /**
51
- * 怪物死亡(示例方法,可以删除)
52
- * @param {object} monster 怪物
53
- */
54
- onMonsterDeath(monster) {
55
- // ✅ System 调用 Factory 创建实体
56
- this.factory.effect.createExpOrb(
57
- this.world,
58
- monster.getComponent('position'),
59
- monster.getComponent('monster').exp_reward
60
- );
61
-
62
- // 随机掉落物品
63
- if (Math.random() < 0.3) {
64
- this.factory.factory.item.createRandomDrop(
65
- this.world,
66
- monster.getComponent('monster').loot_table
67
- );
68
- }
69
-
70
- // 处理死亡特效
71
- this.factory.effect.createDeathEffect(
72
- this.world,
73
- monster.getComponent('position'),
74
- monster.getComponent('monster').death_effect_type
75
- );
76
- }
77
- };
@@ -1,14 +0,0 @@
1
- {
2
- // 名称
3
- "name": "${name}",
4
- // 标题
5
- "title": "${title || '视图'}",
6
- // 描述
7
- "description": "${description || '视图'}",
8
- // 主文件
9
- "main": "${main || 'index.js'}",
10
- // 状态 0:禁用 1:启用
11
- "state": 1,
12
- // 排序,越小越靠前
13
- "sort": 100
14
- }
@@ -1,91 +0,0 @@
1
- const {
2
- Drive
3
- } = require('mm_machine');
4
- const Tpl = require('mm_tpl');
5
-
6
- /**
7
- * 渲染视图基类
8
- * 渲染html或消息模板
9
- */
10
- class View extends Drive {
11
- static config = {
12
- // 视图名称
13
- name: 'default',
14
- // 视图目录
15
- dir: './static/template',
16
- };
17
- /**
18
- * 构造函数
19
- * @param {object} config 配置参数
20
- * @param {object} parent 父对象
21
- */
22
- constructor(config, parent) {
23
- super({ ...View.config, ...config || {} }, parent);
24
- }
25
- }
26
-
27
- /**
28
- * 预设
29
- */
30
- View.prototype._preset = function () {
31
- // 模板引擎
32
- this._tpl = $.tpl;
33
- };
34
-
35
- /**
36
- * 获取模板目录
37
- * @returns {string} 模板目录
38
- */
39
- View.prototype.getTplDir = function () {
40
- return __dirname;
41
- };
42
-
43
- /**
44
- * 初始化核心
45
- * @param {object} logger 日志管理器
46
- */
47
- View.prototype._initCore = async function (logger) {
48
- // 初始化依赖项
49
- if (logger) {
50
- this.setLogger(logger);
51
- }
52
- this._tpl = new Tpl();
53
- };
54
-
55
- /**
56
- * 渲染html模板
57
- * @param {string} html 模板
58
- * @param {object} model 数据模型
59
- * @returns {string} 渲染结果
60
- */
61
- View.prototype.render = async function (html, model) {
62
- // 参数校验
63
- if (!html || typeof html !== 'string') {
64
- throw new TypeError('模板必须是非空字符串');
65
- }
66
- if (model && typeof model !== 'object') {
67
- throw new TypeError('数据模型必须是对象');
68
- }
69
- // 渲染模板
70
- return this._tpl.render(html, model);
71
- };
72
-
73
- /**
74
- * 渲染html模板文件
75
- * @param {string} file 模板文件
76
- * @param {object} model 数据模型
77
- * @returns {string} 渲染结果
78
- */
79
- View.prototype.view = async function (file, model) {
80
- // 参数校验
81
- if (!file || typeof file !== 'string') {
82
- throw new TypeError('模板文件必须是非空字符串');
83
- }
84
- if (model && typeof model !== 'object') {
85
- throw new TypeError('数据模型必须是对象');
86
- }
87
- // 渲染模板文件
88
- return this._tpl.view(file, model);
89
- };
90
-
91
- exports.View = View;
@@ -1,20 +0,0 @@
1
- /**
2
- * 渲染器
3
- */
4
- module.exports = {
5
- /**
6
- * 初始化
7
- * @returns {Promise<void>}
8
- */
9
- async _init() {
10
- this.log('debug', '初始化!');
11
- },
12
- /**
13
- * 主要逻辑
14
- * @param {...any} args 参数列表
15
- */
16
- async main(...args) {
17
- this.log('debug', 'view main 被调用', { args });
18
- // 主要代码写在这
19
- }
20
- };