projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Draft of a problems section + news system
[vchess.git]
/
client
/
src
/
views
/
Game.vue
diff --git
a/client/src/views/Game.vue
b/client/src/views/Game.vue
index
a61655a
..
1b82d81
100644
(file)
--- a/
client/src/views/Game.vue
+++ b/
client/src/views/Game.vue
@@
-1,7
+1,7
@@
<template lang="pug">
main
<template lang="pug">
main
- input#modalChat.modal(type="checkbox" @click="resetChatColor")
- div#chatWrap(role="dialog" data-checkbox="modalChat"
aria-labelledby="inputChat"
)
+ input#modalChat.modal(type="checkbox" @click="resetChatColor
()
")
+ div#chatWrap(role="dialog" data-checkbox="modalChat")
#chat.card
label.modal-close(for="modalChat")
#participants
#chat.card
label.modal-close(for="modalChat")
#participants
@@
-17,10
+17,10
@@
main
span.variant-info {{ game.vname }}
button#chatBtn(onClick="doClick('modalChat')") Chat
#actions(v-if="game.score=='*'")
span.variant-info {{ game.vname }}
button#chatBtn(onClick="doClick('modalChat')") Chat
#actions(v-if="game.score=='*'")
- button(@click="clickDraw" :class="{['draw-' + drawOffer]: true}")
+ button(@click="clickDraw
()
" :class="{['draw-' + drawOffer]: true}")
| {{ st.tr["Draw"] }}
| {{ st.tr["Draw"] }}
- button(v-if="!!game.mycolor" @click="abortGame") {{ st.tr["Abort"] }}
- button(v-if="!!game.mycolor" @click="resign") {{ st.tr["Resign"] }}
+ button(v-if="!!game.mycolor" @click="abortGame
()
") {{ st.tr["Abort"] }}
+ button(v-if="!!game.mycolor" @click="resign
()
") {{ st.tr["Resign"] }}
#playersInfo
p
span.name(:class="{connected: isConnected(0)}")
#playersInfo
p
span.name(:class="{connected: isConnected(0)}")
@@
-30,8
+30,7
@@
main
span.name(:class="{connected: isConnected(1)}")
| {{ game.players[1].name || "@nonymous" }}
span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
span.name(:class="{connected: isConnected(1)}")
| {{ game.players[1].name || "@nonymous" }}
span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
- BaseGame(:game="game" :vr="vr" ref="basegame"
- @newmove="processMove" @gameover="gameOver")
+ BaseGame(:game="game" :vr="vr" @newmove="processMove" @gameover="gameOver")
</template>
<script>
</template>
<script>
@@
-62,6
+61,7
@@
export default {
},
game: { //passed to BaseGame
players:[{name:""},{name:""}],
},
game: { //passed to BaseGame
players:[{name:""},{name:""}],
+ chats: [],
rendered: false,
},
virtualClocks: [0, 0], //initialized with true game.clocks
rendered: false,
},
virtualClocks: [0, 0], //initialized with true game.clocks
@@
-133,7
+133,11
@@
export default {
if (!!this.conn && this.conn.readyState == 1) //1 == OPEN state
callback();
else //socket not ready yet (initial loading)
if (!!this.conn && this.conn.readyState == 1) //1 == OPEN state
callback();
else //socket not ready yet (initial loading)
- this.conn.onopen = callback;
+ {
+ // NOTE: it's important to call callback without arguments,
+ // otherwise first arg is Websocket object and loadGame fails.
+ this.conn.onopen = () => { return callback() };
+ }
};
if (!this.gameRef.rid) //game stored locally or on server
this.loadGame(null, () => socketInit(this.roomInit));
};
if (!this.gameRef.rid) //game stored locally or on server
this.loadGame(null, () => socketInit(this.roomInit));
@@
-419,6
+423,8
@@
export default {
this.vr = new V(game.fen);
const gtype = (game.cadence.indexOf('d') >= 0 ? "corr" : "live");
const tc = extractTime(game.cadence);
this.vr = new V(game.fen);
const gtype = (game.cadence.indexOf('d') >= 0 ? "corr" : "live");
const tc = extractTime(game.cadence);
+ if (!game.chats)
+ game.chats = []; //live games don't have chat history
if (gtype == "corr")
{
if (game.players[0].color == "b")
if (gtype == "corr")
{
if (game.players[0].color == "b")
@@
-537,7
+543,8
@@
export default {
});
if (this.repeat[repIdx] >= 3)
this.drawOffer = "threerep";
});
if (this.repeat[repIdx] >= 3)
this.drawOffer = "threerep";
- callback();
+ if (!!callback)
+ callback();
};
if (!!game)
return afterRetrieval(game);
};
if (!!game)
return afterRetrieval(game);
@@
-552,8
+559,13
@@
export default {
GameStorage.get(this.gameRef.id, afterRetrieval);
}
},
GameStorage.get(this.gameRef.id, afterRetrieval);
}
},
- // Post-process a move (which was just played)
+ // Post-process a move (which was just played
in BaseGame
)
processMove: function(move) {
processMove: function(move) {
+ if (this.game.type == "corr" && move.color == this.game.mycolor)
+ {
+ if (!confirm(this.st.tr["Are you sure?"]))
+ return this.$set(this.game, "moveToUndo", move);
+ }
// Update storage (corr or live) if I play in the game
const colorIdx = ["w","b"].indexOf(move.color);
const nextIdx = ["w","b"].indexOf(this.vr.turn);
// Update storage (corr or live) if I play in the game
const colorIdx = ["w","b"].indexOf(move.color);
const nextIdx = ["w","b"].indexOf(this.vr.turn);
@@
-678,6
+690,8
@@
export default {
{
GameStorage.update(this.gameRef.id,
{score: score, scoreMsg: scoreMsg});
{
GameStorage.update(this.gameRef.id,
{score: score, scoreMsg: scoreMsg});
+ // Notify the score to main Hall. TODO: only one player (currently double send)
+ this.send("result", {gid:this.game.id, score:score});
}
},
},
}
},
},
@@
-735,7
+749,7
@@
export default {
#chat
padding-top: 20px
#chat
padding-top: 20px
- max-width:
600
px
+ max-width:
767
px
border: none;
#chatBtn
border: none;
#chatBtn