Skip to content

Commit

Permalink
Add Eight Tracks advanced option to mark inner track starting squares.
Browse files Browse the repository at this point in the history
See #43
  • Loading branch information
jpd236 committed Oct 24, 2024
1 parent 95c5cce commit 198bd80
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class EightTracks(
val lightTrackColor: String,
val darkTrackColor: String,
val trackLabel: TrackLabel = TrackLabel.TRACKS,
val markInnerTrackStarts: Boolean = false,
) : Puzzleable() {

enum class TrackLabel(val firstTrack: String, val otherTracks: String) {
Expand Down Expand Up @@ -53,7 +54,15 @@ data class EightTracks(
val coordinates = trackCoordinates[coordinateIndex]
val cell = Puzzle.Cell(
solution = "$ch",
number = if (trackIndex == 0 && i == 0) "${answerId + 1}" else "",
number = if (i == 0) {
if (trackIndex == 0) {
"${answerId + 1}"
} else if (markInnerTrackStarts) {
"\u2022"
} else {
""
}
} else "",
backgroundColor = if (trackIndex % 2 == 0) darkTrackColor else lightTrackColor,
borderDirections = getBorderDirections(coordinateIndex, trackCoordinates.size)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ class EightTracksTest {
)
}

@Test
fun jpzGeneration_markInnerTrackStarts() = runTest {
val eightTracks = EightTracks(
title = "Test title",
creator = "Test creator",
copyright = "Test copyright",
description = "Test description",
trackDirections = listOf(EightTracks.Direction.CLOCKWISE, EightTracks.Direction.COUNTERCLOCKWISE),
trackStartingOffsets = listOf(3, 7),
trackAnswers = listOf(listOf("CDEF", "GHIJK", "LMN", "OPAB"), listOf("MKIG", "ECAO")),
trackClues = listOf(listOf("Clue 1", "Clue 2", "Clue 3", "Clue 4"), listOf("Clue 1", "Clue 2")),
includeEnumerations = true,
includeDirections = true,
lightTrackColor = "#FFFFFF",
darkTrackColor = "#C0C0C0",
markInnerTrackStarts = true,
)
val puzzle = eightTracks.asPuzzle()

val expected = readStringResource(EightTracks::class, "eight-tracks/inner-track-starts.jpz")
assertXmlEquals(
expected, puzzle.asJpz(
appletSettings = CrosswordCompilerApplet.AppletSettings(
cursorColor = "#00b100",
selectedCellsColor = "#80ff80",
completion = CrosswordCompilerApplet.AppletSettings.Completion(message = "All done!"),
)
).toXmlString()
)
}

@Test
fun asPuzzle_invalidSection() = runTest {
val eightTracks = EightTracks(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><crossword-compiler-applet xmlns="http://crossword.info/xml/crossword-compiler-applet"><applet-settings cursor-color="#00b100" selected-cells-color="#80ff80"><completion only-if-correct="true">All done!</completion><actions buttons-layout="left"><reveal-word label="Reveal Word"/><reveal-letter label="Reveal Letter"/><check label="Check"/><solution label="Solution"/><pencil label="Pencil"/></actions></applet-settings><rectangular-puzzle xmlns="http://crossword.info/xml/rectangular-puzzle"><metadata><title>Test title</title><creator>Test creator</creator><copyright>Test copyright</copyright><description>Test description</description></metadata><crossword><grid width="5" height="5"><grid-look numbering-scheme="normal"/><cell x="1" y="1" solution="A" background-color="#C0C0C0"/><cell x="2" y="1" solution="B" background-color="#C0C0C0"/><cell x="3" y="1" solution="C" background-color="#C0C0C0" number="1" left-bar="true"/><cell x="4" y="1" solution="D" background-color="#C0C0C0"/><cell x="5" y="1" solution="E" background-color="#C0C0C0" left-bar="true"/><cell x="1" y="2" solution="P" background-color="#C0C0C0" top-bar="true"/><cell x="2" y="2" solution="A" background-color="#FFFFFF" left-bar="true"/><cell x="3" y="2" solution="C" background-color="#FFFFFF" left-bar="true"/><cell x="4" y="2" solution="E" background-color="#FFFFFF" number="•" top-bar="true" left-bar="true"/><cell x="5" y="2" solution="F" background-color="#C0C0C0"/><cell x="1" y="3" solution="O" background-color="#C0C0C0" number="4"/><cell x="2" y="3" solution="O" background-color="#FFFFFF" top-bar="true"/><cell x="3" y="3" type="block" top-bar="true" left-bar="true"/><cell x="4" y="3" solution="G" background-color="#FFFFFF" top-bar="true" left-bar="true"/><cell x="5" y="3" solution="G" background-color="#C0C0C0" number="2" top-bar="true"/><cell x="1" y="4" solution="N" background-color="#C0C0C0" top-bar="true"/><cell x="2" y="4" solution="M" background-color="#FFFFFF" number="•" top-bar="true"/><cell x="3" y="4" solution="K" background-color="#FFFFFF" top-bar="true" left-bar="true"/><cell x="4" y="4" solution="I" background-color="#FFFFFF" top-bar="true" left-bar="true"/><cell x="5" y="4" solution="H" background-color="#C0C0C0" left-bar="true"/><cell x="1" y="5" solution="M" background-color="#C0C0C0"/><cell x="2" y="5" solution="L" background-color="#C0C0C0" number="3" top-bar="true" left-bar="true"/><cell x="3" y="5" solution="K" background-color="#C0C0C0"/><cell x="4" y="5" solution="J" background-color="#C0C0C0" left-bar="true"/><cell x="5" y="5" solution="I" background-color="#C0C0C0" top-bar="true"/></grid><word id="101"><cells x="3" y="1"/><cells x="4" y="1"/><cells x="5" y="1"/><cells x="5" y="2"/></word><word id="102"><cells x="5" y="3"/><cells x="5" y="4"/><cells x="5" y="5"/><cells x="4" y="5"/><cells x="3" y="5"/></word><word id="103"><cells x="2" y="5"/><cells x="1" y="5"/><cells x="1" y="4"/></word><word id="104"><cells x="1" y="3"/><cells x="1" y="2"/><cells x="1" y="1"/><cells x="2" y="1"/></word><word id="2"><cells x="2" y="2"/><cells x="2" y="3"/><cells x="2" y="4"/><cells x="3" y="4"/><cells x="4" y="4"/><cells x="4" y="3"/><cells x="4" y="2"/><cells x="3" y="2"/></word><clues><title><b>Track 1</b></title><clue word="101" number="1">Clue 1 (4)</clue><clue word="102" number="2">Clue 2 (5)</clue><clue word="103" number="3">Clue 3 (3)</clue><clue word="104" number="4">Clue 4 (4)</clue></clues><clues><title><b>Other tracks</b></title><clue word="2" number="2(–)">Clue 1 (4) / Clue 2 (4)</clue></clues></crossword></rectangular-puzzle></crossword-compiler-applet>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EightTracksForm {
private val trackClues: FormFields.TextBoxField = FormFields.TextBoxField("track-clues")
private val includeEnumerations: FormFields.CheckBoxField = FormFields.CheckBoxField("include-enumerations")
private val includeDirections: FormFields.CheckBoxField = FormFields.CheckBoxField("include-directions")
private val markInnerTrackStarts: FormFields.CheckBoxField = FormFields.CheckBoxField("mark-inner-track-starts")
private val trackLabel: FormFields.SelectField = FormFields.SelectField("track-label")
private val lightTrackColor: FormFields.InputField = FormFields.InputField("light-track-color")
private val darkTrackColor: FormFields.InputField = FormFields.InputField("dark-track-color")
Expand Down Expand Up @@ -46,12 +47,13 @@ class EightTracksForm {
}
}, advancedOptionsBlock = {
div(classes = "form-row") {
includeEnumerations.render(this, "Include clue enumerations", flexCols = 6) {
includeEnumerations.render(this, "Include clue enumerations", flexCols = 4) {
checked = true
}
includeDirections.render(this, "Include track directions", flexCols = 6) {
includeDirections.render(this, "Include track directions", flexCols = 4) {
checked = true
}
markInnerTrackStarts.render(this, "Mark starting squares of entries in inner tracks", flexCols = 4)
}
trackLabel.render(
this,
Expand Down Expand Up @@ -93,7 +95,8 @@ class EightTracksForm {
includeDirections = includeDirections.value,
lightTrackColor = lightTrackColor.value,
darkTrackColor = darkTrackColor.value,
trackLabel = EightTracks.TrackLabel.valueOf(trackLabel.value.uppercase())
trackLabel = EightTracks.TrackLabel.valueOf(trackLabel.value.uppercase()),
markInnerTrackStarts = markInnerTrackStarts.value,
)
return eightTracks.asPuzzle()
}
Expand Down

0 comments on commit 198bd80

Please sign in to comment.