X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/a3c116952bbc2bfc1b77d8814637a36ed76883c3..9b8d7e610cef31f15f12c1058dfd45efffac5fb0:/word/memory.js diff --git a/word/memory.js b/word/memory.js index 24feead..dfbb8a6 100644 --- a/word/memory.js +++ b/word/memory.js @@ -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,11 +60,13 @@ class WordMemory extends WordQuiz { let cards; if (this.words) { - 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]); + const aspect = this.form.clientWidth / window.innerHeight; + //TODO image ratio + let count = parseInt(this.preset.n) || 35; + let cols = Math.round(Math.sqrt(count) * aspect**.5); + count = cols * Math.ceil(count / cols); + this.form.style['grid-template-columns'] = `repeat(${cols}, 1fr)`; + cards = this.words.splice(0, count>>1).map(row => row[2]); cards.push(...cards.map(val => -val)); } else { @@ -70,11 +74,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, + } ); }); }