fix lobby hook/seek icons and update json

pull/9189/head
Thibault Duplessis 2021-06-15 16:02:41 +02:00
parent b10cf27bbf
commit 7b1c70e355
9 changed files with 54 additions and 42 deletions

View File

@ -16,12 +16,11 @@ final class LobbyApi(
(ctx.me ?? gameProxyRepo.urgentGames).mon(_.lobby segment "urgentGames") flatMap { case (seeks, povs) =>
val displayedPovs = povs take 9
lightUserApi.preloadMany(displayedPovs.flatMap(_.opponent.userId)) inject {
implicit val lang = ctx.lang
Json.obj(
"me" -> ctx.me.map { u =>
Json.obj("username" -> u.username).add("isBot" -> u.isBot)
},
"seeks" -> JsArray(seeks map (_.render)),
"seeks" -> JsArray(seeks.map(_.render)),
"nowPlaying" -> JsArray(displayedPovs map nowPlaying),
"nbNowPlaying" -> povs.size
) -> displayedPovs

View File

@ -60,7 +60,7 @@ case class Hook(
lazy val perf: Option[LobbyPerf] = for { u <- user; pt <- perfType } yield u perfAt pt
def rating: Option[Int] = perf.map(_.rating)
def render(implicit lang: Lang): JsObject =
def render: JsObject =
Json
.obj(
"id" -> id,
@ -76,7 +76,7 @@ case class Hook(
.add("variant" -> realVariant.exotic.option(realVariant.key))
.add("ra" -> realMode.rated.option(1))
.add("c" -> chess.Color.fromName(color).map(_.name))
.add("perf" -> perfType.map(_.trans))
.add("perf" -> perfType.map(_.key))
def randomColor = color == "random"

View File

@ -71,7 +71,7 @@ final class LobbySocket(
hookSubscriberSris diff idleSris withFilter { sri =>
members get sri exists { biter.showHookTo(hook, _) }
} map Sri.apply,
makeMessage("had", hook.render(defaultLang))
makeMessage("had", hook.render)
)
)
@ -108,7 +108,7 @@ final class LobbySocket(
case HookSub(member, false) => hookSubscriberSris -= member.sri.value
case AllHooksFor(member, hooks) =>
send(
P.Out.tellSri(member.sri, makeMessage("hooks", JsArray(hooks.map(_.render(defaultLang)))))
P.Out.tellSri(member.sri, makeMessage("hooks", hooks.map(_.render)))
)
hookSubscriberSris += member.sri.value
}

View File

@ -48,26 +48,20 @@ case class Seek(
def rating = perf.map(_.rating)
def render(implicit lang: Lang): JsObject =
def render: JsObject =
Json
.obj(
"id" -> _id,
"username" -> user.username,
"rating" -> rating,
"variant" -> Json.obj(
"key" -> realVariant.key,
"short" -> realVariant.shortName,
"name" -> realVariant.name
),
"mode" -> realMode.id,
"days" -> daysPerTurn,
"color" -> chess.Color.fromName(color).??(_.name),
"perf" -> Json.obj(
"icon" -> perfType.map(_.iconChar.toString),
"name" -> perfType.map(_.trans)
)
"mode" -> realMode.id,
"color" -> chess.Color.fromName(color).??(_.name)
)
.add("provisional" -> perf.map(_.provisional).filter(identity))
.add("days" -> daysPerTurn)
.add("perf" -> perfType.map { pt =>
Json.obj("key" -> pt.key)
})
.add("provisional" -> perf.exists(_.provisional))
lazy val perfType = PerfPicker.perfType(Speed.Correspondence, realVariant, daysPerTurn)
}

View File

@ -13,7 +13,19 @@ interface Untyped {
export interface Hook extends Untyped {}
export interface Seek extends Untyped {}
export interface Seek {
id: string;
username: string;
rating: number;
mode: number;
days?: number;
color: string;
perf: {
key: string;
};
provisional?: boolean;
action: 'joinSeek' | 'cancelSeek';
}
export interface Pool {
id: PoolId;

View File

@ -1,7 +1,8 @@
import { h, VNode } from 'snabbdom';
import { tds, bind } from './util';
import { tds, bind, perfNames } from './util';
import LobbyController from '../ctrl';
import { Seek, MaybeVNodes } from '../interfaces';
import perfIcons from 'common/perfIcons';
function renderSeek(ctrl: LobbyController, seek: Seek): VNode {
const klass = seek.action === 'joinSeek' ? 'join' : 'cancel',
@ -11,7 +12,7 @@ function renderSeek(ctrl: LobbyController, seek: Seek): VNode {
{
key: seek.id,
attrs: {
title: seek.action === 'joinSeek' ? noarg('joinTheGame') + ' - ' + seek.perf.name : noarg('cancel'),
title: seek.action === 'joinSeek' ? noarg('joinTheGame') + ' - ' + perfNames[seek.perf.key] : noarg('cancel'),
'data-id': seek.id,
},
},
@ -30,7 +31,7 @@ function renderSeek(ctrl: LobbyController, seek: Seek): VNode {
seek.days ? ctrl.trans.plural('nbDays', seek.days) : '∞',
h('span', [
h('span.varicon', {
attrs: { 'data-icon': seek.perf.icon },
attrs: { 'data-icon': perfIcons[seek.perf.key] },
}),
noarg(seek.mode === 1 ? 'rated' : 'casual'),
]),

View File

@ -1,7 +1,8 @@
import LobbyController from '../../ctrl';
import { bind, perfIcons } from '../util';
import { bind } from '../util';
import { h, VNode } from 'snabbdom';
import { Hook } from '../../interfaces';
import perfIcons from 'common/perfIcons';
const percents = (v: number) => v + '%';

View File

@ -1,6 +1,7 @@
import { h } from 'snabbdom';
import LobbyController from '../../ctrl';
import { bind, tds, perfIcons } from '../util';
import { bind, tds, perfNames } from '../util';
import perfIcons from 'common/perfIcons';
import * as hookRepo from '../../hookRepo';
import { Hook } from '../../interfaces';
@ -12,7 +13,11 @@ function renderHook(ctrl: LobbyController, hook: Hook) {
key: hook.id,
class: { disabled: hook.disabled },
attrs: {
title: hook.disabled ? '' : hook.action === 'join' ? noarg('joinTheGame') + ' | ' + hook.perf : noarg('cancel'),
title: hook.disabled
? ''
: hook.action === 'join'
? noarg('joinTheGame') + ' | ' + perfNames[hook.perf]
: noarg('cancel'),
'data-id': hook.id,
},
},

View File

@ -29,19 +29,19 @@ export function spinner() {
]);
}
export const perfIcons = {
Blitz: '',
'Racing Kings': '',
UltraBullet: '',
Bullet: '',
Classical: '',
Rapid: '',
'Three-check': '',
Antichess: '',
Horde: '',
Atomic: '',
Crazyhouse: '',
Chess960: '',
Correspondence: '',
'King of the Hill': '',
export const perfNames = {
ultraBullet: 'UltraBullet',
bullet: 'Bullet',
blitz: 'Blitz',
rapid: 'Rapid',
classical: 'Classical',
correspondence: 'Correspondence',
racingKings: 'Racing Kings',
threeCheck: 'Three-check',
antichess: 'Antichess',
horde: 'Horde',
atomic: 'Atomic',
crazyhouse: 'Crazyhouse',
chess960: 'Chess960',
kingOfTheHill: 'King of the Hill',
};