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) {
|
||||
if (type == 'extension') {
|
||||
const promise = game.loadExtension(content).then((name) => {
|
||||
if (typeof _status.extensionLoaded == "undefined")
|
||||
_status.extensionLoaded = [];
|
||||
if (typeof _status.extensionLoaded == "undefined") _status.extensionLoaded = [];
|
||||
_status.extensionLoaded.add(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
|
||||
* @returns {(name: string) => Promise<void>}
|
||||
*/
|
||||
function generateImportFunction(type, pathParser) {
|
||||
return async (name) => {
|
||||
if(type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)){
|
||||
await game.import(type,await createEmptyExtension(name));
|
||||
if (type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)) {
|
||||
// @ts-ignore
|
||||
await game.import(type, await createEmptyExtension(name));
|
||||
return;
|
||||
}
|
||||
let path = pathParser(name);
|
||||
|
@ -51,16 +52,18 @@ function generateImportFunction(type, pathParser) {
|
|||
};
|
||||
let script = createScript();
|
||||
script.onerror = (e) => {
|
||||
if (path.endsWith('.js')) {
|
||||
if (path.endsWith('.js') && window.isSecureContext) {
|
||||
path = path.slice(0, -3) + '.ts';
|
||||
script.remove();
|
||||
let ts = createScript();
|
||||
ts.onerror = (e2) => {
|
||||
console.error(`扩展《${name}》加载失败`,e,e2);
|
||||
let remove = confirm(`扩展《${name}》加载失败,是否移除此扩展?此操作不会移除目录下的文件。`);
|
||||
if(remove){
|
||||
lib.config.extensions.remove(name);
|
||||
game.saveConfig('extensions',lib.config.extensions);
|
||||
if (lib.path.basename(path) === 'extension.js' && lib.path.dirname(path).endsWith('/extension')) {
|
||||
console.error(`扩展《${name}》加载失败`, e, e2);
|
||||
let remove = confirm(`扩展《${name}》加载失败,是否移除此扩展?此操作不会移除目录下的文件。`);
|
||||
if (remove) {
|
||||
lib.config.extensions.remove(name);
|
||||
game.saveConfig('extensions', lib.config.extensions);
|
||||
}
|
||||
}
|
||||
resolve(['error', ts]);
|
||||
}
|
||||
|
@ -72,52 +75,69 @@ function generateImportFunction(type, pathParser) {
|
|||
document.head.appendChild(script);
|
||||
});
|
||||
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);
|
||||
if (!modeContent.type) return;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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'}})
|
||||
.then(info=>{
|
||||
return info;
|
||||
},()=>{
|
||||
return {
|
||||
name:name,
|
||||
intro:`扩展<b>《${name}》</b>尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`,
|
||||
author:"未知",
|
||||
diskURL:"",
|
||||
forumURL:"",
|
||||
version:"1.0",
|
||||
};
|
||||
});
|
||||
return {name:extensionInfo.name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{
|
||||
character:{
|
||||
character:{
|
||||
.then(info => info, () => {
|
||||
return {
|
||||
name: name,
|
||||
intro: `扩展<b>《${name}》</b>尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`,
|
||||
author: "未知",
|
||||
diskURL: "",
|
||||
forumURL: "",
|
||||
version: "1.0",
|
||||
};
|
||||
});
|
||||
return {
|
||||
name: extensionInfo.name,
|
||||
content: function (config, pack) { },
|
||||
precontent: function () { },
|
||||
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:{
|
||||
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",
|
||||
},files:{"character":[],"card":[],"skill":[],"audio":[]}}
|
||||
files: {
|
||||
"character": [],
|
||||
"card": [],
|
||||
"skill": [],
|
||||
"audio": []
|
||||
}
|
||||
}
|
||||
}
|
|
@ -301,8 +301,7 @@ export async function boot() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!config.get('gameRecord'))
|
||||
config.set('gameRecord', {});
|
||||
if (!config.get('gameRecord')) config.set('gameRecord', {});
|
||||
for (const name in pack.mode) {
|
||||
if (config.get('hiddenModePack').indexOf(name) == -1) {
|
||||
config.get('all').mode.push(name);
|
||||
|
@ -435,11 +434,8 @@ export async function boot() {
|
|||
extensionlist.push(config.get('plays')[name]);
|
||||
}
|
||||
}
|
||||
var alerted = false;
|
||||
for (var name = 0; name < config.get('extensions').length; name++) {
|
||||
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
||||
//if(!alerted) alert('读取某些扩展时出现问题。');
|
||||
alerted = true;
|
||||
continue;
|
||||
}
|
||||
var extcontent = localStorage.getItem(lib.configprefix + 'extension_' + config.get('extensions')[name]);
|
||||
|
@ -462,11 +458,8 @@ export async function boot() {
|
|||
}
|
||||
else {
|
||||
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++) {
|
||||
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
|
||||
//if(!alerted) alert('读取某些扩展时出现问题。');
|
||||
alerted = true;
|
||||
continue;
|
||||
}
|
||||
// @ts-ignore
|
||||
|
|
|
@ -7883,7 +7883,11 @@ export class Library extends Uninstantable {
|
|||
var icon = document.createElement("span");
|
||||
var className = "cm-completionIcon cm-completionIcon-";
|
||||
if (obj) {
|
||||
const type = typeof obj[text];
|
||||
// 解决访问caller报错等问题
|
||||
let type;
|
||||
try {
|
||||
type = typeof obj[text];
|
||||
} catch {}
|
||||
if (type == 'function') {
|
||||
className += 'function';
|
||||
}
|
||||
|
|
|
@ -5906,7 +5906,7 @@ class Create extends Uninstantable {
|
|||
else {
|
||||
if (!window.CodeMirror) {
|
||||
import('../../game/codemirror.js').then(() => {
|
||||
lib.codeMirrorReady(node, editor);
|
||||
lib.codeMirrorReady(node, this.editor);
|
||||
});
|
||||
lib.init.css(lib.assetURL + 'layout/default', 'codemirror');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue