checkHistory
This commit is contained in:
parent
7273418d0b
commit
c1941a7531
133
game/game.js
133
game/game.js
|
@ -22316,7 +22316,7 @@
|
||||||
if(!position) position=ui.discardPile;
|
if(!position) position=ui.discardPile;
|
||||||
if(!key) key='cards';
|
if(!key) key='cards';
|
||||||
var cards=[],event=this;
|
var cards=[],event=this;
|
||||||
game.getGlobalHistory('cardMove',function(evt){
|
game.checkGlobalHistory('cardMove',function(evt){
|
||||||
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
||||||
if(player&&player!=evt.player) return;
|
if(player&&player!=evt.player) return;
|
||||||
cards.addArray(evt[key]);
|
cards.addArray(evt[key]);
|
||||||
|
@ -22335,7 +22335,7 @@
|
||||||
cards:[],
|
cards:[],
|
||||||
cards2:[],
|
cards2:[],
|
||||||
};
|
};
|
||||||
player.getHistory('lose',function(evt){
|
player.checkHistory('lose',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
map.hs.addArray(evt.hs);
|
map.hs.addArray(evt.hs);
|
||||||
map.es.addArray(evt.es);
|
map.es.addArray(evt.es);
|
||||||
|
@ -22398,7 +22398,7 @@
|
||||||
if(!position) position=ui.discardPile;
|
if(!position) position=ui.discardPile;
|
||||||
if(!key) key='cards';
|
if(!key) key='cards';
|
||||||
var cards=[],event=this;
|
var cards=[],event=this;
|
||||||
game.getGlobalHistory('cardMove',function(evt){
|
game.checkGlobalHistory('cardMove',function(evt){
|
||||||
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
||||||
if(player&&player!=evt.player) return;
|
if(player&&player!=evt.player) return;
|
||||||
cards.addArray(evt[key]);
|
cards.addArray(evt[key]);
|
||||||
|
@ -22417,7 +22417,7 @@
|
||||||
cards:[],
|
cards:[],
|
||||||
cards2:[],
|
cards2:[],
|
||||||
};
|
};
|
||||||
player.getHistory('lose',function(evt){
|
player.checkHistory('lose',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
map.hs.addArray(evt.hs);
|
map.hs.addArray(evt.hs);
|
||||||
map.es.addArray(evt.es);
|
map.es.addArray(evt.es);
|
||||||
|
@ -22881,7 +22881,7 @@
|
||||||
if(!position) position=ui.discardPile;
|
if(!position) position=ui.discardPile;
|
||||||
if(!key) key='cards';
|
if(!key) key='cards';
|
||||||
var cards=[],event=this;
|
var cards=[],event=this;
|
||||||
game.getGlobalHistory('cardMove',function(evt){
|
game.checkGlobalHistory('cardMove',function(evt){
|
||||||
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
||||||
if(player&&player!=evt.player) return;
|
if(player&&player!=evt.player) return;
|
||||||
cards.addArray(evt[key]);
|
cards.addArray(evt[key]);
|
||||||
|
@ -22900,7 +22900,7 @@
|
||||||
cards:[],
|
cards:[],
|
||||||
cards2:[],
|
cards2:[],
|
||||||
};
|
};
|
||||||
player.getHistory('lose',function(evt){
|
player.checkHistory('lose',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
map.hs.addArray(evt.hs);
|
map.hs.addArray(evt.hs);
|
||||||
map.es.addArray(evt.es);
|
map.es.addArray(evt.es);
|
||||||
|
@ -22935,7 +22935,7 @@
|
||||||
if(!position) position=ui.discardPile;
|
if(!position) position=ui.discardPile;
|
||||||
if(!key) key='cards';
|
if(!key) key='cards';
|
||||||
var cards=[],event=this;
|
var cards=[],event=this;
|
||||||
game.getGlobalHistory('cardMove',function(evt){
|
game.checkGlobalHistory('cardMove',function(evt){
|
||||||
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
||||||
if(player&&player!=evt.player) return;
|
if(player&&player!=evt.player) return;
|
||||||
cards.addArray(evt[key]);
|
cards.addArray(evt[key]);
|
||||||
|
@ -22954,7 +22954,7 @@
|
||||||
cards:[],
|
cards:[],
|
||||||
cards2:[],
|
cards2:[],
|
||||||
};
|
};
|
||||||
player.getHistory('lose',function(evt){
|
player.checkHistory('lose',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
map.hs.addArray(evt.hs);
|
map.hs.addArray(evt.hs);
|
||||||
map.es.addArray(evt.es);
|
map.es.addArray(evt.es);
|
||||||
|
@ -24521,7 +24521,7 @@
|
||||||
const history=this.getHistory(key);
|
const history=this.getHistory(key);
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
return history.filter(function(event,index){
|
return history.filter((event,index)=>{
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
return filter(event);
|
return filter(event);
|
||||||
})
|
})
|
||||||
|
@ -24529,11 +24529,27 @@
|
||||||
return history.filter(filter);
|
return history.filter(filter);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
checkHistory:function(key,filter,last){
|
||||||
|
if(!key||!filter) return;
|
||||||
|
else{
|
||||||
|
const history=this.getHistory(key);
|
||||||
|
if(last){
|
||||||
|
const lastIndex=history.indexOf(last);
|
||||||
|
history.forEach((event,index)=>{
|
||||||
|
if(index>lastIndex) return false;
|
||||||
|
filter(event);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
history.forEach(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
hasHistory:function(key,filter,last){
|
hasHistory:function(key,filter,last){
|
||||||
const history=this.getHistory(key);
|
const history=this.getHistory(key);
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
return history.some(function(event,index){
|
return history.some((event,index)=>{
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
return filter(event);
|
return filter(event);
|
||||||
})
|
})
|
||||||
|
@ -24553,7 +24569,7 @@
|
||||||
else{
|
else{
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
return history.filter(function(event,index){
|
return history.filter((event,index)=>{
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
return filter(event);
|
return filter(event);
|
||||||
})
|
})
|
||||||
|
@ -24561,21 +24577,36 @@
|
||||||
return history.filter(filter);
|
return history.filter(filter);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getAllHistory:function(key,filter,last){
|
checkAllHistory:function(key,filter,last){
|
||||||
const history=[];
|
if(!key||!filter) return;
|
||||||
const all=this.actionHistory;
|
this.actionHistory.forEach((value)=>{
|
||||||
for(let j=0;j<all.length;j++){
|
let history=value[key];
|
||||||
if(!key||!all[j][key]){
|
if(last&&history.includes(last)){
|
||||||
history.push(all[j]);
|
const lastIndex=history.indexOf(last);
|
||||||
|
history.forEach((event,index)=>{
|
||||||
|
if(index>lastIndex) return false;
|
||||||
|
return filter(event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
history.push(...all[j][key]);
|
history.forEach(filter);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getAllHistory:function(key,filter,last){
|
||||||
|
const history=[];
|
||||||
|
this.actionHistory.forEach((value)=>{
|
||||||
|
if(!key||!value[key]){
|
||||||
|
history.push(value);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
history.push(...value[key]);
|
||||||
|
}
|
||||||
|
})
|
||||||
if(filter){
|
if(filter){
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
return history.filter(function(event,index){
|
return history.filter((event,index)=>{
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
return filter(event);
|
return filter(event);
|
||||||
});
|
});
|
||||||
|
@ -24585,10 +24616,9 @@
|
||||||
return history;
|
return history;
|
||||||
},
|
},
|
||||||
hasAllHistory:function(key,filter,last){
|
hasAllHistory:function(key,filter,last){
|
||||||
const all=this.actionHistory;
|
return this.actionHistory.some((value)=>{
|
||||||
for(let j=0;j<all.length;j++){
|
let history=value[key];
|
||||||
let history=all[j][key];
|
if(last&&history.includes(last)){
|
||||||
if(last){
|
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
if(history.some(function(event,index){
|
if(history.some(function(event,index){
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
|
@ -24598,8 +24628,8 @@
|
||||||
else{
|
else{
|
||||||
if(history.some(filter)) return true;
|
if(history.some(filter)) return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
})
|
||||||
},
|
},
|
||||||
getLastUsed:function(num){
|
getLastUsed:function(num){
|
||||||
if(typeof num!='number') num=0;
|
if(typeof num!='number') num=0;
|
||||||
|
@ -31293,7 +31323,7 @@
|
||||||
if(!position) position=ui.discardPile;
|
if(!position) position=ui.discardPile;
|
||||||
if(!key) key='cards';
|
if(!key) key='cards';
|
||||||
var cards=[],event=this;
|
var cards=[],event=this;
|
||||||
game.getGlobalHistory('cardMove',function(evt){
|
game.checkGlobalHistory('cardMove',function(evt){
|
||||||
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
if(evt.name!='lose'||evt.position!=position||evt.getParent()!=event) return;
|
||||||
if(player&&player!=evt.player) return;
|
if(player&&player!=evt.player) return;
|
||||||
cards.addArray(evt[key]);
|
cards.addArray(evt[key]);
|
||||||
|
@ -31312,7 +31342,7 @@
|
||||||
cards:[],
|
cards:[],
|
||||||
cards2:[],
|
cards2:[],
|
||||||
};
|
};
|
||||||
player.getHistory('lose',function(evt){
|
player.checkHistory('lose',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
map.hs.addArray(evt.hs);
|
map.hs.addArray(evt.hs);
|
||||||
map.es.addArray(evt.es);
|
map.es.addArray(evt.es);
|
||||||
|
@ -31328,7 +31358,7 @@
|
||||||
next.getg=function(player){
|
next.getg=function(player){
|
||||||
var that=this;
|
var that=this;
|
||||||
var cards=[];
|
var cards=[];
|
||||||
player.getHistory('gain',function(evt){
|
player.checkHistory('gain',function(evt){
|
||||||
if(evt.parent==that){
|
if(evt.parent==that){
|
||||||
cards.addArray(evt.cards);
|
cards.addArray(evt.cards);
|
||||||
}
|
}
|
||||||
|
@ -31348,6 +31378,23 @@
|
||||||
if(get.mode()!='chess'&&rank.junk.contains(name)) return 'junk';
|
if(get.mode()!='chess'&&rank.junk.contains(name)) return 'junk';
|
||||||
return 'common';
|
return 'common';
|
||||||
},
|
},
|
||||||
|
checkGlobalHistory:function(key,filter,last){
|
||||||
|
if(!key) return _status.globalHistory[_status.globalHistory.length-1];
|
||||||
|
if(!filter) return _status.globalHistory[_status.globalHistory.length-1][key];
|
||||||
|
else{
|
||||||
|
const history=game.getGlobalHistory(key);
|
||||||
|
if(last){
|
||||||
|
const lastIndex=history.indexOf(last);
|
||||||
|
history.forEach((event,index)=>{
|
||||||
|
if(index>lastIndex) return false;
|
||||||
|
return filter(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
history.forEach(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
getGlobalHistory:function(key,filter,last){
|
getGlobalHistory:function(key,filter,last){
|
||||||
if(!key) return _status.globalHistory[_status.globalHistory.length-1];
|
if(!key) return _status.globalHistory[_status.globalHistory.length-1];
|
||||||
if(!filter) return _status.globalHistory[_status.globalHistory.length-1][key];
|
if(!filter) return _status.globalHistory[_status.globalHistory.length-1][key];
|
||||||
|
@ -31355,7 +31402,7 @@
|
||||||
const history=game.getGlobalHistory(key);
|
const history=game.getGlobalHistory(key);
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
return history.filter(function(event,index){
|
return history.filter((event,index)=>{
|
||||||
if(index>lastIndex) return false;
|
if(index>lastIndex) return false;
|
||||||
return filter(event);
|
return filter(event);
|
||||||
})
|
})
|
||||||
|
@ -31363,17 +31410,33 @@
|
||||||
return history.filter(filter);
|
return history.filter(filter);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getAllGlobalHistory:function(key,filter,last){
|
checkAllGlobalHistory:function(key,filter,last){
|
||||||
const history=[];
|
if(!key||!filter) return;
|
||||||
const all=_status.globalHistory;
|
_status.globalHistory.forEach(value=>{
|
||||||
for(var j=0;j<all.length;j++){
|
if(value[key]){
|
||||||
if(!key||!all[j][key]){
|
if(last&&value[key].includes(last)){
|
||||||
history.push(all[j]);
|
const lastIndex=value[key].indexOf(last);
|
||||||
|
value[key].filter((event,index)=>{
|
||||||
|
if(index>lastIndex) return false;
|
||||||
|
return filter(event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
list.push(...all[j][key]);
|
value[key].forEach(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getAllGlobalHistory:function(key,filter,last){
|
||||||
|
const history=[];
|
||||||
|
_status.globalHistory.forEach(value=>{
|
||||||
|
if(!key||!value[key]){
|
||||||
|
history.push(value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
history.push(...value[key]);
|
||||||
|
}
|
||||||
|
})
|
||||||
if(filter){
|
if(filter){
|
||||||
if(last){
|
if(last){
|
||||||
const lastIndex=history.indexOf(last);
|
const lastIndex=history.indexOf(last);
|
||||||
|
|
Loading…
Reference in New Issue