From 241aac94bd7647d8b8089d46bcf86cdeb4970b07 Mon Sep 17 00:00:00 2001 From: vzhang03 Date: Sun, 3 Nov 2024 23:21:54 -0500 Subject: [PATCH] Fixed mode three, removed unneccessary comments and slight logic changes --- packages/plugin-spr/src/index.ts | 53 ++++++++++---------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/packages/plugin-spr/src/index.ts b/packages/plugin-spr/src/index.ts index 300246b1..c23a2575 100644 --- a/packages/plugin-spr/src/index.ts +++ b/packages/plugin-spr/src/index.ts @@ -123,7 +123,6 @@ class SprPlugin implements JsPsychPlugin { private index: number = 0; private inner_index: number = -1; // mode 1-2: initialized so that not shown if has an inner_index private current_display_string: string[] = []; // mode 1-2: use this to save iterations - private displayed = false; // mode 3 private structured_reading_string: string[] | string[][] = []; private mode: 1 | 2 | 3; private results = []; @@ -141,6 +140,7 @@ class SprPlugin implements JsPsychPlugin { const blank = this.generateBlank(this.structured_reading_string[this.index]); document.querySelector("p")!.innerHTML = blank; this.addDataPoint(blank, this.index); + this.index = -1; // this initializes mode in way that allows to start at 0, might not be best way to do it } else document.querySelector("p")!.innerHTML = this.updateDisplayString(); // update this, passing null for TS } @@ -238,6 +238,13 @@ class SprPlugin implements JsPsychPlugin { newHtml = `

${this.updateDisplayString(info)}

`; } else if (this.mode === 3) { // might want to include incrementation here for consistency + this.index++; + + if (this.index >= this.structured_reading_string.length) { + this.endTrial(); + return; + } + newHtml = this.updateDisplayString(info); } // need to handle a keyboard press element where records how long until press a key @@ -286,48 +293,22 @@ class SprPlugin implements JsPsychPlugin { ""; this.addDataPoint(this.current_display_string.join(" "), this.index, info.key); - // this.results[this.results.length - 1].push( - // this.structured_reading_string[this.index][this.inner_index], - // this.getElapsed(), - // info.key - // ); - // this.results[this.results.length-1].push([this.getElapsed(), this.structured_reading_string[this.index][this.inner_index]]); } } else if (this.mode == 3) { var newHtml = ""; - if (!this.displayed) { - // accounts for bad user input (not necessary) and could move it up to input - if (typeof this.structured_reading_string[this.index] === "string") - newHtml = this.structured_reading_string[this.index] as string; - else { - for (const c of this.structured_reading_string[this.index]) { - newHtml += c + " "; - } + // accounts for bad user input (not necessary) and could move it up to input + if (typeof this.structured_reading_string[this.index] === "string") + newHtml = this.structured_reading_string[this.index] as string; + else { + for (const c of this.structured_reading_string[this.index]) { + newHtml += c + " "; } + } - newHtml = "

" + newHtml + "

"; - this.displayed = true; - - this.addDataPoint(newHtml, this.index, info.key); - console.log("this is info.key:", info.key, "this is new Html", newHtml); - // this.results.push([this.getElapsed(), newHtml, info.key]); // pushes new list with time passed (time looking at blank) - } else { - this.index++; - this.displayed = false; - - if (this.index >= this.structured_reading_string.length) { - this.endTrial(); - } else { - newHtml = - "

" + - this.generateBlank(this.structured_reading_string[this.index]) + - "

"; - } + newHtml = "

" + newHtml + "

"; - this.addDataPoint(newHtml, this.index, info.key); - // this.results[this.results.length - 1].push(this.getElapsed(), info.key); // pushes second time spent looking at word - } + this.addDataPoint(newHtml, this.index, info.key); return newHtml; }