mm_os 4.3.6 → 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.
- package/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -80
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -696
- package/com/mqtt/index.js +0 -1017
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/mm_mqtt.js +0 -446
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1283
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -385
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -710
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -297
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/store/sql.js +0 -1488
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -595
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive
|
|
3
|
-
} = require('mm_machine');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 实体管理器
|
|
7
|
-
*/
|
|
8
|
-
class EntityAdmin extends Drive {
|
|
9
|
-
/**
|
|
10
|
-
* 构造函数
|
|
11
|
-
* @param {object} config 配置对象
|
|
12
|
-
*/
|
|
13
|
-
constructor(config) {
|
|
14
|
-
super(config);
|
|
15
|
-
this._entities = new Map();
|
|
16
|
-
this._componentIndex = new Map();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 初始化核心组件
|
|
22
|
-
* @param {Map} entities 实体集合
|
|
23
|
-
* @param {object} factory 实体工厂
|
|
24
|
-
* @param {object} eventer 事件总线
|
|
25
|
-
* @param {object} logger 日志记录器
|
|
26
|
-
*/
|
|
27
|
-
EntityAdmin.prototype._initCore = async function (entities, factory, eventer, logger) {
|
|
28
|
-
if (!entities) {
|
|
29
|
-
this.log('error', '实体集合为空');
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (logger) {
|
|
33
|
-
this.setLogger(logger);
|
|
34
|
-
}
|
|
35
|
-
if (eventer) {
|
|
36
|
-
this.getEventer = function () {
|
|
37
|
-
return eventer;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (factory) {
|
|
41
|
-
this._factory = factory;
|
|
42
|
-
}
|
|
43
|
-
this._entities = entities;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 获取所有实体
|
|
48
|
-
* @returns {Iterator} 实体迭代器
|
|
49
|
-
*/
|
|
50
|
-
EntityAdmin.prototype.getEntities = function () {
|
|
51
|
-
return this._entities.values();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 获取实体
|
|
56
|
-
* @param {string} id 实体ID
|
|
57
|
-
* @returns {object} 实体
|
|
58
|
-
*/
|
|
59
|
-
EntityAdmin.prototype.getEntity = function (id) {
|
|
60
|
-
return this._entities.get(id);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 添加实体
|
|
65
|
-
* @param {object} entity 实体
|
|
66
|
-
*/
|
|
67
|
-
EntityAdmin.prototype.addEntity = function (entity) {
|
|
68
|
-
this._entities.set(entity.getId(), entity);
|
|
69
|
-
this._updateComponentIndex(entity);
|
|
70
|
-
// 触发实体创建事件
|
|
71
|
-
this.emitEvent('entity_create', {
|
|
72
|
-
entity_id: entity.getId(),
|
|
73
|
-
entity_type: entity.type || 'unknown',
|
|
74
|
-
timestamp: Date.now()
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 更新组件索引
|
|
80
|
-
* @param {object} entity 实体
|
|
81
|
-
* @returns {void}
|
|
82
|
-
*/
|
|
83
|
-
EntityAdmin.prototype._updateComponentIndex = function (entity) {
|
|
84
|
-
for (let [compName] of entity._component) {
|
|
85
|
-
if (!this._componentIndex.has(compName)) {
|
|
86
|
-
this._componentIndex.set(compName, new Set());
|
|
87
|
-
}
|
|
88
|
-
this._componentIndex.get(compName).add(entity.getId());
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 删除实体
|
|
94
|
-
* @param {string} id 实体ID
|
|
95
|
-
*/
|
|
96
|
-
EntityAdmin.prototype.delEntity = function (id) {
|
|
97
|
-
let entity = this._entities.get(id);
|
|
98
|
-
if (entity) {
|
|
99
|
-
// 触发实体销毁事件
|
|
100
|
-
this.emitEvent('entity_destroy', {
|
|
101
|
-
entity_id: id,
|
|
102
|
-
entity_type: entity.type || 'unknown',
|
|
103
|
-
timestamp: Date.now()
|
|
104
|
-
});
|
|
105
|
-
this._delCompIndex(entity);
|
|
106
|
-
this._entities.delete(id);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 从组件索引中移除实体
|
|
112
|
-
* @param {object} entity 实体
|
|
113
|
-
* @returns {void}
|
|
114
|
-
*/
|
|
115
|
-
EntityAdmin.prototype._delCompIndex = function (entity) {
|
|
116
|
-
for (let [compName] of entity._component) {
|
|
117
|
-
let index = this._componentIndex.get(compName);
|
|
118
|
-
if (index) {
|
|
119
|
-
index.delete(entity.getId());
|
|
120
|
-
if (index.size === 0) {
|
|
121
|
-
this._componentIndex.delete(compName);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 检查实体是否存在
|
|
129
|
-
* @param {string} id 实体ID
|
|
130
|
-
* @returns {boolean} 是否存在
|
|
131
|
-
*/
|
|
132
|
-
EntityAdmin.prototype.hasEntity = function (id) {
|
|
133
|
-
return this._entities.has(id);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 创建实体
|
|
138
|
-
* @param {object} model 实体配置
|
|
139
|
-
* @returns {object} 实体
|
|
140
|
-
*/
|
|
141
|
-
EntityAdmin.prototype.createEntity = function (model) {
|
|
142
|
-
var factory = this._factory[model.type];
|
|
143
|
-
if (!factory) {
|
|
144
|
-
this.log('error', `实体类型 ${model.type} 不存在`);
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
let entity = factory.create(model);
|
|
148
|
-
this.addEntity(entity);
|
|
149
|
-
return entity;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 删除实体组件
|
|
154
|
-
* @param {object} entity 实体
|
|
155
|
-
* @param {string} name 组件类型
|
|
156
|
-
*/
|
|
157
|
-
EntityAdmin.prototype.delComponent = function (entity, name) {
|
|
158
|
-
entity.delComponent(name);
|
|
159
|
-
// 触发实体组件移除事件
|
|
160
|
-
this.emitEvent('entity_component_del', {
|
|
161
|
-
entity_id: entity.getId(),
|
|
162
|
-
component: name,
|
|
163
|
-
timestamp: Date.now()
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 获取实体组件
|
|
169
|
-
* @param {object} entity 实体
|
|
170
|
-
* @param {string} name 组件类型
|
|
171
|
-
* @returns {object} 组件
|
|
172
|
-
*/
|
|
173
|
-
EntityAdmin.prototype.getComponent = function (entity, name) {
|
|
174
|
-
return entity.getComponent(name);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 添加实体组件
|
|
179
|
-
* @param {object} entity 实体
|
|
180
|
-
* @param {string} name 组件类型
|
|
181
|
-
*/
|
|
182
|
-
EntityAdmin.prototype.addComponent = function (entity, name) {
|
|
183
|
-
let component = this._component[name].create();
|
|
184
|
-
entity.addComponent(name, component);
|
|
185
|
-
// 触发实体组件添加事件
|
|
186
|
-
this.emitEvent('entity_component_add', {
|
|
187
|
-
entity_id: entity.getId(),
|
|
188
|
-
component: name,
|
|
189
|
-
timestamp: Date.now()
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* 查询包含特定组件的实体
|
|
195
|
-
* @param {Array} names 组件类型数组
|
|
196
|
-
* @returns {Array} 实体数组
|
|
197
|
-
*/
|
|
198
|
-
EntityAdmin.prototype.getByComponents = function (names) {
|
|
199
|
-
if (!names || names.length === 0) {
|
|
200
|
-
return [];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let first_comp = names[0];
|
|
204
|
-
let candidates = this._componentIndex.get(first_comp);
|
|
205
|
-
if (!candidates) {
|
|
206
|
-
return [];
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let result = [];
|
|
210
|
-
for (let entity_id of candidates) {
|
|
211
|
-
let entity = this._entities.get(entity_id);
|
|
212
|
-
if (entity) {
|
|
213
|
-
let has_all = true;
|
|
214
|
-
for (let i = 1; i < names.length; i++) {
|
|
215
|
-
if (!entity.hasComponent(names[i])) {
|
|
216
|
-
has_all = false;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (has_all) {
|
|
221
|
-
result.push(entity);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return result;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
module.exports = {
|
|
229
|
-
EntityAdmin
|
|
230
|
-
};
|
package/core/game/index.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive,
|
|
3
|
-
Manager
|
|
4
|
-
} = require('mm_machine');
|
|
5
|
-
const {
|
|
6
|
-
System
|
|
7
|
-
} = require('../system/index.js');
|
|
8
|
-
const {
|
|
9
|
-
Logic
|
|
10
|
-
} = require('../logic/index.js');
|
|
11
|
-
const {
|
|
12
|
-
Factory
|
|
13
|
-
} = require('../factory/index.js');
|
|
14
|
-
const {
|
|
15
|
-
Component
|
|
16
|
-
} = require('../component/index.js');
|
|
17
|
-
const {
|
|
18
|
-
Scene
|
|
19
|
-
} = require('../scene/index.js');
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 游戏
|
|
23
|
-
*/
|
|
24
|
-
class Game extends Drive {
|
|
25
|
-
static config = {
|
|
26
|
-
name: 'default',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 构造函数
|
|
31
|
-
* @param {object} config 游戏配置
|
|
32
|
-
* @param {object} parent 父驱动
|
|
33
|
-
*/
|
|
34
|
-
constructor(config, parent = null) {
|
|
35
|
-
super({...Game.config, ...config }, parent);
|
|
36
|
-
// // 游戏场景集合
|
|
37
|
-
// this.scene = {};
|
|
38
|
-
// 游戏系统集合
|
|
39
|
-
this.system = {};
|
|
40
|
-
// 游戏逻辑集合
|
|
41
|
-
this.logic = {};
|
|
42
|
-
// 游戏工厂集合
|
|
43
|
-
this.factory = {};
|
|
44
|
-
// 游戏组件集合
|
|
45
|
-
this.component = {};
|
|
46
|
-
|
|
47
|
-
// 管理器集合
|
|
48
|
-
this.manager = {};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// /**
|
|
53
|
-
// * 预设游戏配置
|
|
54
|
-
// */
|
|
55
|
-
// Game.prototype._preset = function () {
|
|
56
|
-
// this.file = null;
|
|
57
|
-
// this.sql = null;
|
|
58
|
-
// this.cache = null;
|
|
59
|
-
// };
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 初始化游戏核心
|
|
63
|
-
* @param {object} server 游戏服务器
|
|
64
|
-
* @param {object} eventer 事件分发器
|
|
65
|
-
* @param {object} logger 日志记录器
|
|
66
|
-
*/
|
|
67
|
-
Game.prototype._initCore = async function (server, eventer, logger) {
|
|
68
|
-
if (!server) {
|
|
69
|
-
throw new TypeError('游戏服务器不能为空');
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.getServer = function () {
|
|
73
|
-
return server;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (logger) {
|
|
77
|
-
this.setLogger(logger);
|
|
78
|
-
}
|
|
79
|
-
if (eventer) {
|
|
80
|
-
this.getEventer = function () {
|
|
81
|
-
return eventer;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
// 初始化管理
|
|
85
|
-
await this._initManager();
|
|
86
|
-
// 加载资源
|
|
87
|
-
await this._loadSources();
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 初始化管理器集合
|
|
92
|
-
* @returns {Promise<void>} 初始化完成
|
|
93
|
-
*/
|
|
94
|
-
Game.prototype._initManager = async function () {
|
|
95
|
-
// 创建所有管理器实例
|
|
96
|
-
var component = this._createManager('component', '组件', Component);
|
|
97
|
-
var factory = this._createManager('factory', '工厂', Factory);
|
|
98
|
-
var logic = this._createManager('logic', '逻辑', Logic);
|
|
99
|
-
var system = this._createManager('system', '系统', System);
|
|
100
|
-
var scene = this._createManager('scene', '场景', Scene);
|
|
101
|
-
|
|
102
|
-
// 并行执行所有管理器的初始化操作
|
|
103
|
-
var initPromises = [
|
|
104
|
-
component.do('init'),
|
|
105
|
-
factory.do('init'),
|
|
106
|
-
logic.do('init'),
|
|
107
|
-
system.do('init'),
|
|
108
|
-
scene.do('init'),
|
|
109
|
-
];
|
|
110
|
-
|
|
111
|
-
await Promise.all(initPromises);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* 创建管理器实例
|
|
116
|
-
* @param {string} name 管理器名称
|
|
117
|
-
* @param {string} title 管理器标题
|
|
118
|
-
* @param {Function} cls 管理器类
|
|
119
|
-
* @returns {object} 管理器实例
|
|
120
|
-
*/
|
|
121
|
-
Game.prototype._createManager = function (name, title, cls) {
|
|
122
|
-
let dir = this.getDir();
|
|
123
|
-
var manager = new Manager({
|
|
124
|
-
name: name,
|
|
125
|
-
title: title,
|
|
126
|
-
filename: name + '.json',
|
|
127
|
-
tpl_dir: `../${name}/`.fullname(__dirname),
|
|
128
|
-
base_dir: '',
|
|
129
|
-
dir: `./${name}`.fullname(dir)
|
|
130
|
-
}, this, this[name], cls);
|
|
131
|
-
this.manager[name] = manager;
|
|
132
|
-
return manager;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 加载资源
|
|
137
|
-
*/
|
|
138
|
-
Game.prototype._loadSources = async function () {
|
|
139
|
-
// 加载无需依赖关系,所以可以同时加载
|
|
140
|
-
await Promise.all([
|
|
141
|
-
this.manager.component.runAll('load'),
|
|
142
|
-
this.manager.factory.runAll('load'),
|
|
143
|
-
this.manager.logic.runAll('load'),
|
|
144
|
-
this.manager.system.runAll('load'),
|
|
145
|
-
this.manager.scene.runAll('load')
|
|
146
|
-
]);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 初始化资源
|
|
151
|
-
*/
|
|
152
|
-
Game.prototype._initSources = async function () {
|
|
153
|
-
// 初始化顺序 scene -> system -> logic -> factory -> entity -> component ,需要依赖下级,所以自下而上初始化
|
|
154
|
-
await this.manager.component.runAll('init', this.getLogger());
|
|
155
|
-
await this.manager.factory.runAll('init', this.component, this.getEventer(), this.getLogger());
|
|
156
|
-
await this.manager.logic.runAll('init', this.getLogger());
|
|
157
|
-
await this.manager.system.runAll('init', this, this.getEventer(), this.getLogger());
|
|
158
|
-
await this.manager.scene.runAll('init', this, this.getEventer(), this.getLogger());
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 启动核心
|
|
163
|
-
*/
|
|
164
|
-
Game.prototype._startCore = async function () {
|
|
165
|
-
// 初始化资源
|
|
166
|
-
await this._initSources();
|
|
167
|
-
// 启动资源
|
|
168
|
-
await this._startSources();
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 启动资源
|
|
173
|
-
*/
|
|
174
|
-
Game.prototype._startSources = async function () {
|
|
175
|
-
// 并行启动游戏系统和场景
|
|
176
|
-
await Promise.all([
|
|
177
|
-
// 启动游戏系统
|
|
178
|
-
this.manager.system.runAll('start'),
|
|
179
|
-
// 启动游戏场景
|
|
180
|
-
this.manager.scene.runAll('start')
|
|
181
|
-
]);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
module.exports = {
|
|
185
|
-
Game
|
|
186
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 名称
|
|
3
|
-
"name": "${name}",
|
|
4
|
-
// 标题
|
|
5
|
-
"title": "${title || '示例处理器'}",
|
|
6
|
-
// 描述
|
|
7
|
-
"description": "${description || '介绍该处理器有什么用'}",
|
|
8
|
-
// 主文件
|
|
9
|
-
"main": "${main || 'index.js'}",
|
|
10
|
-
// 作用域,决定加载到什么区域
|
|
11
|
-
"scope": "${scope || 'server'}",
|
|
12
|
-
// 状态 0:禁用 1:启用
|
|
13
|
-
"state": 1,
|
|
14
|
-
// 排序,越小越靠前
|
|
15
|
-
"sort": 100,
|
|
16
|
-
// 依赖的领域服务
|
|
17
|
-
"services": [],
|
|
18
|
-
// 依赖的仓储
|
|
19
|
-
"stores": [],
|
|
20
|
-
// 依赖的富血模型
|
|
21
|
-
"models": []
|
|
22
|
-
}
|
package/core/handler/index.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive
|
|
3
|
-
} = require('mm_machine');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 应用处理器基类(应用服务层)
|
|
7
|
-
* 负责处理请求,调用服务层,返回响应
|
|
8
|
-
*/
|
|
9
|
-
class Handler extends Drive {
|
|
10
|
-
static config = {
|
|
11
|
-
name: 'default',
|
|
12
|
-
title: '处理器',
|
|
13
|
-
// 依赖的服务
|
|
14
|
-
services: [],
|
|
15
|
-
// 依赖的仓储
|
|
16
|
-
stores: [],
|
|
17
|
-
// 依赖的富血模型
|
|
18
|
-
models: [],
|
|
19
|
-
timeout: 30000,
|
|
20
|
-
perf_log: false, // 是否记录性能日志
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* 构造函数
|
|
24
|
-
* @param {object} config 配置参数
|
|
25
|
-
* @param {object} parent 父对象
|
|
26
|
-
*/
|
|
27
|
-
constructor(config, parent) {
|
|
28
|
-
super({ ...Handler.config, ...config || {} }, parent);
|
|
29
|
-
|
|
30
|
-
// 仓储管理集合
|
|
31
|
-
this._store = {};
|
|
32
|
-
// 服务管理集合
|
|
33
|
-
this._service = {};
|
|
34
|
-
// 富血模型管理集合
|
|
35
|
-
this._model = {};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 预设
|
|
41
|
-
*/
|
|
42
|
-
Handler.prototype._preset = function () {
|
|
43
|
-
/** === 基础设施 === */
|
|
44
|
-
// 文件管理器
|
|
45
|
-
this._filer = null;
|
|
46
|
-
|
|
47
|
-
// 消息推送器
|
|
48
|
-
this._sender = null;
|
|
49
|
-
// 广播器
|
|
50
|
-
this._pusher = null;
|
|
51
|
-
// 通知器
|
|
52
|
-
this._notifier = null;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 获取模板目录
|
|
57
|
-
* @returns {string} 模板目录
|
|
58
|
-
*/
|
|
59
|
-
Handler.prototype.getTplDir = function () {
|
|
60
|
-
return __dirname;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 初始化依赖检查
|
|
65
|
-
*/
|
|
66
|
-
Handler.prototype._checkDeps = function () {
|
|
67
|
-
let {
|
|
68
|
-
services,
|
|
69
|
-
stores,
|
|
70
|
-
models
|
|
71
|
-
} = this.config;
|
|
72
|
-
|
|
73
|
-
for (var i = 0; i < services.length; i++) {
|
|
74
|
-
var name = services[i];
|
|
75
|
-
if (!this._service[name]) {
|
|
76
|
-
this.log('error', `${name}服务(service)未找到`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (var i = 0; i < stores.length; i++) {
|
|
81
|
-
var name = stores[i];
|
|
82
|
-
if (!this._store[name]) {
|
|
83
|
-
this.log('error', `${name}仓储(store)未找到`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (var i = 0; i < models.length; i++) {
|
|
88
|
-
var name = models[i];
|
|
89
|
-
if (!this._model[name]) {
|
|
90
|
-
this.log('error', `${name}模型(model)未找到`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 初始化核心
|
|
97
|
-
* @param {object} app 当前应用
|
|
98
|
-
* @param {object} eventer 事件总线
|
|
99
|
-
* @param {object} logger 日志管理器
|
|
100
|
-
*/
|
|
101
|
-
Handler.prototype._initCore = async function (app, eventer, logger) {
|
|
102
|
-
// 初始化依赖项
|
|
103
|
-
if (logger) {
|
|
104
|
-
this.setLogger(logger);
|
|
105
|
-
}
|
|
106
|
-
if (eventer) {
|
|
107
|
-
this.getEventer = function () {
|
|
108
|
-
return eventer;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let {
|
|
113
|
-
store,
|
|
114
|
-
service,
|
|
115
|
-
model
|
|
116
|
-
} = app;
|
|
117
|
-
this._store = store;
|
|
118
|
-
this._service = service;
|
|
119
|
-
this._model = model;
|
|
120
|
-
|
|
121
|
-
// 检查依赖项
|
|
122
|
-
this._checkDeps();
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 销毁处理器
|
|
127
|
-
*/
|
|
128
|
-
Handler.prototype._destroy = async function () {
|
|
129
|
-
try {
|
|
130
|
-
// 清理资源
|
|
131
|
-
this._store = null;
|
|
132
|
-
this._service = null;
|
|
133
|
-
this._model = null;
|
|
134
|
-
this._db = null;
|
|
135
|
-
this._cache = null;
|
|
136
|
-
this._filer = null;
|
|
137
|
-
|
|
138
|
-
this._sender = null;
|
|
139
|
-
this._pusher = null;
|
|
140
|
-
this._notifier = null;
|
|
141
|
-
|
|
142
|
-
} catch (error) {
|
|
143
|
-
this.log('error', '销毁发生错误:', error);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 请求预处理方法
|
|
149
|
-
* @param {object} req 请求对象
|
|
150
|
-
* @param {object} res 响应对象
|
|
151
|
-
* @returns {Promise<void>}
|
|
152
|
-
*/
|
|
153
|
-
Handler.prototype._before = async function (req, res) {
|
|
154
|
-
this.log('debug', '请求预处理', { req, res });
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 请求主处理逻辑
|
|
159
|
-
* 核心业务逻辑应该在此方法中实现
|
|
160
|
-
* @param {object} req 请求对象
|
|
161
|
-
* @param {object} res 响应对象
|
|
162
|
-
* @returns {Promise<object>} 处理结果
|
|
163
|
-
*/
|
|
164
|
-
Handler.prototype.main = async function (req, res) {
|
|
165
|
-
this.log('debug', '默认请求处理,子类应重写此方法', { req, res });
|
|
166
|
-
// 默认实现,子类必须重写
|
|
167
|
-
throw new Error('main 方法必须被重写');
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 请求后处理方法
|
|
172
|
-
* @param {object} req 请求对象
|
|
173
|
-
* @param {object} res 响应对象
|
|
174
|
-
* @param {object} result 处理结果
|
|
175
|
-
* @returns {Promise<void>}
|
|
176
|
-
*/
|
|
177
|
-
Handler.prototype._after = async function (req, res, result) {
|
|
178
|
-
this.log('debug', '请求后处理', { req, res, result });
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
exports.Handler = Handler;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 处理器(应用层)
|
|
3
|
-
*/
|
|
4
|
-
module.exports = {
|
|
5
|
-
/**
|
|
6
|
-
* 初始化
|
|
7
|
-
* @param {object} app 应用实例
|
|
8
|
-
* @param {object} eventer 事件总线
|
|
9
|
-
*/
|
|
10
|
-
async _init(app, eventer) {
|
|
11
|
-
// this.log('debug', `初始化!`);
|
|
12
|
-
// 可将监听写在这里
|
|
13
|
-
// eventer.on('');
|
|
14
|
-
},
|
|
15
|
-
/**
|
|
16
|
-
* 主要逻辑
|
|
17
|
-
* @param {...any} args 逻辑参数
|
|
18
|
-
*/
|
|
19
|
-
async main(...args) {
|
|
20
|
-
this.log('debug', `主要逻辑`);
|
|
21
|
-
// 主要代码写在这
|
|
22
|
-
}
|
|
23
|
-
};
|
package/core/logic/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const { Drive } = require('mm_machine');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 游戏逻辑基类
|
|
5
|
-
* 负责处理游戏业务规则和玩法逻辑
|
|
6
|
-
* 负责初始化游戏逻辑的核心组件,如日志记录器、工厂等
|
|
7
|
-
* 确保在游戏逻辑开始前,所有必要的组件都已初始化并准备就绪
|
|
8
|
-
*/
|
|
9
|
-
class Logic extends Drive {
|
|
10
|
-
static config = {
|
|
11
|
-
// 逻辑名称
|
|
12
|
-
name: 'default',
|
|
13
|
-
// 逻辑标题
|
|
14
|
-
title: '基础逻辑',
|
|
15
|
-
// 逻辑描述
|
|
16
|
-
description: '游戏逻辑基类,负责处理游戏业务规则和玩法逻辑',
|
|
17
|
-
// 入口脚本
|
|
18
|
-
script: './index.js',
|
|
19
|
-
// 状态 0:禁用 1:启用
|
|
20
|
-
state: 1,
|
|
21
|
-
// 排序,越小越靠前
|
|
22
|
-
sort: 0,
|
|
23
|
-
// 逻辑类型: core|module|system
|
|
24
|
-
type: 'system',
|
|
25
|
-
// 依赖的工厂组件
|
|
26
|
-
factorys: [],
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* 构造函数
|
|
30
|
-
* @param {object} config 配置参数
|
|
31
|
-
* @param {object} parent 父对象
|
|
32
|
-
*/
|
|
33
|
-
constructor(config, parent) {
|
|
34
|
-
// 确保正确合并配置并传递给父类构造函数
|
|
35
|
-
super({ ...Logic.config, ...config || {} }, parent);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 获取模板目录
|
|
41
|
-
* @returns {string} 模板目录
|
|
42
|
-
*/
|
|
43
|
-
Logic.prototype.getTplDir = function() {
|
|
44
|
-
return __dirname;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 初始化核心
|
|
49
|
-
* @param {object} logger 日志记录器实例
|
|
50
|
-
* @returns {Promise<void>}
|
|
51
|
-
*/
|
|
52
|
-
Logic.prototype._initCore = async function (logger) {
|
|
53
|
-
// 初始化依赖项
|
|
54
|
-
if (logger) {
|
|
55
|
-
this.setLogger(logger);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
exports.Logic = Logic;
|