concede game round

This commit is contained in:
ntr
2019-11-20 12:39:09 +11:00
parent 40ca99d185
commit 8e6561499a
5 changed files with 58 additions and 4 deletions
+19 -1
View File
@@ -20,12 +20,17 @@ const addState = connect(
return ws.sendGameOfferDraw(game.id);
}
function sendConcede() {
return ws.sendGameConcede(game.id);
}
return {
game,
account,
sendAbandon,
sendDraw,
sendConcede,
animating,
};
},
@@ -49,11 +54,12 @@ function GameCtrlTopBtns(args) {
leave,
sendAbandon,
sendDraw,
sendConcede,
animating,
} = args;
const finished = game && game.phase === 'Finished';
const { abandonState, drawState } = this.state;
const { abandonState, drawState, concedeState } = this.state;
const player = game.players.find(p => p.id === account.id);
const drawOffered = player && player.draw_offered;
@@ -70,6 +76,12 @@ function GameCtrlTopBtns(args) {
setTimeout(() => this.setState({ drawState: false }), 2000);
};
const concedeStateTrue = e => {
e.stopPropagation();
this.setState({ concedeState: true });
setTimeout(() => this.setState({ concedeState: false }), 2000);
};
const abandonClasses = `abandon ${abandonState ? 'confirming' : ''}`;
const abandonText = abandonState ? 'Confirm' : 'Abandon';
const abandonAction = abandonState ? sendAbandon : abandonStateTrue;
@@ -83,9 +95,15 @@ function GameCtrlTopBtns(args) {
const drawAction = drawState ? sendDraw : drawStateTrue;
const drawBtn = <button class={drawClasses} disabled={finished || animating || drawOffered} onClick={drawAction}>{drawText}</button>;
const concedeClasses = `draw ${concedeState ? 'confirming' : ''}`;
const concedeText = concedeState ? 'Round' : 'Concede';
const concedeAction = concedeState ? sendConcede : concedeStateTrue;
const concedeBtn = <button class={concedeClasses} disabled={finished || animating } onClick={concedeAction}>{concedeText}</button>;
return (
<div class="instance-ctrl-btns">
{abandonBtn}
{concedeBtn}
{drawBtn}
</div>
);
+6
View File
@@ -138,6 +138,11 @@ function createSocket(events) {
events.setActiveSkill(null);
}
function sendGameConcede(gameId) {
send(['GameConcede', { game_id: gameId }]);
events.setActiveSkill(null);
}
function sendGameTarget(gameId, constructId, skillId) {
send(['GameTarget', { game_id: gameId, construct_id: constructId, skill_id: skillId }]);
events.setActiveSkill(null);
@@ -391,6 +396,7 @@ function createSocket(events) {
sendGameSkill,
sendGameSkillClear,
sendGameOfferDraw,
sendGameConcede,
sendGameTarget,
sendInstanceAbandon,