diff --git a/src/scripts/components/h5p-crossword-content.js b/src/scripts/components/h5p-crossword-content.js index 6c1f5bb..d00ab30 100644 --- a/src/scripts/components/h5p-crossword-content.js +++ b/src/scripts/components/h5p-crossword-content.js @@ -118,10 +118,10 @@ export default class CrosswordContent { this.clueAnnouncer = new CrosswordClueAnnouncer(); tableWrapper.appendChild(this.clueAnnouncer.getDOM()); - this.crosswordLayout.result = this.crosswordLayout.result.map((word, index) => { - word.clue = this.params.words[index].clue; - word.answer = this.params.words[index].answer; - word.extraClue = this.params.words[index].extraClue; + this.crosswordLayout.result = this.crosswordLayout.result.map((word) => { + word.clue = this.params.words[word.index].clue; + word.answer = this.params.words[word.index].answer; + word.extraClue = this.params.words[word.index].extraClue; return word; }); @@ -396,6 +396,7 @@ export default class CrosswordContent { rows: this.crosswordLayout.rows, result: this.crosswordLayout.result.map((word) => { return { + index: word.index, clueId: word.clueId, orientation: word.orientation, startx: word.startx, diff --git a/src/scripts/services/h5p-crossword-generator.js b/src/scripts/services/h5p-crossword-generator.js index c0fb8ca..8310d16 100644 --- a/src/scripts/services/h5p-crossword-generator.js +++ b/src/scripts/services/h5p-crossword-generator.js @@ -697,7 +697,7 @@ export default class CrosswordGenerator { continue; } - if (cell.down && cell.down.isStartOfWord) { + if (cell.down?.isStartOfWord) { result.push({ clue: this.getWordElement(cell.down.index, 'clue'), answer: this.getWordElement(cell.down.index, 'answer'), @@ -705,11 +705,12 @@ export default class CrosswordGenerator { startx: c + 1, starty: r + 1, orientation: 'down', - clueId: nextClueId + clueId: nextClueId, + index: cell.down.index }); } - if (cell.across && cell.across.isStartOfWord) { + if (cell.across?.isStartOfWord) { result.push({ clue: this.getWordElement(cell.across.index, 'clue'), answer: this.getWordElement(cell.across.index, 'answer'), @@ -717,11 +718,12 @@ export default class CrosswordGenerator { startx: c + 1, starty: r + 1, orientation: 'across', - clueId: nextClueId + clueId: nextClueId, + index: cell.across.index }); } - if (cell.down && cell.down.isStartOfWord || cell.across && cell.across.isStartOfWord) { + if (cell.down?.isStartOfWord || cell.across?.isStartOfWord) { nextClueId++; } }