unicode: one set of barb arrows from unicode 7.0
[sheet.git] / word / memory.js
index 94836c282b54666093c396631cc56fe17c8840db..89fd853c3cb89210c2a1d3e02e1b9fdaaaec2b55 100644 (file)
@@ -5,6 +5,7 @@ class WordMemory extends WordQuiz {
                        // show an open card
                        this.turned.push(target);
                        put(target, '.turn');
+                       this.log('pick', target.id, target.index);
                }
                else if (this.turned.length < 2) {
                        return; // keep open
@@ -30,6 +31,7 @@ class WordMemory extends WordQuiz {
                        this.turned = [];
                        if (Array.from(this.form.children).every(card => card.classList.contains('good'))) {
                                put(this.form, '.good');
+                               this.stop('done');
                        }
                        return;
                }
@@ -58,7 +60,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 {
@@ -66,11 +72,15 @@ class WordMemory extends WordQuiz {
                                .map(e => e.toString())
                }
 
-               cards.shuffle().forEach(word => {
+               cards.shuffle().forEach((word, seq) => {
                        let ref = Math.abs(word);
                        put(this.form,
-                               'figure>img[src=$]<', `/data/word/en/${ref}.jpg`,
-                               {onclick: e => this.turn(e), id: ref, className: word < 0 ? 'mirror' : ''}
+                               'figure>img[src=$]<', `/data/word/32/${ref}.jpg`, {
+                                       onclick: e => this.turn(e),
+                                       id: ref,
+                                       className: word < 0 ? 'mirror' : '',
+                                       index: seq,
+                               }
                        );
                });
        }