Skip to content

Commit

Permalink
Use emt when missing clock in NewPgnImport
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Apr 12, 2024
1 parent 0927db1 commit b7400ac
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions modules/study/src/main/NewPgnImport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object NewPgnImport:
val annotator = PgnImport.findAnnotator(parsedPgn, contributors)
PgnImport.parseComments(parsedPgn.initialPosition.comments, annotator) match
case (shapes, _, _, comments) =>
val clock = parsedPgn.tags.clockConfig.map(_.limit)
val setup = Context(replay.setup, clock)
val root: NewRoot =
NewRoot(
Metas(
Expand All @@ -49,9 +51,9 @@ object NewPgnImport:
glyphs = Glyphs.empty,
opening = None,
crazyData = replay.setup.situation.board.crazyData,
clock = parsedPgn.tags.clockConfig.map(_.limit)
clock = clock
),
parsedPgn.tree.flatMap(makeTree(replay.setup, _, annotator))
parsedPgn.tree.flatMap(makeTree(setup, _, annotator))
)
val end: Option[PgnImport.End] = (game.finished.option(game.status)).map { status =>
PgnImport.End(
Expand All @@ -77,28 +79,33 @@ object NewPgnImport:
)
}

case class Context(
game: chess.Game,
clock: Option[Centis]
)

private def makeTree(
setup: chess.Game,
context: Context,
node: ParsedPgnTree,
annotator: Option[Comment.Author]
): Option[PgnNode[NewBranch]] =
node.mapAccumlOption_(setup): (setup, data) =>
transform(setup, data, annotator)
node.mapAccumlOption_(context): (context, data) =>
transform(context, data, annotator)

private def transform(
context: chess.Game,
context: Context,
data: PgnNodeData,
annotator: Option[Comment.Author]
): (chess.Game, Option[NewBranch]) =
): (Context, Option[NewBranch]) =
data
.san(context.situation)
.san(context.game.situation)
.map(moveOrDrop =>
val game = moveOrDrop.applyGame(context)
val game = moveOrDrop.applyGame(context.game)
val uci = moveOrDrop.toUci
val id = UciCharPair(uci)
val sanStr = moveOrDrop.toSanStr
(
game,
Context(game, None), // TODO
PgnImport.parseComments(data.metas.comments, annotator) match
case (shapes, clock, emt, comments) =>
NewBranch(
Expand All @@ -118,12 +125,13 @@ object NewPgnImport:
gamebook = None,
glyphs = data.metas.glyphs,
opening = None,
clock = clock,
clock = clock.orElse((context.clock, emt).mapN(_ + _)),
crazyData = game.situation.board.crazyData
)
).some
)
)
.toOption match
case Some(branch) => branch
case None => (context, None)
.toOption
.match
case Some(branch) => branch
case None => (context, None)

0 comments on commit b7400ac

Please sign in to comment.