+ }
+ else {
+ super.load();
+ }
+ }
+
+ setup() {
+ super.setup();
+ this.turned = [];
+ this.form.innerHTML = '';
+ this.form.className = '';
+
+ let cards;
+ if (this.words) {
+ 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.imgid);
+ cards.push(...cards.map(val => -val));
+ }
+ else {
+ cards = Object.entries(this.pairs).flat()
+ .map(e => e.toString())
+ }
+
+ cards.shuffle().forEach((word, seq) => {
+ let ref = Math.abs(word);
+ put(this.form,
+ 'figure>img[src=$]<', `/data/word/32/${ref}.jpg`, {
+ onclick: e => this.turn(e),
+ id: ref,
+ className: word < 0 ? 'mirror' : '',
+ index: seq,
+ }
+ );