summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-02-19 09:56:03 -0500
committerBrian Cully <bjc@kublai.com>2021-02-19 09:56:03 -0500
commitfc3f9feeddd755d357fa76a28ce5d4a327e0c2e1 (patch)
tree2b26bac2e67711406192612df6596cd8841ba90a
parent335ef36746c30d80f2b979050bfd40a70d4be44b (diff)
downloadmolsim2-fc3f9feeddd755d357fa76a28ce5d4a327e0c2e1.tar.gz
molsim2-fc3f9feeddd755d357fa76a28ce5d4a327e0c2e1.zip
Get nucleotide selection working again.
-rw-r--r--genome.mjs32
-rw-r--r--rules.mjs4
2 files changed, 25 insertions, 11 deletions
diff --git a/genome.mjs b/genome.mjs
index 581e9a8..7303b40 100644
--- a/genome.mjs
+++ b/genome.mjs
@@ -5,8 +5,6 @@ import { randomItem } from './utils.mjs'
class Genome {
constructor(nucleotides) {
const codonList = document.createElement('ol')
- this._boundNucleotideClickedHandler =
- this.nucleotideClickedHandler.bind(this)
this.codons = []
let tmpCodon = []
@@ -20,7 +18,15 @@ class Genome {
}
})
this.elt.appendChild(codonList)
+
this.lock()
+ this._boundNucleotideClickedHandler =
+ this.nucleotideClickedHandler.bind(this)
+ this.codons.forEach(c => {
+ c.bases.forEach(b => {
+ b.onClick = this._boundNucleotideClickedHandler
+ })
+ })
}
get elt() {
@@ -31,15 +37,15 @@ class Genome {
return this._elt
}
- get onSelectionChanged() {
- if (this._onSelectionChanged !== undefined) {
- return this._onSelectionChanged
+ get onNucleotideSelectionChanged() {
+ if (this._onNucleotideSelectionChanged !== undefined) {
+ return this._onNucleotideSelectionChanged
}
return () => {}
}
- set onSelectionChanged(fn) {
- this._onSelectionChanged = fn
+ set onNucleotideSelectionChanged(fn) {
+ this._onNucleotideSelectionChanged = fn
}
lock() {
@@ -67,8 +73,16 @@ class Genome {
this._selectedNucleotide = nucleotide
this._selectedNucleotide.select()
- const i = this.nucleotides.indexOf(this._selectedNucleotide)
- this.onSelectionChanged(this._selectedNucleotide, i)
+ let i = 0
+ for (const c of this.codons) {
+ for (const b of c.bases) {
+ if (b === this._selectedNucleotide) {
+ this.onNucleotideSelectionChanged(this._selectedNucleotide, i)
+ return
+ }
+ i++
+ }
+ }
}
nucleotideClickedHandler(nucleotide) {
diff --git a/rules.mjs b/rules.mjs
index f726a5a..8f038bc 100644
--- a/rules.mjs
+++ b/rules.mjs
@@ -77,14 +77,14 @@ class NucleotideSelect {
this.rules.instructions.querySelector('#select-number').innerHTML =
`${this.want}<sup>${ordinalSuffix(this.want)}</sup>`
- this.rules.currentGenome.onSelectionChanged =
+ this.rules.currentGenome.onNucleotideSelectionChanged =
this.handleSelectionChanged.bind(this)
this.rules.currentGenome.unlock()
}
exit() {
this.rules.currentGenome.lock()
- this.rules.currentGenome.onSelectionChanged = undefined;
+ this.rules.currentGenome.onNucleotideSelectionChanged = undefined;
}
handleSelectionChanged(nucleotide, i) {