word/memory: pick cards to fit grid dimensions
[sheet.git] / word / memory.js
index 94836c282b54666093c396631cc56fe17c8840db..24feead78cbfd4d66f3eb79728bce412638e18d4 100644 (file)
@@ -58,7 +58,11 @@ class WordMemory extends WordQuiz {
 
                let cards;
                if (this.words) {
-                       cards = this.words.splice(0, 6).map(row => row[2]);
+                       const formstyle = window.getComputedStyle(this.form)
+                       const gridsize = [
+                               formstyle['grid-template-rows'], formstyle['grid-template-columns']
+                       ].map(val => val.match(/ /g).length + 1).reduce((x, y) => x * y) / 2;
+                       cards = this.words.splice(0, gridsize || 6).map(row => row[2]);
                        cards.push(...cards.map(val => -val));
                }
                else {