2017-09-23 09:42:16 +00:00
|
|
|
'use strict';
|
|
|
|
var global = this;
|
|
|
|
/*global base*/
|
|
|
|
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
|
|
|
function init(root, plugin) {
|
|
|
|
global.root = root;
|
|
|
|
initDir();
|
|
|
|
loadCore();
|
|
|
|
loadRequire();
|
2017-10-09 13:17:24 +00:00
|
|
|
loadLib4Bukkit();
|
2017-09-23 09:42:16 +00:00
|
|
|
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');
|
2017-10-09 13:17:24 +00:00
|
|
|
load(core_dir + '/console.js');
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化模块
|
|
|
|
*/
|
|
|
|
function loadRequire() {
|
|
|
|
// 初始化加载器
|
2017-10-10 13:01:43 +00:00
|
|
|
global.require = load(core_dir + '/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');
|
|
|
|
global.setTimeout = function (func, time) {
|
|
|
|
return task.later(func, time)
|
|
|
|
};
|
|
|
|
global.clearTimeout = function (task) {
|
|
|
|
task.cancel();
|
|
|
|
};
|
|
|
|
global.setInterval = function (func, time) {
|
|
|
|
return task.timer(func, time)
|
|
|
|
};
|
|
|
|
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');
|
|
|
|
pluginManager.init(plugin, plugins_dir);
|
|
|
|
// 只有当在正式环境运行的时候才加载
|
|
|
|
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
|
|
|
}
|