puzzle racer WIP
parent
857f297b8d
commit
aafb7d4593
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -29,8 +29,9 @@ export interface ServerState {
|
|||
}
|
||||
|
||||
export interface Player {
|
||||
index: number;
|
||||
user?: LightUser;
|
||||
name: string;
|
||||
userId?: string;
|
||||
title?: string;
|
||||
moves: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue