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 selected = null;
|
||||||
var queue = [];
|
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() {
|
function buildSets() {
|
||||||
var sets = {};
|
var sets = {};
|
||||||
['river', 'you', 'them'].forEach(function(id) {
|
['river', 'you', 'them'].forEach(function(id) {
|
||||||
|
@ -39,10 +29,24 @@ function Game(modules) {
|
||||||
return sets;
|
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() {
|
function runQueue() {
|
||||||
if(queue.length > 0) {
|
if(queue.length > 0) {
|
||||||
|
var length = queue.length;
|
||||||
modules.async.run.apply(null, queue.concat(
|
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