Skip to content

Commit 34147cf

Browse files
committed
fix(ui,signatures): ignore everything except cosmic signature or anomaly
1 parent 4ffdc90 commit 34147cf

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ lazy val ui = project
182182
"dev.zio" %%% "zio-test-magnolia" % Versions.zio % Test
183183
)
184184
)
185-
.dependsOn(protocol.js)
185+
.dependsOn(protocol.js, `test-deps`.js % Test)
186186

187187
lazy val root = project
188188
.in(file("."))

ui/src/main/scala/controltower/page/map/view/PasteSignaturesView.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class PasteSignaturesView(
4141
.map(parseLines)
4242
.withCurrentValueOf(time)
4343
.map { (res, now) =>
44-
res.filterOrElse(_.nonEmpty, "No signatures pasted").flatMap(_.map(parseLineToSignature(_, now)).sequence)
44+
res
45+
.flatMap(
46+
_.filter(includeSignatureLine)
47+
.map(parseLineToSignature(_, now))
48+
.sequence
49+
)
50+
.filterOrElse(_.nonEmpty, "No signatures pasted")
4551
}
4652
.combineWith(shouldReplace.signal)
4753
.map {
@@ -62,7 +68,10 @@ class PasteSignaturesView(
6268
input(
6369
cls := "signature-replace",
6470
tpe := "checkbox",
65-
onInput.mapToChecked --> shouldReplace
71+
controlled(
72+
checked <-- shouldReplace,
73+
onInput.mapToChecked --> shouldReplace
74+
)
6675
),
6776
textArea(
6877
cls := "signature-paste",
@@ -240,6 +249,9 @@ def parseLineToSignature(line: ParsedLine, now: Instant): Either[String, NewSyst
240249
group <- signatureGroupFor(line)
241250
yield signatureFrom(sigId, group, line, now)
242251

252+
private def includeSignatureLine(line: ParsedLine) =
253+
line.tpe == "Cosmic Signature" || line.tpe == "Cosmic Anomaly" || line.group == "Combat Site"
254+
243255
// TODO: ghost sites?
244256
private def signatureGroupFor(line: ParsedLine) = (line.tpe, line.group) match
245257
case (_, "Combat Site") => Right(SignatureGroup.Combat)

ui/src/main/scala/controltower/page/map/view/SystemSignatureView.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ private[map] def pasteSignaturesView(
705705
val shouldReplace = Var(false)
706706
val addAll = PasteSignaturesView(mss.signatures, time, updates.writer, shouldReplace)
707707
div(
708+
ctx.userPreferences.map(_.sig.replaceSignaturesByDefault) --> shouldReplace,
708709
cls := "system-paste-signatures-view",
709710
cls := "dialog-view",
710711
h2(cls := "dialog-header", s"Paste system signatures [${mss.system.name.getOrElse(solarSystem.name)}]"),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package controltower.page.map.view
2+
3+
import zio.test.*
4+
5+
object PasteSignatureViewSpec extends ZIOSpecDefault:
6+
7+
override def spec =
8+
suite("Signature parsing")(
9+
test("Works on all signature types"):
10+
val clipboard =
11+
"""
12+
|WZB-024 Cosmic Signature Combat Site 0.0% 32.13 AU
13+
|PIA-435 Cosmic Signature 0.0% 28.15 AU
14+
|JEY-515 Cosmic Signature Data Site 0.0% 19.06 AU
15+
|THS-490 Cosmic Signature Wormhole Unstable Wormhole 100.0% 4.94 AU
16+
|ULL-880 Cosmic Signature Gas Site 0.0% 9.93 AU
17+
|WFD-000 Cosmic Signature Relic Site Forgotten Frontier Evacuation Center 0.0% 9.93 AU
18+
|IXC-218 Ship Mining Barge Covetor 100.0% 4,710 km
19+
|JLH-924 Cosmic Anomaly Ore Site Ordinary Perimeter Deposit 100.0% 38.53 AU
20+
|""".stripMargin
21+
val expected = List(
22+
ParsedLine("WZB-024", "Cosmic Signature", "Combat Site", "", "0.0%", "32.13 AU"),
23+
ParsedLine("PIA-435", "Cosmic Signature", "", "", "0.0%", "28.15 AU"),
24+
ParsedLine("JEY-515", "Cosmic Signature", "Data Site", "", "0.0%", "19.06 AU"),
25+
ParsedLine("THS-490", "Cosmic Signature", "Wormhole", "Unstable Wormhole", "100.0%", "4.94 AU"),
26+
ParsedLine("ULL-880", "Cosmic Signature", "Gas Site", "", "0.0%", "9.93 AU"),
27+
ParsedLine(
28+
"WFD-000",
29+
"Cosmic Signature",
30+
"Relic Site",
31+
"Forgotten Frontier Evacuation Center",
32+
"0.0%",
33+
"9.93 AU"
34+
),
35+
ParsedLine("IXC-218", "Ship", "Mining Barge", "Covetor", "100.0%", "4,710 km"),
36+
ParsedLine("JLH-924", "Cosmic Anomaly", "Ore Site", "Ordinary Perimeter Deposit", "100.0%", "38.53 AU")
37+
)
38+
val res = parseLines(clipboard)
39+
assertTrue(res == Right(expected))
40+
)

0 commit comments

Comments
 (0)