summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-02-19 20:20:51 -0500
committerBrian Cully <bjc@kublai.com>2021-02-19 20:20:51 -0500
commitfc6ceb53c571ecc86148e54752f45acf6166df23 (patch)
treed797f296cecb3fd64f65ccec22ba6e624508c92e
parent6fc5f812561ecd556d185084e2b9a611c5b9ccd8 (diff)
downloadmolsim2-fc6ceb53c571ecc86148e54752f45acf6166df23.tar.gz
molsim2-fc6ceb53c571ecc86148e54752f45acf6166df23.zip
Change error state to take message. Deselect nucleotide on error.
-rw-r--r--genome.mjs6
-rw-r--r--rules.mjs38
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 <em>clone</em> 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 <em>clone</em> 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 <strong>${this.codon.value}</strong> does not code for <strong>${aminoAcid}</strong>`
- this.rules.next(new ShowError(this.rules, this))
+ this.rules.next(new ShowError(this.rules, this,
+ `The codon <strong>${this.codon.value}</strong> does not code for <strong>${aminoAcid}</strong>`))
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() {