Make sure game states are rendered sequentially to fix race condition bug caused by playing a very fast opponent (like the bot Hannah)
This commit is contained in:
parent
d2b8c2ee47
commit
bcaa606021
1 changed files with 15 additions and 11 deletions
26
www/game.js
26
www/game.js
|
@ -11,16 +11,6 @@ function Game(modules) {
|
|||
var selected = null;
|
||||
var queue = [];
|
||||
|
||||
window.addEventListener('focus', runQueue);
|
||||
modules.messaging.addEventListener(["Game"], function(o) {
|
||||
if(document.hasFocus()) {
|
||||
modules.async.run(handleGameMessage(o));
|
||||
} else {
|
||||
modules.statusHandler.set("♪");
|
||||
queue.push(handleGameMessage(o));
|
||||
}
|
||||
});
|
||||
|
||||
function buildSets() {
|
||||
var sets = {};
|
||||
['river', 'you', 'them'].forEach(function(id) {
|
||||
|
@ -39,10 +29,24 @@ function Game(modules) {
|
|||
return sets;
|
||||
}
|
||||
|
||||
window.addEventListener('focus', runQueue);
|
||||
modules.messaging.addEventListener(["Game"], function(o) {
|
||||
queue.push(handleGameMessage(o));
|
||||
if(document.hasFocus() && queue.length == 1) {
|
||||
runQueue();
|
||||
} else {
|
||||
modules.statusHandler.set("♪");
|
||||
}
|
||||
});
|
||||
|
||||
function runQueue() {
|
||||
if(queue.length > 0) {
|
||||
var length = queue.length;
|
||||
modules.async.run.apply(null, queue.concat(
|
||||
modules.async.apply(function() {queue = [];})
|
||||
modules.async.apply(function() {
|
||||
queue = queue.slice(length);
|
||||
runQueue();
|
||||
})
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue