Skip to content

Commit

Permalink
fix(ui,signatures): ignore everything except cosmic signature or anomaly
Browse files Browse the repository at this point in the history
  • Loading branch information
updraft0 committed Feb 12, 2025
1 parent 4ffdc90 commit 34147cf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ lazy val ui = project
"dev.zio" %%% "zio-test-magnolia" % Versions.zio % Test
)
)
.dependsOn(protocol.js)
.dependsOn(protocol.js, `test-deps`.js % Test)

lazy val root = project
.in(file("."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class PasteSignaturesView(
.map(parseLines)
.withCurrentValueOf(time)
.map { (res, now) =>
res.filterOrElse(_.nonEmpty, "No signatures pasted").flatMap(_.map(parseLineToSignature(_, now)).sequence)
res
.flatMap(
_.filter(includeSignatureLine)
.map(parseLineToSignature(_, now))
.sequence
)
.filterOrElse(_.nonEmpty, "No signatures pasted")
}
.combineWith(shouldReplace.signal)
.map {
Expand All @@ -62,7 +68,10 @@ class PasteSignaturesView(
input(
cls := "signature-replace",
tpe := "checkbox",
onInput.mapToChecked --> shouldReplace
controlled(
checked <-- shouldReplace,
onInput.mapToChecked --> shouldReplace
)
),
textArea(
cls := "signature-paste",
Expand Down Expand Up @@ -240,6 +249,9 @@ def parseLineToSignature(line: ParsedLine, now: Instant): Either[String, NewSyst
group <- signatureGroupFor(line)
yield signatureFrom(sigId, group, line, now)

private def includeSignatureLine(line: ParsedLine) =
line.tpe == "Cosmic Signature" || line.tpe == "Cosmic Anomaly" || line.group == "Combat Site"

// TODO: ghost sites?
private def signatureGroupFor(line: ParsedLine) = (line.tpe, line.group) match
case (_, "Combat Site") => Right(SignatureGroup.Combat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ private[map] def pasteSignaturesView(
val shouldReplace = Var(false)
val addAll = PasteSignaturesView(mss.signatures, time, updates.writer, shouldReplace)
div(
ctx.userPreferences.map(_.sig.replaceSignaturesByDefault) --> shouldReplace,
cls := "system-paste-signatures-view",
cls := "dialog-view",
h2(cls := "dialog-header", s"Paste system signatures [${mss.system.name.getOrElse(solarSystem.name)}]"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package controltower.page.map.view

import zio.test.*

object PasteSignatureViewSpec extends ZIOSpecDefault:

override def spec =
suite("Signature parsing")(
test("Works on all signature types"):
val clipboard =
"""
|WZB-024 Cosmic Signature Combat Site 0.0% 32.13 AU
|PIA-435 Cosmic Signature 0.0% 28.15 AU
|JEY-515 Cosmic Signature Data Site 0.0% 19.06 AU
|THS-490 Cosmic Signature Wormhole Unstable Wormhole 100.0% 4.94 AU
|ULL-880 Cosmic Signature Gas Site 0.0% 9.93 AU
|WFD-000 Cosmic Signature Relic Site Forgotten Frontier Evacuation Center 0.0% 9.93 AU
|IXC-218 Ship Mining Barge Covetor 100.0% 4,710 km
|JLH-924 Cosmic Anomaly Ore Site Ordinary Perimeter Deposit 100.0% 38.53 AU
|""".stripMargin
val expected = List(
ParsedLine("WZB-024", "Cosmic Signature", "Combat Site", "", "0.0%", "32.13 AU"),
ParsedLine("PIA-435", "Cosmic Signature", "", "", "0.0%", "28.15 AU"),
ParsedLine("JEY-515", "Cosmic Signature", "Data Site", "", "0.0%", "19.06 AU"),
ParsedLine("THS-490", "Cosmic Signature", "Wormhole", "Unstable Wormhole", "100.0%", "4.94 AU"),
ParsedLine("ULL-880", "Cosmic Signature", "Gas Site", "", "0.0%", "9.93 AU"),
ParsedLine(
"WFD-000",
"Cosmic Signature",
"Relic Site",
"Forgotten Frontier Evacuation Center",
"0.0%",
"9.93 AU"
),
ParsedLine("IXC-218", "Ship", "Mining Barge", "Covetor", "100.0%", "4,710 km"),
ParsedLine("JLH-924", "Cosmic Anomaly", "Ore Site", "Ordinary Perimeter Deposit", "100.0%", "38.53 AU")
)
val res = parseLines(clipboard)
assertTrue(res == Right(expected))
)

0 comments on commit 34147cf

Please # to comment.