notify takeback state change with websocket messages - maybe fixes #418

pull/437/head
Thibault Duplessis 2015-04-21 21:21:26 +02:00
parent 610737d2a2
commit d874587e0b
3 changed files with 18 additions and 3 deletions

View File

@ -196,6 +196,16 @@ object Event {
).noNull
}
case class TakebackOffers(
white: Boolean,
black: Boolean) extends Event {
def typ = "takebackOffers"
def data = Json.obj(
"white" -> white.option(true),
"black" -> black.option(true)
).noNull
}
case class Crowd(
white: Boolean,
black: Boolean,

View File

@ -19,7 +19,7 @@ private[round] final class Takebacker(
val progress = Progress(game) map { g =>
g.updatePlayer(color, _ proposeTakeback g.turns)
}
GameRepo save progress inject List(Event.ReloadOwner)
GameRepo save progress inject List(Event.TakebackOffers(color.white, color.black))
case _ => ClientErrorException.future("[takebacker] invalid yes " + pov)
}
}
@ -29,11 +29,11 @@ private[round] final class Takebacker(
case Pov(game, color) if pov.player.isProposingTakeback => GameRepo save {
messenger.system(game, _.takebackPropositionCanceled)
Progress(game) map { g => g.updatePlayer(color, _.removeTakebackProposition) }
} inject List(Event.ReloadOwner)
} inject List(Event.TakebackOffers(false, false))
case Pov(game, color) if pov.opponent.isProposingTakeback => GameRepo save {
messenger.system(game, _.takebackPropositionDeclined)
Progress(game) map { g => g.updatePlayer(!color, _.removeTakebackProposition) }
} inject List(Event.ReloadOwner)
} inject List(Event.TakebackOffers(false, false))
case _ => ClientErrorException.future("[takebacker] invalid no " + pov)
}
}

View File

@ -29,6 +29,11 @@ module.exports = function(send, ctrl) {
m.redraw();
ctrl.setTitle();
},
takebackOffers: function(o) {
ctrl.data.player.proposingTakeback = o[ctrl.data.player.color];
ctrl.data.opponent.proposingTakeback = o[ctrl.data.opponent.color];
m.redraw();
},
move: function(o) {
ctrl.apiMove(o);
},