refactor: 减少全局变量 调试require选项
This commit is contained in:
@ -5,34 +5,21 @@ var global = this;
|
||||
// noinspection JSUnusedLocalSymbols
|
||||
function init(root, plugin) {
|
||||
global.root = root;
|
||||
initDir();
|
||||
loadCore();
|
||||
loadRequire();
|
||||
loadLib4Bukkit();
|
||||
loadPlugins(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化目录
|
||||
*/
|
||||
function initDir() {
|
||||
// 核心目录
|
||||
global.core_dir = root + "/core";
|
||||
// 模块目录
|
||||
global.miao_module_dir = root + "/modules";
|
||||
// 插件目录
|
||||
global.plugins_dir = root + "/plugins";
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化核心
|
||||
*/
|
||||
function loadCore() {
|
||||
// 加载基础模块
|
||||
load(core_dir + '/ext.js');
|
||||
load(core_dir + '/console.js');
|
||||
load(root + '/core/ext.js');
|
||||
load(root + '/core/console.js');
|
||||
// 加载补丁和扩展
|
||||
load(core_dir + '/patch.js');
|
||||
load(root + '/core/patch.js');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,20 +27,20 @@ function loadCore() {
|
||||
*/
|
||||
function loadRequire() {
|
||||
// 初始化加载器
|
||||
global.require = load(core_dir + '/require.js')(root);
|
||||
global.require = load(root + '/core/require.js')(root);
|
||||
}
|
||||
|
||||
function loadLib4Bukkit() {
|
||||
require('modules/event');
|
||||
var task = require('modules/task');
|
||||
global.setTimeout = function (func, time, async) {
|
||||
return async ? task.laterAsync(func, time) : task.later(func, time);
|
||||
global.setTimeout = function (func, time, _async) {
|
||||
return _async ? task.laterAsync(func, time) : task.later(func, time);
|
||||
};
|
||||
global.clearTimeout = function (task) {
|
||||
task.cancel();
|
||||
};
|
||||
global.setInterval = function (func, time, async) {
|
||||
return async ? task.timerAsync(func, time) : task.timer(func, time);
|
||||
global.setInterval = function (func, time, _async) {
|
||||
return _async ? task.timerAsync(func, time) : task.timer(func, time);
|
||||
};
|
||||
global.clearInterval = function (task) {
|
||||
task.cancel();
|
||||
@ -66,7 +53,7 @@ function loadLib4Bukkit() {
|
||||
function loadPlugins(plugin) {
|
||||
// 初始化本体插件
|
||||
global.pluginManager = require('modules/plugin');
|
||||
pluginManager.init(plugin, plugins_dir);
|
||||
pluginManager.init(plugin, root + '/plugins');
|
||||
// 只有当在正式环境运行的时候才加载
|
||||
if (pluginManager.$) {
|
||||
pluginManager.load();
|
||||
|
Reference in New Issue
Block a user