feat: 调整基础类库加载
This commit is contained in:
parent
f164f7dd42
commit
9ef64d9bc2
@ -3,24 +3,6 @@
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// Java格式化方法
|
||||
var str = Java.type('java.lang.String');
|
||||
String.prototype.format = function () {
|
||||
return str.format(this, Array.prototype.slice.call(arguments, 0))
|
||||
};
|
||||
|
||||
// ========== 暂不扩展Object ==========
|
||||
// // JSON快捷方法
|
||||
// Object.prototype.toJson = function () {
|
||||
// return JSON.stringify(this);
|
||||
// };
|
||||
|
||||
// // YAML快速生成
|
||||
// var yaml = require('modules/yaml');
|
||||
// Object.prototype.toYaml = function () {
|
||||
// return yaml.safeDump(this);
|
||||
// };
|
||||
|
||||
/**
|
||||
* 日期格式化
|
||||
* 例: new Date().format('yyyy-MM-dd hh:mm:ss.s') => "2017-08-24 16:15:40.693"
|
50
src/main/resources/core/ext/Object.js
Normal file
50
src/main/resources/core/ext/Object.js
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 补丁和方法扩展
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// Object.assign Polyfill
|
||||
if (!Object.assign) {
|
||||
Object.defineProperty(Object, "assign", {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(target) {
|
||||
"use strict";
|
||||
if (target === undefined || target === null)
|
||||
throw new TypeError("Cannot convert first argument to object");
|
||||
var to = Object(target);
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var nextSource = arguments[i];
|
||||
if (nextSource === undefined || nextSource === null) continue;
|
||||
var keysArray = Object.keys(Object(nextSource));
|
||||
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
|
||||
var nextKey = keysArray[nextIndex];
|
||||
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
||||
if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey];
|
||||
}
|
||||
}
|
||||
return to;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// // JSON快捷方法
|
||||
if(!Object.toJson){
|
||||
Object.defineProperty(Object, "toJson", {
|
||||
enumerable: false,
|
||||
value: function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Object.prototype.toJson = function () {
|
||||
// return JSON.stringify(this);
|
||||
// };
|
||||
|
||||
// // YAML快速生成
|
||||
// var yaml = require('modules/yaml');
|
||||
// Object.prototype.toYaml = function () {
|
||||
// return yaml.safeDump(this);
|
||||
// };
|
||||
})();
|
11
src/main/resources/core/ext/String.js
Normal file
11
src/main/resources/core/ext/String.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 补丁和方法扩展
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// Java格式化方法
|
||||
var str = Java.type('java.lang.String');
|
||||
String.prototype.format = function () {
|
||||
return str.format(this, Array.prototype.slice.call(arguments, 0))
|
||||
};
|
||||
})();
|
@ -8,9 +8,9 @@
|
||||
global.noop = function () {
|
||||
};
|
||||
loadCore();
|
||||
loadExt();
|
||||
loadRequire();
|
||||
try {
|
||||
loadExt();
|
||||
loadServerLib();
|
||||
loadPlugins();
|
||||
} catch (ex) {
|
||||
@ -43,8 +43,7 @@
|
||||
* 加载补丁
|
||||
*/
|
||||
function loadExt() {
|
||||
var fs = require('core/fs');
|
||||
fs.list(fs.file(root, 'core/ext')).forEach(function (path) {
|
||||
java.nio.file.Files.list(new java.io.File(root, 'core/ext').toPath()).forEach(function (path) {
|
||||
console.log('加载扩展类库', path);
|
||||
try {
|
||||
load(path.toFile());
|
||||
@ -59,7 +58,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载Bukkit的类库
|
||||
* 加载系统类库
|
||||
*/
|
||||
function loadServerLib() {
|
||||
var task = require('api/task');
|
||||
|
@ -106,7 +106,6 @@
|
||||
file = ext.notNull(dir) ? new File(dir, file) : new File(file);
|
||||
// 直接文件
|
||||
if (file.isFile()) {
|
||||
console.log(file);
|
||||
return file;
|
||||
}
|
||||
// JS文件
|
||||
@ -184,7 +183,6 @@
|
||||
if (_canonical(file).endsWith('.msm')) {
|
||||
throw Error("暂不支持解析 MiaoScript 模块");
|
||||
}
|
||||
console.debug('模块', name, '编译成功!');
|
||||
} catch (ex) {
|
||||
console.console('§4警告! §c模块§a', name, '§c编译失败! §4ERR:', ex);
|
||||
console.ex(ex);
|
||||
@ -240,11 +238,13 @@
|
||||
function _require(name, path, optional) {
|
||||
var file = new File(name);
|
||||
file = _isFile(file) ? file : resolve(name, path);
|
||||
optional = Object.assign({cache: true, warnNotFound: true}, optional);
|
||||
if (file === undefined) {
|
||||
if (optional.warnNotFound) {
|
||||
console.console('§c目录§b', path, '§c下模块§a', name, '§c加载失败! §4未找到该模块!');
|
||||
}
|
||||
return {exports: {}};
|
||||
}
|
||||
if (!optional) optional = {cache: true};
|
||||
// 重定向文件名称和类型
|
||||
return getCacheModule(_canonical(file), file.name.split(".")[0], file, optional);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user