Merge pull request #934 from universe-st/PR-Branch

导入扩展出错时弹窗提示并询问是否移除
This commit is contained in:
Spmario233 2024-02-11 15:44:10 +08:00 committed by GitHub
commit 5f9df3673f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -1367,7 +1367,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
yangfan:{
trigger:{player:'useCard'},
forced:true,
filter:(event,player)=>get.type(event.card)!='equip'&&player.hasCard(card=>get.color(card)==get.color(trigger.card)&&player.canRecast(card),'h'),
filter:(event,player)=>get.type(event.card)!='equip'&&player.hasCard(card=>get.color(card)==get.color(event.card)&&player.canRecast(card),'h'),
content(){
'step 0'
var cards=player.getCards('h',card=>get.suit(card)==get.suit(trigger.card)&&player.canRecast(card));

View File

@ -50,12 +50,20 @@ function generateImportFunction(type, pathParser) {
return script;
};
let script = createScript();
script.onerror = () => {
script.onerror = (e) => {
if (path.endsWith('.js')) {
path = path.slice(0, -3) + '.ts';
script.remove();
let ts = createScript();
ts.onerror = () => resolve(['error', ts]);
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);
}
resolve(['error', ts]);
}
document.head.appendChild(ts);
} else {
resolve(['error', script]);