2017-09-23 09:42:16 +00:00
|
|
|
'use strict';
|
|
|
|
var global = this;
|
|
|
|
/*global base*/
|
|
|
|
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
|
|
|
function init(root, plugin) {
|
|
|
|
global.root = root;
|
|
|
|
loadCore();
|
|
|
|
loadRequire();
|
2017-10-09 13:17:24 +00:00
|
|
|
loadLib4Bukkit();
|
2017-09-23 09:42:16 +00:00
|
|
|
loadPlugins(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化核心
|
|
|
|
*/
|
|
|
|
function loadCore() {
|
|
|
|
// 加载基础模块
|
2017-10-17 02:53:51 +00:00
|
|
|
load(root + '/core/ext.js');
|
|
|
|
load(root + '/core/console.js');
|
2017-10-14 06:32:50 +00:00
|
|
|
// 加载补丁和扩展
|
2017-10-17 02:53:51 +00:00
|
|
|
load(root + '/core/patch.js');
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化模块
|
|
|
|
*/
|
|
|
|
function loadRequire() {
|
|
|
|
// 初始化加载器
|
2017-10-17 02:53:51 +00:00
|
|
|
global.require = load(root + '/core/require.js')(root);
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 13:17:24 +00:00
|
|
|
function loadLib4Bukkit() {
|
|
|
|
require('modules/event');
|
|
|
|
var task = require('modules/task');
|
2017-10-17 02:53:51 +00:00
|
|
|
global.setTimeout = function (func, time, _async) {
|
|
|
|
return _async ? task.laterAsync(func, time) : task.later(func, time);
|
2017-10-09 13:17:24 +00:00
|
|
|
};
|
|
|
|
global.clearTimeout = function (task) {
|
|
|
|
task.cancel();
|
|
|
|
};
|
2017-10-17 02:53:51 +00:00
|
|
|
global.setInterval = function (func, time, _async) {
|
|
|
|
return _async ? task.timerAsync(func, time) : task.timer(func, time);
|
2017-10-09 13:17:24 +00:00
|
|
|
};
|
|
|
|
global.clearInterval = function (task) {
|
|
|
|
task.cancel();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-23 09:42:16 +00:00
|
|
|
/**
|
|
|
|
* 加载JS插件
|
|
|
|
*/
|
|
|
|
function loadPlugins(plugin) {
|
|
|
|
// 初始化本体插件
|
2017-09-27 12:40:57 +00:00
|
|
|
global.pluginManager = require('modules/plugin');
|
2017-10-17 02:53:51 +00:00
|
|
|
pluginManager.init(plugin, root + '/plugins');
|
2017-09-27 12:40:57 +00:00
|
|
|
// 只有当在正式环境运行的时候才加载
|
|
|
|
if (pluginManager.$) {
|
|
|
|
pluginManager.load();
|
|
|
|
pluginManager.enable();
|
2017-09-23 10:30:14 +00:00
|
|
|
}
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
|
|
|
/**
|
|
|
|
* 关闭插件Hook
|
|
|
|
*/
|
|
|
|
function disablePlugins() {
|
2017-09-27 12:40:57 +00:00
|
|
|
if (pluginManager.$) {
|
|
|
|
pluginManager.disable();
|
|
|
|
}
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|