word/finder: debug styling for extended levels
[sheet.git] / word / memory.js
index 89fd853c3cb89210c2a1d3e02e1b9fdaaaec2b55..a70ec06638ac20ce07a2ec60bc2aff3803617ff8 100644 (file)
@@ -41,30 +41,35 @@ class WordMemory extends WordQuiz {
                .forEach(card => put(card, '!.turn!.bad'));
        }
 
-       load(dataurl) {
-               if (dataurl) {
-                       super.load(dataurl);
-               }
-               else {
+       load() {
+               this.configure();
+               if (this.preset.pairs) {
                        this.dataurl = '/data/wordpairs.json';
                        fetch(this.dataurl).then(res => res.json()).then(pairs => {
                                this.pairs = pairs;
                                this.setup();
                        });
                }
+               else {
+                       super.load();
+               }
        }
 
        setup() {
+               super.setup();
                this.turned = [];
-               this.form = document.getElementById('quiz');
+               this.form.innerHTML = '';
+               this.form.className = '';
 
                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 {