async content中不需要强制使用await

This commit is contained in:
shijian 2023-12-18 09:08:16 +08:00
parent feaac1735e
commit d6fd7a4c62
1 changed files with 21 additions and 52 deletions

View File

@ -32141,9 +32141,12 @@ new Promise(resolve=>{
// 事件结束后触发resolve // 事件结束后触发resolve
event.resolve=resolve; event.resolve=resolve;
if(!_status.event) return; if(!_status.event) return;
if(!game.executingAsyncEventMap){
game.executingAsyncEventMap=new Map();
}
// game.createEvent的时候还没立即push到next里 // game.createEvent的时候还没立即push到next里
Promise.resolve().then(()=>{ Promise.resolve().then(()=>{
const callback=()=>{ game.executingAsyncEventMap.set(_status.event.toEvent(),(game.executingAsyncEventMap.get(_status.event.toEvent())||Promise.resolve()).then(()=>{
let eventPromise=_status.event.next.find(e=>e.toEvent()==event); let eventPromise=_status.event.next.find(e=>e.toEvent()==event);
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的 // 如果父级事件也是一个异步的话,那应该立即执行这个事件的
// 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件那也直接等会set配置完执行 // 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件那也直接等会set配置完执行
@ -32152,52 +32155,17 @@ new Promise(resolve=>{
// 不直接game.loop(event)是因为需要让别人可以手动set()和setContent() // 不直接game.loop(event)是因为需要让别人可以手动set()和setContent()
// 再执行game.loop是因为原有的game.loop被await卡住了 // 再执行game.loop是因为原有的game.loop被await卡住了
// 得新执行一个只执行这个异步事件的game.loop // 得新执行一个只执行这个异步事件的game.loop
if(!game.executingAsyncEventMap.has(_status.event.toEvent())){
game.executingAsyncEventMap.set(_status.event.toEvent(),Promise.resolve().then(()=>{
console.log(event.name, '将要执行');
if(_status.event!=eventPromise){ if(_status.event!=eventPromise){
eventPromise.parent=_status.event; eventPromise.parent=_status.event;
_status.event=eventPromise; _status.event=eventPromise;
game.getGlobalHistory('everything').push(eventPromise); game.getGlobalHistory('everything').push(eventPromise);
} }
return game.loop(eventPromise); return game.loop(eventPromise).then(()=>{
}).then(()=>{ // 有时候event.finished还是false
console.log(event.name, '执行完毕'); return eventPromise;
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
if(game.executingAsyncEventMap.has(_status.event.toEvent())){
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;
@ -41564,7 +41532,6 @@ new Promise(resolve=>{
_status.event = event.parent; _status.event = event.parent;
if (game.belongAsyncEvent == event) { if (game.belongAsyncEvent == event) {
delete game.belongAsyncEvent; delete game.belongAsyncEvent;
//resolve();
} }
_resolve(); _resolve();
// 此时应该退出了 // 此时应该退出了
@ -41575,7 +41542,6 @@ new Promise(resolve=>{
else { else {
if (game.belongAsyncEvent == event) { if (game.belongAsyncEvent == event) {
delete game.belongAsyncEvent; delete game.belongAsyncEvent;
//resolve();
} }
return _resolve(); return _resolve();
} }
@ -41634,7 +41600,11 @@ new Promise(resolve=>{
console.log(e); console.log(e);
} }
else throw e; else throw e;
}).then(after); }).then(after).then(()=>{
if (event.finished) {
if (game.executingAsyncEventMap) game.executingAsyncEventMap.clear();
}
});
} }
} }
} }
@ -41675,11 +41645,10 @@ new Promise(resolve=>{
// _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(() => {
if (game.executingAsyncEventMap && game.executingAsyncEventMap.has(event.toEvent())) { if (game.executingAsyncEventMap && game.executingAsyncEventMap.has(event.toEvent())) {
game.executingAsyncEventMap.get(event.toEvent()).then(() => { game.executingAsyncEventMap.set(_status.event.toEvent(), game.executingAsyncEventMap.get(_status.event.toEvent()).then(() => {
game.executingAsyncEventMap.delete(event.toEvent());
event.finish(); event.finish();
resolve(); resolve();
}); }));
} else { } else {
event.finish(); event.finish();
resolve(); resolve();