fix tournament standing propagation
This commit is contained in:
parent
89fa5c0b2a
commit
0c70bcc021
|
@ -218,6 +218,7 @@ package round {
|
|||
case class IsOnGame(color: chess.Color)
|
||||
sealed trait SocketEvent
|
||||
case class FishnetPlay(uci: chess.format.Uci, currentFen: chess.format.FEN)
|
||||
case class TourStanding(json: JsObject)
|
||||
}
|
||||
|
||||
package evaluation {
|
||||
|
|
|
@ -15,7 +15,7 @@ import lila.game.actorApi.{ StartGame, UserStartGame }
|
|||
import lila.game.{ Game, GameRepo, Event }
|
||||
import lila.hub.actorApi.Deploy
|
||||
import lila.hub.actorApi.game.ChangeFeatured
|
||||
import lila.hub.actorApi.round.IsOnGame
|
||||
import lila.hub.actorApi.round.{ IsOnGame, TourStanding }
|
||||
import lila.hub.actorApi.tv.{ Select => TvSelect }
|
||||
import lila.hub.TimeBomb
|
||||
import lila.socket._
|
||||
|
@ -35,6 +35,11 @@ private[round] final class Socket(
|
|||
|
||||
private var hasAi = false
|
||||
private var mightBeSimul = true // until proven false
|
||||
private var chatIds = Socket.ChatIds(
|
||||
priv = Chat.Id(gameId), // until replaced with tourney/simul chat
|
||||
pub = Chat.Id(s"$gameId/w")
|
||||
)
|
||||
private var tournamentId = none[String] // until set, to listen to standings
|
||||
|
||||
private val timeBomb = new TimeBomb(socketTimeout)
|
||||
|
||||
|
@ -72,11 +77,6 @@ private[round] final class Socket(
|
|||
private val whitePlayer = new Player(White)
|
||||
private val blackPlayer = new Player(Black)
|
||||
|
||||
private var chatIds = Socket.ChatIds(
|
||||
priv = Chat.Id(gameId),
|
||||
pub = Chat.Id(s"$gameId/w")
|
||||
)
|
||||
|
||||
override def preStart() {
|
||||
super.preStart()
|
||||
refreshSubscriptions
|
||||
|
@ -94,12 +94,19 @@ private[round] final class Socket(
|
|||
lilaBus.subscribe(self, Symbol(s"userStartGame:$userId"))
|
||||
}
|
||||
refreshChatSubscriptions
|
||||
refreshTournamentSubscriptions
|
||||
}
|
||||
|
||||
private def refreshChatSubscriptions {
|
||||
lilaBus.subscribe(self, Symbol(s"chat-${chatIds.priv}"), Symbol(s"chat-${chatIds.pub}"))
|
||||
}
|
||||
|
||||
private def refreshTournamentSubscriptions {
|
||||
tournamentId foreach { id =>
|
||||
lilaBus.subscribe(self, Symbol(s"tour-standing-$id"))
|
||||
}
|
||||
}
|
||||
|
||||
def receiveSpecific = ({
|
||||
|
||||
case SetGame(Some(game)) =>
|
||||
|
@ -111,6 +118,10 @@ private[round] final class Socket(
|
|||
chatIds = chatIds.copy(priv = chatId)
|
||||
refreshChatSubscriptions
|
||||
}
|
||||
game.tournamentId foreach { tourId =>
|
||||
tournamentId = tourId.some
|
||||
refreshTournamentSubscriptions
|
||||
}
|
||||
|
||||
// from lilaBus 'startGame
|
||||
// sets definitive user ids
|
||||
|
@ -209,6 +220,8 @@ private[round] final class Socket(
|
|||
notifyAll(event.typ, event.data)
|
||||
}
|
||||
|
||||
case TourStanding(json) => notifyAll("tourStanding", json)
|
||||
|
||||
}: Actor.Receive) orElse lila.chat.Socket.out(
|
||||
send = (t, d, _) => notifyAll(t, d)
|
||||
)
|
||||
|
|
|
@ -52,8 +52,6 @@ final class Env(
|
|||
}
|
||||
import settings._
|
||||
|
||||
private val standingChannel = system.actorOf(Props(classOf[lila.socket.Channel]), name = ChannelStanding)
|
||||
|
||||
lazy val forms = new DataForm
|
||||
|
||||
lazy val cached = new Cached(
|
||||
|
@ -93,8 +91,7 @@ final class Env(
|
|||
indexLeaderboard = leaderboardIndexer.indexOne _,
|
||||
roundMap = roundMap,
|
||||
asyncCache = asyncCache,
|
||||
lightUserApi = lightUserApi,
|
||||
standingChannel = standingChannel
|
||||
lightUserApi = lightUserApi
|
||||
)
|
||||
|
||||
lazy val crudApi = new crud.CrudApi
|
||||
|
|
|
@ -324,8 +324,8 @@ final class JsonView(
|
|||
|
||||
object JsonView {
|
||||
|
||||
def top(t: TournamentTop, getLightUser: LightUser.GetterSync): JsObject = Json.obj(
|
||||
"top" -> t.value.map { p =>
|
||||
def top(t: TournamentTop, getLightUser: LightUser.GetterSync): JsArray = JsArray {
|
||||
t.value.map { p =>
|
||||
val light = getLightUser(p.userId)
|
||||
Json.obj(
|
||||
"n" -> light.fold(p.userId)(_.name),
|
||||
|
@ -334,7 +334,7 @@ object JsonView {
|
|||
.add("f" -> p.fire)
|
||||
.add("w" -> p.withdraw)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private def formatDate(date: DateTime) = ISODateTimeFormat.dateTime print date
|
||||
|
||||
|
|
|
@ -36,10 +36,11 @@ final class TournamentApi(
|
|||
verify: Condition.Verify,
|
||||
indexLeaderboard: Tournament => Funit,
|
||||
asyncCache: lila.memo.AsyncCache.Builder,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
standingChannel: ActorRef
|
||||
lightUserApi: lila.user.LightUserApi
|
||||
) {
|
||||
|
||||
private val bus = system.lilaBus
|
||||
|
||||
def createTournament(setup: TournamentSetup, me: User): Fu[Tournament] = {
|
||||
val tour = Tournament.make(
|
||||
by = Right(me),
|
||||
|
@ -425,9 +426,10 @@ final class TournamentApi(
|
|||
import lila.hub.EarlyMultiThrottler
|
||||
|
||||
private def publishNow(tourId: Tournament.ID) = tournamentTop(tourId) map { top =>
|
||||
standingChannel ! lila.socket.Channel.Publish(
|
||||
lila.socket.Socket.makeMessage("tourStanding", JsonView.top(top, lightUserApi.sync))
|
||||
)
|
||||
bus.publish(lila.hub.actorApi.round.TourStanding(Json.obj(
|
||||
"id" -> tourId,
|
||||
"top" -> JsonView.top(top, lightUserApi.sync)
|
||||
)), Symbol(s"tour-standing-$tourId"))
|
||||
}
|
||||
|
||||
private val throttler = system.actorOf(Props(new EarlyMultiThrottler(logger = logger)))
|
||||
|
|
|
@ -41,9 +41,11 @@ export default function(opts: RoundOpts, element: HTMLElement): void {
|
|||
}
|
||||
});
|
||||
},
|
||||
tourStanding(data: TourStandingData) {
|
||||
if (opts.chat && opts.chat.plugin) (opts.chat.plugin as TourStandingCtrl).set(data);
|
||||
chat && chat.redraw();
|
||||
tourStanding(s: TourStandingData) {
|
||||
if (data.tournament && data.tournament.id === s.id && opts.chat && opts.chat.plugin && chat) {
|
||||
(opts.chat.plugin as TourStandingCtrl).set(s.top);
|
||||
chat.redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ import { VNode } from 'snabbdom/vnode';
|
|||
import { GameData, Status } from 'game';
|
||||
import { ClockData, Seconds, Centis } from './clock/clockCtrl';
|
||||
import { CorresClockData } from './corresClock/corresClockCtrl';
|
||||
import { TourStandingData } from './tourStanding';
|
||||
import { TourPlayer } from './tourStanding';
|
||||
import { ChatPlugin } from 'chat';
|
||||
import * as cg from 'chessground/types';
|
||||
|
||||
|
@ -82,7 +82,7 @@ export interface RoundOpts {
|
|||
crosstableEl: HTMLElement;
|
||||
i18n: any;
|
||||
chat?: Chat;
|
||||
tour?: TourStandingData;
|
||||
tour?: TourPlayer[];
|
||||
}
|
||||
|
||||
export interface Chat {
|
||||
|
|
|
@ -4,14 +4,15 @@ import { ChatPlugin } from 'chat'
|
|||
import { justIcon } from './util'
|
||||
|
||||
export interface TourStandingCtrl extends ChatPlugin {
|
||||
set(data: TourStandingData): void;
|
||||
set(data: TourPlayer[]): void;
|
||||
}
|
||||
|
||||
export interface TourStandingData {
|
||||
id: string;
|
||||
top: TourPlayer[];
|
||||
}
|
||||
|
||||
interface TourPlayer {
|
||||
export interface TourPlayer {
|
||||
n: string; // name
|
||||
s: number; // score
|
||||
t?: string; // title
|
||||
|
@ -19,16 +20,16 @@ interface TourPlayer {
|
|||
w: boolean; // withdraw
|
||||
}
|
||||
|
||||
export function tourStandingCtrl(data: TourStandingData, name: string): TourStandingCtrl {
|
||||
export function tourStandingCtrl(data: TourPlayer[], name: string): TourStandingCtrl {
|
||||
return {
|
||||
set(d: TourStandingData) { data = d },
|
||||
set(d: TourPlayer[]) { data = d },
|
||||
tab: {
|
||||
key: 'tourStanding',
|
||||
name: name
|
||||
},
|
||||
view(): VNode {
|
||||
return h('table.slist',
|
||||
h('tbody', data.top.map((p: TourPlayer, i: number) => {
|
||||
h('tbody', data.map((p: TourPlayer, i: number) => {
|
||||
return h('tr.' + p.n, [
|
||||
h('td.name', [
|
||||
p.w ? h('span', justIcon('Z')) : h('span.rank', '' + (i + 1)),
|
||||
|
|
Loading…
Reference in a new issue