From e0020298ab295ba7d5956d73d0b844934d72e268 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Wed, 11 Oct 2023 02:41:25 -0700 Subject: [PATCH] Add the ability of chain calling for events, and fix several connect mode bugs. --- game/game.js | 135 +++++++++++++++++++++++++++++++++--------------- mode/connect.js | 27 ++++------ 2 files changed, 103 insertions(+), 59 deletions(-) diff --git a/game/game.js b/game/game.js index 366fae268..42822e321 100644 --- a/game/game.js +++ b/game/game.js @@ -8236,7 +8236,7 @@ lib.ui=ui; lib.ai=ai; lib.game=game; - _status.event=new lib.element.Event(); + _status.event=new lib.element.Event().finish(); HTMLDivElement.prototype.animate=function(name,time){ var that; @@ -30354,45 +30354,49 @@ changeToZero(){ this.num=0; this.numFixed=true; + return this; } finish(){ this.finished=true; + return this; } putStepCache(key,value){ if(!this._stepCache){ - this._stepCache = {}; + this._stepCache={}; } - this._stepCache[key] = value; + this._stepCache[key]=value; + return this; } getStepCache(key){ - if(!this._stepCache)return undefined; + if(!this._stepCache) return undefined; return this._stepCache[key]; } clearStepCache(key){ - if(key !== undefined && key !== null){ + if(key!==undefined&&key!==null){ delete this._stepCache[key]; } delete this._stepCache; + return this; } callFuncUseStepCache(prefix,func,params){ - if(typeof func != 'function')return; - if(_status.closeStepCache)return func.apply(null,params); - var cacheKey = "["+prefix+"]"+get.paramToCacheKey.apply(null,params); - var ret = this.getStepCache(cacheKey); - if(ret === undefined || ret === null){ - ret = func.apply(null,params); + if(typeof func!='function') return; + if(_status.closeStepCache) return func.apply(null,params); + var cacheKey="["+prefix+"]"+get.paramToCacheKey.apply(null,params); + var ret=this.getStepCache(cacheKey); + if(ret===undefined||ret===null){ + ret=func.apply(null,params); this.putStepCache(cacheKey,ret); } return ret; } putTempCache(key1,key2,value){ if(!this._tempCache){ - this._tempCache = {}; + this._tempCache={}; } if(!this._tempCache[key1]){ - this._tempCache[key1] = {}; + this._tempCache[key1]={}; } - this._tempCache[key1][key2] = value; + this._tempCache[key1][key2]=value; return value; } getTempCache(key1,key2){ @@ -30409,7 +30413,9 @@ this.finish(); if(notrigger!='notrigger'){ this.trigger(this.name+'Cancelled'); - if(this.player&&lib.phaseName.contains(this.name)) this.player.getHistory('skipped').add(this.name)} + if(this.player&&lib.phaseName.contains(this.name)) this.player.getHistory('skipped').add(this.name); + } + return this; } neutralize(event){ this.untrigger(); @@ -30417,18 +30423,22 @@ this._neutralized=true; this.trigger('eventNeutralized'); this._neutralize_event=event||_status.event; + return this; } unneutralize(){ this.untrigger(); delete this._neutralized; delete this.finished; if(this.type=='card'&&this.card&&this.name=='sha') this.directHit=true; + return this; } goto(step){ this.step=step-1; + return this; } redo(){ this.step--; + return this; } setHiddenSkill(skill){ if(!this.player) return this; @@ -30500,11 +30510,13 @@ get.stringifiedResult(this.parent),get.skillState(this.player)); this.player.wait(); game.pause(); + return this; } resume(){ delete this._cardChoice; delete this._targetChoice; delete this._skillChoice; + return this; } getParent(level,forced){ var parent,historys=[]; @@ -30552,21 +30564,18 @@ if(!this._rand) this._rand=Math.random(); return this._rand; } - insert(func,map){ - var next=game.createEvent(this.name+'Inserted',false,this); - next.setContent(func); - for(var i in map){ - next.set(i,map[i]); - } + insert(content,map){ + const next=new lib.element.Event(`${this.name}Inserted`,false); + this.next.push(next); + next.setContent(content); + Object.entries(map).forEach(entry=>next.set(entry[0],entry[1])); return next; } - insertAfter(func,map){ - var next=game.createEvent(this.name+'Inserted',false,{next:[]}); + insertAfter(content,map){ + const next=new lib.element.Event(`${this.name}Inserted`,false); this.after.push(next); - next.setContent(func); - for(var i in map){ - next.set(i,map[i]); - } + next.setContent(content); + Object.entries(map).forEach(entry=>next.set(entry[0],entry[1])); return next; } backup(skill){ @@ -30690,6 +30699,7 @@ delete this._cardChoice; delete this._targetChoice; delete this._skillChoice; + return this; } restore(){ if(this._backup){ @@ -30716,6 +30726,7 @@ delete this.skill; delete this.ignoreMod; delete this.filterCard2; + return this; } isMine(){ return (this.player&&this.player==game.me&&!_status.auto&&!this.player.isMad()&&!game.notMe); @@ -30732,13 +30743,13 @@ return !player||player==evt.player; } addTrigger(skill,player){ - if(!player||!skill) return; + if(!player||!skill) return this; var evt=this; if(typeof skill=='string') skill=[skill]; game.expandSkills(skill); while(true){ var evt=evt.getParent('arrangeTrigger'); - if(!evt||evt.name!='arrangeTrigger'||!evt.map) return; + if(!evt||evt.name!='arrangeTrigger'||!evt.map) return this; var filter=function(content){ if(typeof content=='string') return content==triggername; return content.contains(triggername); @@ -30752,7 +30763,7 @@ if(evt.map[i].player==player){map=evt.map[i];break;} } } - if(!map) return; + if(!map) return this; var func=function(skillx){ var info=lib.skill[skillx]; var bool=false; @@ -30779,6 +30790,43 @@ func(skill[j]); } } + return this; + } + removeTrigger(skill,player){ + if(!player||!skill) return; + var evt=this; + if(typeof skill=='string') skill=[skill]; + game.expandSkills(skill); + while(true){ + var evt=evt.getParent('arrangeTrigger'); + if(!evt||evt.name!='arrangeTrigger'||!evt.map) return; + var filter=function(content){ + if(typeof content=='string') return content==triggername; + return content.contains(triggername); + }; + var trigger=evt._trigger; + var triggername=evt.triggername; + var map=false; + if(evt.doing&&evt.doing.player==player) map=evt.doing; + else{ + for(var i=0;i{ + return i[0]==skillx&&i[1]==player; + }); + if(toremove.length>0) map.list.removeArray(toremove); + } + for(var j=0;j{ const next=new lib.element.Event(name,trigger); (triggerEvent||_status.event).next.push(next); diff --git a/mode/connect.js b/mode/connect.js index 4ad1013f7..6e3f85950 100644 --- a/mode/connect.js +++ b/mode/connect.js @@ -35,21 +35,21 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ node.style.left='calc(50% - 210px)'; node.style.top='calc(50% - 20px)'; node.style.whiteSpace='nowrap'; - node.innerHTML=lib.config.last_ip||lib.hallURL; + node.textContent=lib.config.last_ip||lib.hallURL; node.contentEditable=true; node.style.webkitUserSelect='text'; node.style.textAlign='center'; node.style.overflow='hidden'; var connect=function(e){ - event.textnode.innerHTML='正在连接...'; + event.textnode.textContent='正在连接...'; clearTimeout(event.timeout); if(e) e.preventDefault(); - game.saveConfig('last_ip',node.innerHTML); - game.connect(node.innerHTML,function(success){ + game.saveConfig('last_ip',node.textContent=node.textContent); + game.connect(node.textContent,function(success){ if(!success&&event.textnode){ alert('连接失败'); - event.textnode.innerHTML='输入联机地址'; + event.textnode.textContent='输入联机地址'; } }); }; @@ -82,7 +82,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ ui.ipbutton=button; ui.hall_button=ui.create.system('联机大厅',function(){ - node.innerHTML=get.config('hall_ip')||lib.hallURL; + node.textContent=get.config('hall_ip')||lib.hallURL; connect(); },true); if(!get.config('hall_button')){ @@ -90,7 +90,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ } ui.recentIP=ui.create.system('最近连接',null,true); var clickLink=function(){ - node.innerHTML=this.innerHTML; + node.textContent=this.textContent; connect(); }; lib.setPopped(ui.recentIP,function(){ @@ -101,7 +101,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ }); var list=ui.create.div('.caption'); for(var i=0;i清除'); @@ -128,14 +128,14 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ } var n=5; var connect=function(){ - event.textnode.innerHTML='正在连接...'; + event.textnode.textContent='正在连接...'; game.connect(info[0],function(success){ if(!success&&n--){ createNode(); event.timeout=setTimeout(connect,1000); } else{ - event.textnode.innerHTML='输入联机地址'; + event.textnode.textContent='输入联机地址'; } }); }; @@ -153,13 +153,6 @@ game.import('mode',function(lib,game,ui,get,ai,_status){ } } _status.connectDenied=createNode; - for(var i in lib.element.event){ - event.parent[i]=lib.element.event[i]; - } - event.parent.custom={ - add:{}, - replace:{} - }; setTimeout(lib.init.onfree,1000); } };