Commit 8e309527 authored by Stuart John Watson's avatar Stuart John Watson

Added server handling newGoal.

(works towards issue #2)
parent ce03aec6
Pipeline #181 skipped
......@@ -67,24 +67,44 @@ handlers.drawCards = function(data){
}
};
//DEMO
function setGoal(id,card){
document.querySelectorAll("#demo-goals div")[id].innerHTML = !card ? "None":"<strong>"+card.name+" ("+card.score+")</strong></br>"+card.condition;
goals[id] = card;
}
handlers.gridState = function(data){
data.grid.forEach(function(n){
game.grid.addCard(n.position,n.id);
});
data.goals.forEach(function(n) {
var card = game.cardList[n.id];
goals[n.position] = card;
document.querySelectorAll("#demo-goals div")[n.position].innerHTML = "<strong>"+card.name+" ("+card.score+")</strong></br>"+card.condition;
setGoal(n.position,card);
});
game.render();
};
handlers.playCards = function(data){
data.cards.forEach(function(n){
if(n.position === null){
game.grid.removeCard(n.id);
var card = game.cardList[n.id],
pos = n.position;
if (card instanceof GoalCard){
if(pos === null){
var rId = goals.indexOf(card);
if(rId < 0){
console.warning("Removing goal not in goal list");
} else {
setGoal(rId,null);
}
} else {
setGoal(pos,card);
}
} else {
game.grid.addCard(n.position,n.id);
if(pos === null){
game.grid.removeCard(card);
} else {
game.grid.addCard(pos,card);
}
}
});
game.render();
......
......@@ -127,7 +127,7 @@ Game.prototype.effects = {
var goalCard = this.decks.resolveCardish(params.shift()),
rId = this.currentGoals.indexOf(goalCard),
newGoal = this.decks.drawGoals(1)[0];
this.currentGoals = this.currentGoals.splice(rId,1,newGoal);
this.currentGoals[rId] = newGoal;
return [{id:goalCard.id,position:null},{id:newGoal.id,position:rId}];
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment