From fc6ceb53c571ecc86148e54752f45acf6166df23 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 19 Feb 2021 20:20:51 -0500 Subject: Change error state to take message. Deselect nucleotide on error. --- genome.mjs | 6 +++++- rules.mjs | 38 +++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/genome.mjs b/genome.mjs index 3dd294f..680d2fa 100644 --- a/genome.mjs +++ b/genome.mjs @@ -80,8 +80,12 @@ class Genome { this.selectedNucleotide.deselect() } this._selectedNucleotide = nucleotide - this._selectedNucleotide.select() + if (nucleotide === undefined) { + return + } + + this._selectedNucleotide.select() let i = 0 for (const c of this.codons) { for (const b of c.bases) { diff --git a/rules.mjs b/rules.mjs index ac8d61b..9f6fb7d 100644 --- a/rules.mjs +++ b/rules.mjs @@ -68,9 +68,8 @@ class NucleotideSelect { handleClone(evt) { if (this.rules.die.value <= this.rules.currentGenome.length) { - this.rules.error.innerHTML = - `Select the ${this.ordinalFor(this.rules.die.value)} nucleotide.` - this.rules.next(new ShowError(this.rules, this)) + this.rules.next(new ShowError(this.rules, this, + `Select the ${this.ordinalFor(this.rules.die.value)} nucleotide.`)) return } @@ -86,14 +85,14 @@ class NucleotideSelect { handleSelectionChanged(nucleotide, i) { i++; if (this.rules.die.value > this.rules.currentGenome.length) { - this.rules.error.innerHTML = - `You need to clone this nucleotide.` - this.rules.next(new ShowError(this.rules, this)) + this.rules.currentGenome.selectedNucleotide = undefined + this.rules.next(new ShowError(this.rules, this, + `You need to clone this nucleotide.`)) return } else if (i != this.rules.die.value) { - this.rules.error.innerHTML = - `You selected the ${this.ordinalFor(i)} nucleotide. Please select the ${this.ordinalFor(this.want)} one.` - this.rules.next(new ShowError(this.rules, this)) + this.rules.currentGenome.selectedNucleotide = undefined + this.rules.next(new ShowError(this.rules, this, + `You selected the ${this.ordinalFor(i)} nucleotide. Please select the ${this.ordinalFor(this.want)} one.`)) return } this.rules.next(new RollForMutation(this.rules)) @@ -185,8 +184,7 @@ class PerformMutation { handleItemSelected(base) { if (!this.validMutation(this.selectedNucleotide.value, base)) { - this.rules.error.innerHTML = this.errorHTML - this.rules.next(new ShowError(this.rules, this)) + this.rules.next(new ShowError(this.rules, this, this.errorHTML)) return } @@ -227,9 +225,8 @@ class SelectAminoAcid { handleItemSelected(aminoAcid) { if (!this.validSelection(aminoAcid)) { - this.rules.error.innerHTML = - `The codon ${this.codon.value} does not code for ${aminoAcid}` - this.rules.next(new ShowError(this.rules, this)) + this.rules.next(new ShowError(this.rules, this, + `The codon ${this.codon.value} does not code for ${aminoAcid}`)) return } @@ -285,8 +282,7 @@ class MarkAsLethal { handleClone(evt) { if (this.isLethal) { - this.rules.error.innerHTML = this.lethalHTML - this.rules.next(new ShowError(this.rules, this)) + this.rules.next(new ShowError(this.rules, this, this.lethalHTML)) return } this.nextGoodState(this.rules.currentGenome) @@ -294,8 +290,7 @@ class MarkAsLethal { handleKill(evt) { if (!this.isLethal) { - this.rules.error.innerHTML = this.nonLethalHTML - this.rules.next(new ShowError(this.rules, this)) + this.rules.next(new ShowError(this.rules, this, this.nonLethalHTML)) return } this.nextGoodState(this.originalGenome) @@ -338,9 +333,10 @@ class PrintResults { } class ShowError { - constructor(rules, nextState) { + constructor(rules, nextState, message) { this.rules = rules this.nextState = nextState + this.rules.error.innerHTML = message this._boundClickHandler = this.clickHandler.bind(this) } @@ -445,8 +441,8 @@ class Rules { } _debugStartWithError() { - this.currentState = new ShowError(this, new RollForNucleotide(this)) - this.error.innerHTML = 'test an error' + this.currentState = new ShowError(this, new RollForNucleotide(this), + 'test an error') } get currentGenome() { -- cgit v1.2.3