Skip to content

Commit c9ac3dc

Browse files
authored
Merge pull request #58 from puzzmo-com/refs-in-amuse
Adds support for grabbing refs in the amuse json
2 parents 84cca6c + 26d3170 commit c9ac3dc

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

packages/xd-crossword-tools/src/amuseJSONToXD.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,32 @@ export function convertAmuseToCrosswordJSON(amuseJson: AmuseTopLevel): Crossword
280280
currentClue.metadata.revealer = convertHtmlToXdMarkup(placedWord.clue.refText)
281281
}
282282

283+
// Add refs metadata for linked clues
284+
if (currentClue.metadata && placedWord.linkedWordIdxs && placedWord.linkedWordIdxs.length > 0) {
285+
const refs: string[] = []
286+
for (const linkedIdx of placedWord.linkedWordIdxs) {
287+
const linkedWord = amuseData.placedWords[linkedIdx]
288+
if (linkedWord) {
289+
// Determine direction of the linked word
290+
let linkedDirection: "A" | "D"
291+
if (linkedWord.clueSection) {
292+
linkedDirection = linkedWord.clueSection === "Across" ? "A" : "D"
293+
} else if ("acrossNotDown" in linkedWord) {
294+
linkedDirection = linkedWord.acrossNotDown ? "A" : "D"
295+
} else {
296+
// Skip this linked word if we can't determine direction
297+
continue
298+
}
299+
300+
refs.push(`${linkedDirection}${linkedWord.clueNum}`)
301+
}
302+
}
303+
304+
if (refs.length > 0) {
305+
currentClue.metadata.refs = refs.join(" ")
306+
}
307+
}
308+
283309
const clueID = `${clueNumberStr}-${direction}`
284310

285311
const positionData: CluePosition = {

packages/xd-crossword-tools/tests/amuseJSONToXD.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import type { AmuseTopLevel } from "../src/amuseJSONToXD.types"
44
import { beforeAll, describe, expect, it } from "vitest"
55
import { rebusAmuseExample, schrodingerAmuseExample } from "./amuse/amuseExamples"
66

7-
const exampleJSONPath = "/Users/orta/dev/workshop/packages/amuse-to-xd/examples/2024_03_17-barred_cryptic.json"
7+
const exampleJSONPath = "/Users/orta/dev/old-workshop/packages/amuse-to-xd/examples/2024_03_17-barred_cryptic.json"
88
const fullExamplePath = exampleJSONPath
99

10-
const hasCirclesPath = "/Users/orta/dev/workshop/packages/amuse-to-xd/examples/2025_04_01-themed.json"
11-
const largeGrid = "/Users/orta/dev/workshop/packages/amuse-to-xd/examples/2021_01_01-oversize.json"
12-
const cartoon = "/Users/orta/dev/workshop/packages/amuse-to-xd/examples/2019_12_23-cartoon.json"
10+
const hasCirclesPath = "/Users/orta/dev/old-workshop/packages/amuse-to-xd/examples/2025_04_01-themed.json"
11+
const largeGrid = "/Users/orta/dev/old-workshop/packages/amuse-to-xd/examples/2021_01_01-oversize.json"
12+
const cartoon = "/Users/orta/dev/old-workshop/packages/amuse-to-xd/examples/2019_12_23-cartoon.json"
1313

1414
// Only run tests if the example JSON files exist
1515
const shouldRunTests = existsSync(fullExamplePath) && existsSync(hasCirclesPath)
@@ -614,5 +614,26 @@ describeConditional("amuseJSONToXD", () => {
614614
expect(a1Clue?.body).toEqual("Hairdo")
615615
expect(a1Clue?.answer).toEqual("COIF")
616616
})
617+
618+
it("handles linked clues with refs metadata", () => {
619+
const xdOutput = convertAmuseToCrosswordJSON(JSON.parse(readFileSync(largeGrid, "utf-8")))
620+
621+
// Look for clues with refs metadata (linked clues)
622+
const allClues = [...xdOutput.clues.across, ...xdOutput.clues.down]
623+
const cluesWithRefs = allClues.filter((clue) => clue.metadata?.refs)
624+
625+
expect(cluesWithRefs.map((c) => [c.body, c.metadata?.refs] as const).sort((a, b) => a[0].localeCompare(b[0]))).toMatchInlineSnapshot(`
626+
[
627+
[
628+
"See 54-Across",
629+
"A54",
630+
],
631+
[
632+
"With 44-Across, Middle Eastern body of water",
633+
"A44",
634+
],
635+
]
636+
`)
637+
})
617638
})
618639
})

0 commit comments

Comments
 (0)