puzzle racer WIP

puzzle-racer-road-translate
Thibault Duplessis 2021-03-05 09:55:21 +01:00
parent 857f297b8d
commit aafb7d4593
7 changed files with 1297 additions and 1257 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,6 @@ import play.api.libs.json._
import lila.common.Json._
import lila.common.LightUser
import lila.common.LightUser.lightUserWrites
import lila.storm
import lila.storm.StormJson
import lila.storm.StormPuzzle
import lila.storm.StormSign
@ -32,10 +30,12 @@ final class RacerJson(stormJson: StormJson, sign: StormSign, lightUserSync: Ligh
)
private def playersJson(race: RacerRace) = JsArray {
race.players.zipWithIndex.map { case (player, index) =>
race.players.map { case player =>
val user = player.userId flatMap lightUserSync
Json
.obj("index" -> (index + 1), "moves" -> player.moves)
.add("user" -> player.userId.flatMap(lightUserSync))
.obj("name" -> player.name, "moves" -> player.moves)
.add("userId" -> player.userId)
.add("title" -> user.map(_.title))
}
}
}

View File

@ -1,23 +1,29 @@
package lila.racer
import org.joda.time.DateTime
import lila.common.CuteNameGenerator
import lila.user.User
case class RacerPlayer(id: RacerPlayer.Id, createdAt: DateTime, moves: Int) {
import RacerPlayer.Id
def userId: Option[User.ID] = id match {
case Id.User(id) => id.some
case _ => none
lazy val userId: Option[User.ID] = id match {
case Id.User(name) => User.normalize(name).some
case _ => none
}
lazy val name: String = id match {
case Id.User(n) => n
case Id.Anon(id) => CuteNameGenerator fromSeed id.hashCode
}
}
object RacerPlayer {
sealed trait Id
object Id {
case class User(userId: lila.user.User.ID) extends Id
case class Anon(sessionId: String) extends Id
case class User(name: String) extends Id
case class Anon(sessionId: String) extends Id
def apply(str: String) =
if (str startsWith "@") Anon(str drop 1)
else User(str)

View File

@ -218,13 +218,16 @@ interface Study {
setTab(tab: string): void;
}
interface LightUser {
id: string;
interface LightUserNoId {
name: string;
title?: string;
patron?: boolean;
}
interface LightUser extends LightUserNoId {
id: string;
}
interface Navigator {
deviceMemory?: number; // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory
}

View File

@ -29,8 +29,9 @@ export interface ServerState {
}
export interface Player {
index: number;
user?: LightUser;
name: string;
userId?: string;
title?: string;
moves: number;
}

View File

@ -5,13 +5,19 @@ import { Player } from '../interfaces';
export const renderRace = (ctrl: RacerCtrl) => h('div.racer__race', ctrl.players().map(renderPlayer));
const renderPlayer = (player: Player) =>
const renderPlayer = (player: Player, index: number) =>
h('div.racer__race__player', [
h('div.racer__race__player__name', player.user ? userName(player.user) : ['Anon', ' ', player.index]),
h(`div.racer__race__player__car.car-${player.index}`, [player.moves]),
h('div.racer__race__player__name', playerLink(player)),
h(`div.racer__race__player__car.car-${index}`, [player.moves]),
]);
export const userName = (user: LightUser): Array<string | VNode> =>
user.title
? [h('span.utitle', user.title == 'BOT' ? { attrs: { 'data-bot': true } } : {}, user.title), ' ', user.name]
: [user.name];
export const playerLink = (player: Player) =>
player.userId
? h(
'a.user-link.ulpt',
{
attrs: { href: '/@/' + player.name },
},
player.title ? [h('span.utitle', player.title), player.name] : [player.name]
)
: h('anonymous', player.name);