Merge pull request #938 from nonameShijian/PR-Branch
修复打开主代码报错的问题,修复所有js加载失败均弹窗的问题,修复代码编辑器访问caller等属性报错问题,对扩展自行创建武将包使用了lib.config.all.characters.push进行提示
This commit is contained in:
commit
7b04bb7817
|
@ -1753,8 +1753,7 @@ export class Game extends Uninstantable {
|
||||||
static import(type, content, url) {
|
static import(type, content, url) {
|
||||||
if (type == 'extension') {
|
if (type == 'extension') {
|
||||||
const promise = game.loadExtension(content).then((name) => {
|
const promise = game.loadExtension(content).then((name) => {
|
||||||
if (typeof _status.extensionLoaded == "undefined")
|
if (typeof _status.extensionLoaded == "undefined") _status.extensionLoaded = [];
|
||||||
_status.extensionLoaded = [];
|
|
||||||
_status.extensionLoaded.add(name);
|
_status.extensionLoaded.add(name);
|
||||||
return name;
|
return name;
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,14 +28,15 @@ export const importMode = generateImportFunction('mode', (name) => `../../mode/$
|
||||||
/**
|
/**
|
||||||
* 生成导入
|
* 生成导入
|
||||||
*
|
*
|
||||||
* @param {string} type
|
* @param { 'card' | 'character' | 'extension' | 'mode' } type
|
||||||
* @param {(name: string) => string} pathParser
|
* @param {(name: string) => string} pathParser
|
||||||
* @returns {(name: string) => Promise<void>}
|
* @returns {(name: string) => Promise<void>}
|
||||||
*/
|
*/
|
||||||
function generateImportFunction(type, pathParser) {
|
function generateImportFunction(type, pathParser) {
|
||||||
return async (name) => {
|
return async (name) => {
|
||||||
if(type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)){
|
if (type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)) {
|
||||||
await game.import(type,await createEmptyExtension(name));
|
// @ts-ignore
|
||||||
|
await game.import(type, await createEmptyExtension(name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let path = pathParser(name);
|
let path = pathParser(name);
|
||||||
|
@ -51,16 +52,18 @@ function generateImportFunction(type, pathParser) {
|
||||||
};
|
};
|
||||||
let script = createScript();
|
let script = createScript();
|
||||||
script.onerror = (e) => {
|
script.onerror = (e) => {
|
||||||
if (path.endsWith('.js')) {
|
if (path.endsWith('.js') && window.isSecureContext) {
|
||||||
path = path.slice(0, -3) + '.ts';
|
path = path.slice(0, -3) + '.ts';
|
||||||
script.remove();
|
script.remove();
|
||||||
let ts = createScript();
|
let ts = createScript();
|
||||||
ts.onerror = (e2) => {
|
ts.onerror = (e2) => {
|
||||||
console.error(`扩展《${name}》加载失败`,e,e2);
|
if (lib.path.basename(path) === 'extension.js' && lib.path.dirname(path).endsWith('/extension')) {
|
||||||
let remove = confirm(`扩展《${name}》加载失败,是否移除此扩展?此操作不会移除目录下的文件。`);
|
console.error(`扩展《${name}》加载失败`, e, e2);
|
||||||
if(remove){
|
let remove = confirm(`扩展《${name}》加载失败,是否移除此扩展?此操作不会移除目录下的文件。`);
|
||||||
lib.config.extensions.remove(name);
|
if (remove) {
|
||||||
game.saveConfig('extensions',lib.config.extensions);
|
lib.config.extensions.remove(name);
|
||||||
|
game.saveConfig('extensions', lib.config.extensions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resolve(['error', ts]);
|
resolve(['error', ts]);
|
||||||
}
|
}
|
||||||
|
@ -72,52 +75,69 @@ function generateImportFunction(type, pathParser) {
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
});
|
});
|
||||||
script.remove();
|
script.remove();
|
||||||
if (status === 'error') return;
|
if (status === 'error') {
|
||||||
|
if (type === 'character') {
|
||||||
|
console.error('如果您在扩展中使用了game.import创建武将包,请将以下代码删除: lib.config.all.characters.push(\'武将包名\');');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
const modeContent = await import(path);
|
const modeContent = await import(path);
|
||||||
if (!modeContent.type) return;
|
if (!modeContent.type) return;
|
||||||
if (modeContent.type !== type) throw new Error(`Loaded Content doesn't conform to "${type}" but "${modeContent.type}".`);
|
if (modeContent.type !== type) throw new Error(`Loaded Content doesn't conform to "${type}" but "${modeContent.type}".`);
|
||||||
|
// @ts-ignore
|
||||||
await game.import(type, modeContent.default);
|
await game.import(type, modeContent.default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createEmptyExtension(name){
|
async function createEmptyExtension(name) {
|
||||||
const extensionInfo = await lib.init.promises.json(`${lib.assetURL}extension/${name}/info.json`)//await import(`../../extension/${name}/info.json`,{assert:{type:'json'}})
|
const extensionInfo = await lib.init.promises.json(`${lib.assetURL}extension/${name}/info.json`)//await import(`../../extension/${name}/info.json`,{assert:{type:'json'}})
|
||||||
.then(info=>{
|
.then(info => info, () => {
|
||||||
return info;
|
return {
|
||||||
},()=>{
|
name: name,
|
||||||
return {
|
intro: `扩展<b>《${name}》</b>尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`,
|
||||||
name:name,
|
author: "未知",
|
||||||
intro:`扩展<b>《${name}》</b>尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`,
|
diskURL: "",
|
||||||
author:"未知",
|
forumURL: "",
|
||||||
diskURL:"",
|
version: "1.0",
|
||||||
forumURL:"",
|
};
|
||||||
version:"1.0",
|
});
|
||||||
};
|
return {
|
||||||
});
|
name: extensionInfo.name,
|
||||||
return {name:extensionInfo.name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{
|
content: function (config, pack) { },
|
||||||
character:{
|
precontent: function () { },
|
||||||
character:{
|
config: {},
|
||||||
|
help: {},
|
||||||
|
package: {
|
||||||
|
character: {
|
||||||
|
character: {
|
||||||
|
},
|
||||||
|
translate: {
|
||||||
|
},
|
||||||
},
|
},
|
||||||
translate:{
|
card: {
|
||||||
|
card: {
|
||||||
|
},
|
||||||
|
translate: {
|
||||||
|
},
|
||||||
|
list: [],
|
||||||
},
|
},
|
||||||
|
skill: {
|
||||||
|
skill: {
|
||||||
|
},
|
||||||
|
translate: {
|
||||||
|
},
|
||||||
|
},
|
||||||
|
intro: extensionInfo.intro ? extensionInfo.intro.replace("${assetURL}", lib.assetURL) : "",
|
||||||
|
author: extensionInfo.author ? extensionInfo.author : "未知",
|
||||||
|
diskURL: extensionInfo.diskURL ? extensionInfo.diskURL : "",
|
||||||
|
forumURL: extensionInfo.forumURL ? extensionInfo.forumURL : "",
|
||||||
|
version: extensionInfo.version ? extensionInfo.version : "1.0.0",
|
||||||
},
|
},
|
||||||
card:{
|
files: {
|
||||||
card:{
|
"character": [],
|
||||||
},
|
"card": [],
|
||||||
translate:{
|
"skill": [],
|
||||||
},
|
"audio": []
|
||||||
list:[],
|
}
|
||||||
},
|
}
|
||||||
skill:{
|
|
||||||
skill:{
|
|
||||||
},
|
|
||||||
translate:{
|
|
||||||
},
|
|
||||||
},
|
|
||||||
intro:extensionInfo.intro?extensionInfo.intro.replace("${assetURL}",lib.assetURL):"",
|
|
||||||
author:extensionInfo.author?extensionInfo.author:"未知",
|
|
||||||
diskURL:extensionInfo.diskURL?extensionInfo.diskURL:"",
|
|
||||||
forumURL:extensionInfo.forumURL?extensionInfo.forumURL:"",
|
|
||||||
version:extensionInfo.version?extensionInfo.version:"1.0.0",
|
|
||||||
},files:{"character":[],"card":[],"skill":[],"audio":[]}}
|
|
||||||
}
|
}
|
|
@ -301,8 +301,7 @@ export async function boot() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.get('gameRecord'))
|
if (!config.get('gameRecord')) config.set('gameRecord', {});
|
||||||
config.set('gameRecord', {});
|
|
||||||
for (const name in pack.mode) {
|
for (const name in pack.mode) {
|
||||||
if (config.get('hiddenModePack').indexOf(name) == -1) {
|
if (config.get('hiddenModePack').indexOf(name) == -1) {
|
||||||
config.get('all').mode.push(name);
|
config.get('all').mode.push(name);
|
||||||
|
@ -435,11 +434,8 @@ export async function boot() {
|
||||||
extensionlist.push(config.get('plays')[name]);
|
extensionlist.push(config.get('plays')[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var alerted = false;
|
|
||||||
for (var name = 0; name < config.get('extensions').length; name++) {
|
for (var name = 0; name < config.get('extensions').length; name++) {
|
||||||
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
||||||
//if(!alerted) alert('读取某些扩展时出现问题。');
|
|
||||||
alerted = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var extcontent = localStorage.getItem(lib.configprefix + 'extension_' + config.get('extensions')[name]);
|
var extcontent = localStorage.getItem(lib.configprefix + 'extension_' + config.get('extensions')[name]);
|
||||||
|
@ -462,11 +458,8 @@ export async function boot() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (config.get('mode') != 'connect' || (!localStorage.getItem(lib.configprefix + 'directstart') && show_splash)) {
|
if (config.get('mode') != 'connect' || (!localStorage.getItem(lib.configprefix + 'directstart') && show_splash)) {
|
||||||
var alerted = false;
|
|
||||||
for (var name = 0; name < config.get('extensions').length; name++) {
|
for (var name = 0; name < config.get('extensions').length; name++) {
|
||||||
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
||||||
//if(!alerted) alert('读取某些扩展时出现问题。');
|
|
||||||
alerted = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
@ -7883,7 +7883,11 @@ export class Library extends Uninstantable {
|
||||||
var icon = document.createElement("span");
|
var icon = document.createElement("span");
|
||||||
var className = "cm-completionIcon cm-completionIcon-";
|
var className = "cm-completionIcon cm-completionIcon-";
|
||||||
if (obj) {
|
if (obj) {
|
||||||
const type = typeof obj[text];
|
// 解决访问caller报错等问题
|
||||||
|
let type;
|
||||||
|
try {
|
||||||
|
type = typeof obj[text];
|
||||||
|
} catch {}
|
||||||
if (type == 'function') {
|
if (type == 'function') {
|
||||||
className += 'function';
|
className += 'function';
|
||||||
}
|
}
|
||||||
|
|
|
@ -5906,7 +5906,7 @@ class Create extends Uninstantable {
|
||||||
else {
|
else {
|
||||||
if (!window.CodeMirror) {
|
if (!window.CodeMirror) {
|
||||||
import('../../game/codemirror.js').then(() => {
|
import('../../game/codemirror.js').then(() => {
|
||||||
lib.codeMirrorReady(node, editor);
|
lib.codeMirrorReady(node, this.editor);
|
||||||
});
|
});
|
||||||
lib.init.css(lib.assetURL + 'layout/default', 'codemirror');
|
lib.init.css(lib.assetURL + 'layout/default', 'codemirror');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue