coordinates working in and out the 2d and 3d boards + stuff!

pull/132/head
Thibault Duplessis 2014-10-12 13:28:42 +02:00
parent 25ac3fcaa5
commit e88c743224
14 changed files with 98 additions and 18 deletions

View File

@ -24,16 +24,25 @@
<h2>Show board highlights (last move and check)</h2> <h2>Show board highlights (last move and check)</h2>
@base.radios(form("highlight"), Seq(0 -> "No", 1 -> "Yes")) @base.radios(form("highlight"), Seq(0 -> "No", 1 -> "Yes"))
</li> </li>
<li>
<h2>Show board coordinates (A-H, 1-8)</h2>
@base.radios(form("coords"), Pref.Coords.choices)
</li>
<li> <li>
<h2>Show piece destinations (valid moves and premoves)</h2> <h2>Show piece destinations (valid moves and premoves)</h2>
@base.radios(form("destination"), Seq(0 -> "No", 1 -> "Yes")) @base.radios(form("destination"), Seq(0 -> "No", 1 -> "Yes"))
</li> </li>
</ul>
</fieldset>
<fieldset>
<legend>Chess clock</legend>
<ul>
<li> <li>
<h2>Show tenths of seconds on the clock</h2> <h2>Show tenths of seconds</h2>
@base.radios(form("clockTenths"), Seq(0 -> "Never", 1 -> "When time remaining < 10 seconds")) @base.radios(form("clockTenths"), Seq(0 -> "Never", 1 -> "When time remaining < 10 seconds"))
</li> </li>
<li> <li>
<h2>Show horizontal green bars on the clock</h2> <h2>Show horizontal green bars</h2>
@base.radios(form("clockBar"), Seq(0 -> "No", 1 -> "Yes")) @base.radios(form("clockBar"), Seq(0 -> "No", 1 -> "Yes"))
</li> </li>
</ul> </ul>

View File

@ -47,7 +47,8 @@ openGraph: Map[Symbol, String] = Map.empty)(body: Html)(implicit ctx: Context)
ctx.currentPieceSet3d, ctx.currentPieceSet3d,
ctx.pref.highlight ?? "highlight", ctx.pref.highlight ?? "highlight",
ctx.blindMode ?? "blind_mode", ctx.blindMode ?? "blind_mode",
if (ctx.is3d) "is3d" else "is2d").mkString(" ")" if (ctx.is3d) "is3d" else "is2d",
"coords_" + ctx.pref.coords).mkString(" ")"
data-piece-set="@ctx.currentPieceSet" data-piece-set="@ctx.currentPieceSet"
data-static-url="@staticUrl("")" data-static-url="@staticUrl("")"
data-sound-dir="@staticUrl("sound")" data-sound-dir="@staticUrl("sound")"

View File

@ -193,7 +193,7 @@ Each event has a version number `v`, a type `t` and data `d`.
"t": "premove", "t": "premove",
"d": null "d": null
}, { }, {
"v": 12, // game metadata has changed (could be rematch negociation, for instance) "v": 12, // game metadata has changed (could be rematch negotiation, for instance)
"t": "reloadTable", // fetch the game document for more info "t": "reloadTable", // fetch the game document for more info
"d": null "d": null
}, { }, {
@ -209,12 +209,12 @@ Each event has a version number `v`, a type `t` and data `d`.
{t: 'resign'} {t: 'resign'}
``` ```
## Rematch negociation ## Rematch negotiation
When the opponent proposes or declines a rematch, When the opponent proposes or declines a rematch,
a `reloadTable` event is sent to the client. a `reloadTable` event is sent to the client.
You should then fetch the game document to learn about You should then fetch the game document to learn about
the rematch negociation state, in `opponent.isOfferingRematch`. the rematch negotiation state, in `opponent.isOfferingRematch`.
### Propose or accept rematch ### Propose or accept rematch

View File

@ -16,6 +16,7 @@ private[pref] final class DataForm(api: PrefApi) {
"follow" -> number.verifying(Set(0, 1) contains _), "follow" -> number.verifying(Set(0, 1) contains _),
"highlight" -> number.verifying(Set(0, 1) contains _), "highlight" -> number.verifying(Set(0, 1) contains _),
"destination" -> number.verifying(Set(0, 1) contains _), "destination" -> number.verifying(Set(0, 1) contains _),
"coords" -> number.verifying(Pref.Coords.choices.toMap contains _),
"challenge" -> number.verifying(Pref.Challenge.choices.toMap contains _), "challenge" -> number.verifying(Pref.Challenge.choices.toMap contains _),
"premove" -> number.verifying(Set(0, 1) contains _), "premove" -> number.verifying(Set(0, 1) contains _),
"animation" -> number.verifying(Set(0, 1, 2, 3) contains _), "animation" -> number.verifying(Set(0, 1, 2, 3) contains _),
@ -31,6 +32,7 @@ private[pref] final class DataForm(api: PrefApi) {
follow: Int, follow: Int,
highlight: Int, highlight: Int,
destination: Int, destination: Int,
coords: Int,
challenge: Int, challenge: Int,
premove: Int, premove: Int,
animation: Int, animation: Int,
@ -45,6 +47,7 @@ private[pref] final class DataForm(api: PrefApi) {
follow = follow == 1, follow = follow == 1,
highlight = highlight == 1, highlight = highlight == 1,
destination = destination == 1, destination = destination == 1,
coords = coords,
challenge = challenge, challenge = challenge,
premove = premove == 1, premove = premove == 1,
animation = animation, animation = animation,
@ -62,6 +65,7 @@ private[pref] final class DataForm(api: PrefApi) {
follow = pref.follow.fold(1, 0), follow = pref.follow.fold(1, 0),
highlight = pref.highlight.fold(1, 0), highlight = pref.highlight.fold(1, 0),
destination = pref.destination.fold(1, 0), destination = pref.destination.fold(1, 0),
coords = pref.coords,
challenge = pref.challenge, challenge = pref.challenge,
premove = pref.premove.fold(1, 0), premove = pref.premove.fold(1, 0),
animation = pref.animation, animation = pref.animation,

View File

@ -25,6 +25,7 @@ case class Pref(
follow: Boolean, follow: Boolean,
highlight: Boolean, highlight: Boolean,
destination: Boolean, destination: Boolean,
coords: Int,
challenge: Int, challenge: Int,
coordColor: Int, coordColor: Int,
puzzleDifficulty: Int, puzzleDifficulty: Int,
@ -145,6 +146,17 @@ object Pref {
SLOW -> "Slow") SLOW -> "Slow")
} }
object Coords {
val NONE = 0
val INSIDE = 1
val OUTSIDE = 2
val choices = Seq(
NONE -> "Nope",
INSIDE -> "Inside the board",
OUTSIDE -> "Outside the board")
}
object Challenge { object Challenge {
val NEVER = 1 val NEVER = 1
val RATING = 2 val RATING = 2
@ -189,6 +201,7 @@ object Pref {
follow = true, follow = true,
highlight = true, highlight = true,
destination = true, destination = true,
coords = Coords.OUTSIDE,
challenge = Challenge.RATING, challenge = Challenge.RATING,
coordColor = Color.RANDOM, coordColor = Color.RANDOM,
puzzleDifficulty = Difficulty.NORMAL, puzzleDifficulty = Difficulty.NORMAL,

View File

@ -39,13 +39,36 @@ final class PrefApi(coll: Coll, cacheTtl: Duration) {
follow = r.getD("follow", Pref.default.follow), follow = r.getD("follow", Pref.default.follow),
highlight = r.getD("highlight", Pref.default.highlight), highlight = r.getD("highlight", Pref.default.highlight),
destination = r.getD("destination", Pref.default.destination), destination = r.getD("destination", Pref.default.destination),
coords = r.getD("coords", Pref.default.coords),
challenge = r.getD("challenge", Pref.default.challenge), challenge = r.getD("challenge", Pref.default.challenge),
coordColor = r.getD("coordColor", Pref.default.coordColor), coordColor = r.getD("coordColor", Pref.default.coordColor),
puzzleDifficulty = r.getD("puzzleDifficulty", Pref.default.puzzleDifficulty), puzzleDifficulty = r.getD("puzzleDifficulty", Pref.default.puzzleDifficulty),
tags = r.getD("tags", Pref.default.tags)) tags = r.getD("tags", Pref.default.tags))
private val writer = Macros.writer[Pref] def writes(w: BSON.Writer, o: Pref) = BSONDocument(
def writes(w: BSON.Writer, o: Pref) = writer write o "_id" -> o._id,
"dark" -> o.dark,
"is3d" -> o.is3d,
"theme" -> o.theme,
"pieceSet" -> o.pieceSet,
"theme3d" -> o.theme3d,
"pieceSet3d" -> o.pieceSet3d,
"autoQueen" -> o.autoQueen,
"autoThreefold" -> o.autoThreefold,
"takeback" -> o.takeback,
"clockTenths" -> o.clockTenths,
"clockBar" -> o.clockBar,
"premove" -> o.premove,
"animation" -> o.animation,
"captured" -> o.captured,
"follow" -> o.follow,
"highlight" -> o.highlight,
"destination" -> o.destination,
"coords" -> o.coords,
"challenge" -> o.challenge,
"coordColor" -> o.coordColor,
"puzzleDifficulty" -> o.puzzleDifficulty,
"tags" -> o.tags)
} }
def saveTag(user: User, name: String, value: String) = def saveTag(user: User, name: String, value: String) =

View File

@ -84,6 +84,7 @@ final class JsonView(
"animationDuration" -> animationDuration(pov, pref), "animationDuration" -> animationDuration(pov, pref),
"highlight" -> pref.highlight, "highlight" -> pref.highlight,
"destination" -> pref.destination, "destination" -> pref.destination,
"coords" -> pref.coords,
"autoQueen" -> pref.autoQueen, "autoQueen" -> pref.autoQueen,
"clockTenths" -> pref.clockTenths, "clockTenths" -> pref.clockTenths,
"clockBar" -> pref.clockBar, "clockBar" -> pref.clockBar,
@ -155,6 +156,7 @@ final class JsonView(
"pref" -> Json.obj( "pref" -> Json.obj(
"animationDelay" -> animationDuration(pov, pref), "animationDelay" -> animationDuration(pov, pref),
"highlight" -> pref.highlight, "highlight" -> pref.highlight,
"coords" -> pref.coords,
"clockTenths" -> pref.clockTenths, "clockTenths" -> pref.clockTenths,
"clockBar" -> pref.clockBar, "clockBar" -> pref.clockBar,
"showCaptured" -> pref.captured "showCaptured" -> pref.captured

View File

@ -9,6 +9,7 @@ function parseFen($elem) {
var color = $this.data('color'); var color = $this.data('color');
var ground = $this.data('chessground'); var ground = $this.data('chessground');
var config = { var config = {
coordinates: false,
viewOnly: true, viewOnly: true,
fen: $this.data('fen'), fen: $this.data('fen'),
lastMove: lm ? [lm[0] + lm[1], lm[2] + lm[3]] : [], lastMove: lm ? [lm[0] + lm[1], lm[2] + lm[3]] : [],

View File

@ -1106,13 +1106,13 @@ div.control .rematch.disabled {
} }
#claim_draw_zone, #claim_draw_zone,
div.force_resign_zone, div.force_resign_zone,
div.negociation { div.negotiation {
margin-top: 10px; margin-top: 10px;
padding-top: 10px; padding-top: 10px;
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
} }
#claim_draw_zone .button, #claim_draw_zone .button,
div.negociation .button, div.negotiation .button,
div.force_resign_zone .button { div.force_resign_zone .button {
display: inline-block; display: inline-block;
} }

View File

@ -41,8 +41,6 @@ body.is3d .cg-board {
position: absolute; position: absolute;
font-size: 11px; font-size: 11px;
line-height: 11px; line-height: 11px;
color: #fff;
text-shadow: 0 1px 2px #000;
opacity: 0.7; opacity: 0.7;
text-transform: uppercase; text-transform: uppercase;
} }
@ -56,6 +54,32 @@ body.is3d .cg-board {
right: 1px; right: 1px;
top: 1px; top: 1px;
} }
body.coords_1 .cg-square[data-coord-x]::after {
color: #fff;
text-shadow: 0 1px 2px #000;
}
body.coords_1 .cg-square[data-coord-y]::before {
color: #fff;
text-shadow: 0 1px 2px #000;
}
body.coords_2 .cg-square[data-coord-x]::after {
bottom: -11px;
left: 29px;
color: #bbb;
font-weight: bold;
}
body.coords_2.is3d .cg-square[data-coord-x]::after {
bottom: -22px;
}
body.coords_2 .cg-square[data-coord-y]::before {
right: -8px;
top: 26px;
color: #bbb;
font-weight: bold;
}
body.coords_2.is3d .cg-square[data-coord-y]::before {
top: 24px;
}
.cg-square.move-dest { .cg-square.move-dest {
background: radial-gradient(rgba(20, 85, 30, 0.3) 22%, #208530 0, rgba(0, 0, 0, 0.3) 0, rgba(0, 0, 0, 0) 0); background: radial-gradient(rgba(20, 85, 30, 0.3) 22%, #208530 0, rgba(0, 0, 0, 0.3) 0, rgba(0, 0, 0, 0) 0);
cursor: pointer; cursor: pointer;

View File

@ -125,7 +125,7 @@ body.dark #hooks_list .pool_buttons > a,
body.dark #hooks_list .pool_title, body.dark #hooks_list .pool_title,
body.dark div.training div.box, body.dark div.training div.box,
body.dark div.force_resign_zone, body.dark div.force_resign_zone,
body.dark div.negociation { body.dark div.negotiation {
border-color: #3d3d3d; border-color: #3d3d3d;
} }
body.dark #crosstable td.last { body.dark #crosstable td.last {
@ -163,6 +163,8 @@ body.dark #tv_history a.user_link,
body.dark #timeline a.user_link, body.dark #timeline a.user_link,
body.dark #team .forum a.user_link, body.dark #team .forum a.user_link,
body.dark span.board_mark, body.dark span.board_mark,
body.dark.coords_2 .cg-square[data-coord-x]::after,
body.dark.coords_2 .cg-square[data-coord-y]::before,
body.dark div.user_show div.content_box_top > span, body.dark div.user_show div.content_box_top > span,
body.dark span.progress > .zero, body.dark span.progress > .zero,
body.dark div.undertable_top span.title { body.dark div.undertable_top span.title {

View File

@ -30,7 +30,7 @@
"watchify": "^1.0.2" "watchify": "^1.0.2"
}, },
"dependencies": { "dependencies": {
"chessground": "^1.5.6", "chessground": "^1.5.7",
"lodash-node": "^2.4.1", "lodash-node": "^2.4.1",
"mithril": "^0.1.22" "mithril": "^0.1.22"
} }

View File

@ -9,6 +9,7 @@ function makeConfig(data, fen) {
turnColor: data.game.player, turnColor: data.game.player,
lastMove: util.str2move(data.game.lastMove), lastMove: util.str2move(data.game.lastMove),
check: data.game.check, check: data.game.check,
coordinates: data.pref.coords !== 0,
highlight: { highlight: {
lastMove: data.pref.highlight, lastMove: data.pref.highlight,
check: data.pref.highlight, check: data.pref.highlight,

View File

@ -152,13 +152,13 @@ function renderTablePlay(ctrl) {
onclick: partial(ctrl.socket.send, 'draw-claim', null) onclick: partial(ctrl.socket.send, 'draw-claim', null)
}, ctrl.trans('claimADraw')) }, ctrl.trans('claimADraw'))
]) : ( ]) : (
d.player.isOfferingDraw ? m('div.negociation', [ d.player.isOfferingDraw ? m('div.negotiation', [
ctrl.trans('drawOfferSent') + ' ', ctrl.trans('drawOfferSent') + ' ',
m('a', { m('a', {
onclick: partial(ctrl.socket.send, 'draw-no', null) onclick: partial(ctrl.socket.send, 'draw-no', null)
}, ctrl.trans('cancel')) }, ctrl.trans('cancel'))
]) : null, ]) : null,
d.opponent.isOfferingDraw ? m('div.negociation', [ d.opponent.isOfferingDraw ? m('div.negotiation', [
ctrl.trans('yourOpponentOffersADraw'), ctrl.trans('yourOpponentOffersADraw'),
m('br'), m('br'),
m('a.button[data-icon=E]', { m('a.button[data-icon=E]', {
@ -170,13 +170,13 @@ function renderTablePlay(ctrl) {
}, ctrl.trans('decline')), }, ctrl.trans('decline')),
]) : null ]) : null
), ),
d.player.isProposingTakeback ? m('div.negociation', [ d.player.isProposingTakeback ? m('div.negotiation', [
ctrl.trans('takebackPropositionSent') + ' ', ctrl.trans('takebackPropositionSent') + ' ',
m('a', { m('a', {
onclick: partial(ctrl.socket.send, 'takeback-no', null) onclick: partial(ctrl.socket.send, 'takeback-no', null)
}, ctrl.trans('cancel')) }, ctrl.trans('cancel'))
]) : null, ]) : null,
d.opponent.isProposingTakeback ? m('div.negociation', [ d.opponent.isProposingTakeback ? m('div.negotiation', [
ctrl.trans('yourOpponentProposesATakeback'), ctrl.trans('yourOpponentProposesATakeback'),
m('br'), m('br'),
m('a.button[data-icon=E]', { m('a.button[data-icon=E]', {