Skip to content

Commit

Permalink
Merge pull request #16721 from SergioGlorias/simply-replace
Browse files Browse the repository at this point in the history
simplify replace system
  • Loading branch information
ornicar authored Jan 12, 2025
2 parents e14e4f7 + 967567f commit ca47fd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
31 changes: 11 additions & 20 deletions modules/relay/src/main/RelayPlayerEnrich.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,18 @@ private case class RelayPlayersTextarea(text: String):
lines.nonEmpty.so:
text.linesIterator.take(1000).toList.flatMap(parse).toMap

// Original name / Optional rating / Optional title / Optional replacement name
// Original name / Optional FideID / Optional title / Optional rating / Optional replacement name
private def parse(line: String): Option[(PlayerName, RelayPlayerLine)] =
line.split('=').map(_.trim) match
case Array(nameStr, fideId) =>
val name = PlayerName(nameStr)
val parts = fideId.split('/').map(_.trim)
parts
.lift(0)
.flatMap(_.toIntOption)
.map: id =>
name -> RelayPlayerLine(name.some, none, parts.lift(1).flatMap(PlayerTitle.get), FideId(id).some)
case _ =>
val arr = line.split('/').map(_.trim)
arr
.lift(0)
.map: fromName =>
PlayerName(fromName) -> RelayPlayerLine(
name = PlayerName.from(arr.lift(3).filter(_.nonEmpty)),
rating = IntRating.from(arr.lift(1).flatMap(_.toIntOption)),
title = arr.lift(2).flatMap(PlayerTitle.get)
)
val arr = line.split('/').map(_.trim)
arr
.lift(0)
.map: fromName =>
PlayerName(fromName) -> RelayPlayerLine(
name = PlayerName.from(arr.lift(4).filter(_.nonEmpty)),
rating = IntRating.from(arr.lift(3).flatMap(_.toIntOption)),
title = arr.lift(2).flatMap(PlayerTitle.get),
fideId = arr.lift(1).flatMap(_.toIntOption).map(FideId(_))
)

private case class RelayPlayerLines(players: Map[PlayerName, RelayPlayerLine]):

Expand Down
12 changes: 6 additions & 6 deletions modules/relay/src/main/ui/RelayFormUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,20 @@ final class RelayFormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
trb.replacePlayerTags(),
help = frag( // do not translate
"One line per player, formatted as such:",
pre("player name = FIDE ID"),
pre("player name / FIDE ID"),
"Example:",
pre("""Magnus Carlsen = 1503014"""),
pre("""Magnus Carlsen / 1503014"""),
"Player names ignore case and punctuation, and match all possible combinations of 2 words:",
br,
""""Jorge Rick Vito" will match "Jorge Rick", "jorge vito", "Rick, Vito", etc.""",
br,
"If the player is NM or WNM, you can:",
pre("""Player Name = FIDE ID / Title"""),
pre("""Player Name / FIDE ID / title"""),
"Alternatively, you may set tags manually, like so:",
pre("player name / rating / title / new name"),
pre("player name / FIDE ID / title / rating / new name"),
"All values are optional. Example:",
pre("""Magnus Carlsen / 2863 / GM
YouGotLittUp / 1890 / / Louis Litt""")
pre("""Magnus Carlsen / / GM / 2863
YouGotLittUp / / / 1890 / Louis Litt""")
).some,
half = true
)(form3.textarea(_)(rows := 3, spellcheck := "false", cls := "monospace")),
Expand Down

0 comments on commit ca47fd8

Please sign in to comment.