修复async content中事件不使用await会报错的问题2
This commit is contained in:
parent
d6941b3774
commit
feaac1735e
|
@ -2211,6 +2211,8 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
frequent:true,
|
frequent:true,
|
||||||
preHidden:true,
|
preHidden:true,
|
||||||
async content(event,trigger,player){
|
async content(event,trigger,player){
|
||||||
|
player.damage();
|
||||||
|
//player.recover();
|
||||||
await player.draw();
|
await player.draw();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
66
game/game.js
66
game/game.js
|
@ -32148,24 +32148,56 @@ new Promise(resolve=>{
|
||||||
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的
|
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的
|
||||||
// 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件,那也直接(等会set配置完)执行
|
// 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件,那也直接(等会set配置完)执行
|
||||||
if (eventPromise&&_status.event.content instanceof AsyncFunction){
|
if (eventPromise&&_status.event.content instanceof AsyncFunction){
|
||||||
if(_status.event!=eventPromise){
|
|
||||||
eventPromise.parent=_status.event;
|
|
||||||
_status.event=eventPromise;
|
|
||||||
game.getGlobalHistory('everything').push(eventPromise);
|
|
||||||
}
|
|
||||||
// 异步执行game.loop
|
// 异步执行game.loop
|
||||||
// 不直接game.loop(event)是因为需要让别人可以手动set()和setContent()
|
// 不直接game.loop(event)是因为需要让别人可以手动set()和setContent()
|
||||||
// 再执行game.loop是因为原有的game.loop被await卡住了,
|
// 再执行game.loop是因为原有的game.loop被await卡住了,
|
||||||
// 得新执行一个只执行这个异步事件的game.loop
|
// 得新执行一个只执行这个异步事件的game.loop
|
||||||
game.executingAsyncEvent=Promise.resolve().then(()=>game.loop(eventPromise))
|
if(!game.executingAsyncEventMap.has(_status.event.toEvent())){
|
||||||
.then(()=>{
|
game.executingAsyncEventMap.set(_status.event.toEvent(),Promise.resolve().then(()=>{
|
||||||
delete game.executingAsyncEvent;
|
console.log(event.name, '将要执行');
|
||||||
});
|
if(_status.event!=eventPromise){
|
||||||
|
eventPromise.parent=_status.event;
|
||||||
|
_status.event=eventPromise;
|
||||||
|
game.getGlobalHistory('everything').push(eventPromise);
|
||||||
|
}
|
||||||
|
return game.loop(eventPromise);
|
||||||
|
}).then(()=>{
|
||||||
|
console.log(event.name, '执行完毕');
|
||||||
|
return event.name;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
game.executingAsyncEventMap.set(_status.event.toEvent(),game.executingAsyncEventMap.get(_status.event.toEvent()).then(()=>{
|
||||||
|
console.log(event.name,'将要执行');
|
||||||
|
if (_status.event != eventPromise) {
|
||||||
|
eventPromise.parent = _status.event;
|
||||||
|
_status.event = eventPromise;
|
||||||
|
game.getGlobalHistory('everything').push(eventPromise);
|
||||||
|
}
|
||||||
|
return game.loop(eventPromise);
|
||||||
|
}).then(()=>{
|
||||||
|
console.log(event.name, '执行完毕');
|
||||||
|
return event.name;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
console.error(event.name,'没有执行');
|
||||||
|
console.error(_status.event.toEvent());
|
||||||
|
return event.name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if(!game.executingAsyncEventMap){
|
||||||
|
game.executingAsyncEventMap=new Map();
|
||||||
|
}
|
||||||
// 没有await上个事件(也就是_status.event)
|
// 没有await上个事件(也就是_status.event)
|
||||||
if(game.executingAsyncEvent) game.executingAsyncEvent.then(callback);
|
if(game.executingAsyncEventMap.has(_status.event.toEvent())){
|
||||||
else callback();
|
console.log(event.name,'正在等待',_status.event.name,'执行');
|
||||||
|
game.executingAsyncEventMap.set(_status.event.toEvent(),game.executingAsyncEventMap.get(_status.event.toEvent()).then(callback));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.log(event.name,'立即执行');
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.#event=event;
|
this.#event=event;
|
||||||
|
@ -41642,8 +41674,16 @@ new Promise(resolve=>{
|
||||||
else if (event.content instanceof AsyncFunction) {
|
else if (event.content instanceof AsyncFunction) {
|
||||||
// _status,lib,game,ui,get,ai六个变量由game.import提供
|
// _status,lib,game,ui,get,ai六个变量由game.import提供
|
||||||
event.content(event, trigger, player).then(() => {
|
event.content(event, trigger, player).then(() => {
|
||||||
event.finish();
|
if (game.executingAsyncEventMap && game.executingAsyncEventMap.has(event.toEvent())) {
|
||||||
resolve();
|
game.executingAsyncEventMap.get(event.toEvent()).then(() => {
|
||||||
|
game.executingAsyncEventMap.delete(event.toEvent());
|
||||||
|
event.finish();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
event.finish();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue