Skip to content

Commit

Permalink
fix puzzle racer
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 30, 2022
1 parent a77ab2b commit 80d85f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Racer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class Racer(env: Env)(implicit mat: akka.stream.Materializer) extends Lila

def apiCreate = Scoped(_.Racer.Write) { implicit req => me =>
me.noBot ?? {
env.racer.api.createAndJoin(RacerPlayer.Id.User(me.username)) map { raceId =>
env.racer.api.createAndJoin(RacerPlayer.Id.User(me.id)) map { raceId =>
JsonOk(
Json.obj(
"id" -> raceId.value,
Expand Down
2 changes: 1 addition & 1 deletion modules/racer/src/main/RacerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class RacerApi(colls: RacerColls, selector: StormSelector, userRepo: UserR
def get(id: Id): Option[RacerRace] = store getIfPresent id

def playerId(sessionId: String, user: Option[User]) = user match
case Some(u) => RacerPlayer.Id.User(u.username)
case Some(u) => RacerPlayer.Id.User(u.id)
case None => RacerPlayer.Id.Anon(sessionId)

def createAndJoin(player: RacerPlayer.Id): Fu[RacerRace.Id] =
Expand Down
8 changes: 4 additions & 4 deletions modules/racer/src/main/RacerPlayer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ case class RacerPlayer(id: RacerPlayer.Id, createdAt: DateTime, score: Int):
case _ => none

lazy val name: UserName = id match
case Id.User(n) => n
case Id.User(n) => n into UserName
case Id.Anon(id) => CuteNameGenerator fromSeed id.hashCode

object RacerPlayer:
enum Id:
case User(name: UserName)
case User(id: UserId)
case Anon(sessionId: String)
object Id:
def apply(str: String) =
if (str startsWith "@") Anon(str drop 1)
else User(UserName(str))
else User(UserId(str))

val lichess = Id.User(User.lichessName)
val lichess = Id.User(User.lichessId)

def make(id: Id) = RacerPlayer(id = id, score = 0, createdAt = DateTime.now)

0 comments on commit 80d85f1

Please sign in to comment.