From 256fd05e012d5825a50368878d1c7f1c8feabfd8 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 6 Feb 2021 13:41:35 -0500 Subject: whitespace --- error.mjs | 16 ++-- nucleotide.mjs | 38 ++++----- rules.mjs | 252 ++++++++++++++++++++++++++++----------------------------- 3 files changed, 153 insertions(+), 153 deletions(-) diff --git a/error.mjs b/error.mjs index 0c12f0e..535a956 100644 --- a/error.mjs +++ b/error.mjs @@ -2,8 +2,8 @@ class Error { constructor(elt) { this.elt = elt - this._boundClickHandler = this.clickHandler.bind(this) - this.button.addEventListener('click', this._boundClickHandler) + this._boundClickHandler = this.clickHandler.bind(this) + this.button.addEventListener('click', this._boundClickHandler) } get errorElt() { @@ -30,21 +30,21 @@ class Error { get onClick() { if (this._onClick !== undefined) { - return this._onClick - } - return () => {} + return this._onClick + } + return () => {} } set onClick(fn) { - this._onClick = fn + this._onClick = fn } show() { - this.elt.classList.remove('hidden') + this.elt.classList.remove('hidden') } hide() { - this.elt.classList.add('hidden') + this.elt.classList.add('hidden') } clickHandler() { diff --git a/nucleotide.mjs b/nucleotide.mjs index e646efc..13ed1b6 100644 --- a/nucleotide.mjs +++ b/nucleotide.mjs @@ -7,46 +7,46 @@ class Nucleotide { } get elt() { - if (this._elt === undefined) { - this._elt = document.createElement('li') - this._elt.classList.add('nucleotide') - } - return this._elt + if (this._elt === undefined) { + this._elt = document.createElement('li') + this._elt.classList.add('nucleotide') + } + return this._elt } get valueElt() { - if (this._valueElt === undefined) { - this._valueElt = document.createElement('span') - this.elt.appendChild(this._valueElt) - } - return this._valueElt + if (this._valueElt === undefined) { + this._valueElt = document.createElement('span') + this.elt.appendChild(this._valueElt) + } + return this._valueElt } get value() { - return this.valueElt.innerText + return this.valueElt.innerText } set value(val) { - this.valueElt.innerText = val + this.valueElt.innerText = val } get onClick() { - if (this._onClick !== undefined) { - return this._onClick - } - return () => {} + if (this._onClick !== undefined) { + return this._onClick + } + return () => {} } set onClick(fn) { - this._onClick = fn + this._onClick = fn } lock() { - this.elt.removeEventListener('click', this._boundClickHandler) + this.elt.removeEventListener('click', this._boundClickHandler) } unlock() { - this.elt.addEventListener('click', this._boundClickHandler) + this.elt.addEventListener('click', this._boundClickHandler) } select() { diff --git a/rules.mjs b/rules.mjs index 48f51dd..d397bf0 100644 --- a/rules.mjs +++ b/rules.mjs @@ -8,263 +8,263 @@ import Error from './error.mjs' class CloneNucleotide { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'clone-nucleotide' - this._boundClickHandler = this.clickHandler.bind(this) + this._boundClickHandler = this.clickHandler.bind(this) } enter() { - this.rules.cloneButton.addEventListener('click', - this._boundClickHandler) - this.rules.cloneButton.disabled = false + this.rules.cloneButton.addEventListener('click', + this._boundClickHandler) + this.rules.cloneButton.disabled = false } exit() { - this.rules.cloneButton.removeEventListener('click', - this._boundClickHandler) - this.rules.cloneButton.disabled = true + this.rules.cloneButton.removeEventListener('click', + this._boundClickHandler) + this.rules.cloneButton.disabled = true } clickHandler(evt) { - const genome = this.rules.currentGenome.clone() - this.rules.genomeList.push(genome) - this.rules.next(new RollForNucleotide(this.rules)) + const genome = this.rules.currentGenome.clone() + this.rules.genomeList.push(genome) + this.rules.next(new RollForNucleotide(this.rules)) } } class RollForNucleotide { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'roll-for-nucleotide' } enter() { - this.rules.die.value = '--' - this.rules.die.onChanged = this.handleDieRoll.bind(this) - this.rules.die.enable() + this.rules.die.value = '--' + this.rules.die.onChanged = this.handleDieRoll.bind(this) + this.rules.die.enable() } exit() { - this.rules.die.disable() - this.rules.die.onChanged = undefined + this.rules.die.disable() + this.rules.die.onChanged = undefined } handleDieRoll() { - if (this.rules.die.value > Genome.size) { - this.rules.iterations-- - if (this.rules.isLastIteration) { - this.rules.next(new DoNothing(this.rules)) - } else { - this.rules.next(new CloneNucleotide(this.rules)) - } - } else { - this.rules.next(new NucleotideSelect(this.rules)) - } + if (this.rules.die.value > Genome.size) { + this.rules.iterations-- + if (this.rules.isLastIteration) { + this.rules.next(new DoNothing(this.rules)) + } else { + this.rules.next(new CloneNucleotide(this.rules)) + } + } else { + this.rules.next(new NucleotideSelect(this.rules)) + } } } class NucleotideSelect { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'nucleotide-select' } enter() { - this.want = this.rules.die.value - this.rules.instructions.querySelector('#select-number').innerHTML = - `${this.want}${ordinalSuffix(this.want)}` + this.want = this.rules.die.value + this.rules.instructions.querySelector('#select-number').innerHTML = + `${this.want}${ordinalSuffix(this.want)}` - this.rules.currentGenome.onSelectionChanged = - this.handleSelectionChanged.bind(this) - this.rules.currentGenome.unlock() + this.rules.currentGenome.onSelectionChanged = + this.handleSelectionChanged.bind(this) + this.rules.currentGenome.unlock() } exit() { - this.rules.currentGenome.lock() - this.rules.currentGenome.onSelectionChanged = undefined; + this.rules.currentGenome.lock() + this.rules.currentGenome.onSelectionChanged = undefined; } handleSelectionChanged(nucleotide, i) { - i++; - if (i != this.rules.die.value) { - this.rules.error.innerHTML = - `You selected the ${i}${ordinalSuffix(i)} nucleotide. Please select the ${this.want}${ordinalSuffix(this.want)} one.` - this.rules.next(new ShowError(this.rules, this)) - return - } - this.rules.next(new RollForMutation(this.rules)) + i++; + if (i != this.rules.die.value) { + this.rules.error.innerHTML = + `You selected the ${i}${ordinalSuffix(i)} nucleotide. Please select the ${this.want}${ordinalSuffix(this.want)} one.` + this.rules.next(new ShowError(this.rules, this)) + return + } + this.rules.next(new RollForMutation(this.rules)) } } class RollForMutation { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'roll-for-mutation' } enter() { - this.rules.die.value = '--' - this.rules.die.onChanged = this.handleDieRoll.bind(this) - this.rules.die.enable() + this.rules.die.value = '--' + this.rules.die.onChanged = this.handleDieRoll.bind(this) + this.rules.die.enable() } exit() { - this.rules.die.disable() - this.rules.die.onChanged = undefined + this.rules.die.disable() + this.rules.die.onChanged = undefined } handleDieRoll() { - this.rules.next(new PerformMutation(this.rules)) + this.rules.next(new PerformMutation(this.rules)) } } class PerformMutation { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'perform-mutation' } enter() { - const selector = this.rules.nucleotideSelector - selector.onItemSelected = this.handleItemSelected.bind(this) - selector.attach(this.selectedNucleotide) + const selector = this.rules.nucleotideSelector + selector.onItemSelected = this.handleItemSelected.bind(this) + selector.attach(this.selectedNucleotide) } exit() { - this.rules.nucleotideSelector.detach() + this.rules.nucleotideSelector.detach() } validMutation(from, to) { - return to == this.expectedMutation[from] + return to == this.expectedMutation[from] } get expectedMutation() { - if (this.rules.die.value <= 14) { - return Nucleotide.transition - } else if (this.rules.die.value <= 17) { - return Nucleotide.complementingTransversion - } else { - return Nucleotide.defaultTransversion - } + if (this.rules.die.value <= 14) { + return Nucleotide.transition + } else if (this.rules.die.value <= 17) { + return Nucleotide.complementingTransversion + } else { + return Nucleotide.defaultTransversion + } } get selectedNucleotide() { - return this.rules.currentGenome.selectedNucleotide + return this.rules.currentGenome.selectedNucleotide } get errorTransitionHTML() { - return `Select the base that corresponds to a transition of ${this.selectedNucleotide.value}.` + return `Select the base that corresponds to a transition of ${this.selectedNucleotide.value}.` } get errorComplementingTransversionHTML() { - return `Select the base that corresponds to a complementing transversion of ${this.selectedNucleotide.value}.` + return `Select the base that corresponds to a complementing transversion of ${this.selectedNucleotide.value}.` } get errorDefaultTransversionHTML() { - return `Select the base that corresponds to the other transversion of ${this.selectedNucleotide.value}.` + return `Select the base that corresponds to the other transversion of ${this.selectedNucleotide.value}.` } get errorHTML() { - if (this.expectedMutation == Nucleotide.transition) { - return this.errorTransitionHTML - } else if (this.expectedMutation == Nucleotide.complementingTransversion) { - return this.errorComplementingTransversionHTML - } else { - return this.errorDefaultTransversionHTML - } + if (this.expectedMutation == Nucleotide.transition) { + return this.errorTransitionHTML + } else if (this.expectedMutation == Nucleotide.complementingTransversion) { + return this.errorComplementingTransversionHTML + } else { + return this.errorDefaultTransversionHTML + } } handleItemSelected(base) { - if (!this.validMutation(this.selectedNucleotide.value, base)) { - this.rules.error.innerHTML = this.errorHTML - this.rules.next(new ShowError(this.rules, this)) - return - } - - this.selectedNucleotide.value = base - this.rules.iterations-- - if (this.rules.isLastIteration) { - this.rules.next(new DoNothing(this.rules)) - } else { - this.rules.next(new CloneNucleotide(this.rules)) - } + if (!this.validMutation(this.selectedNucleotide.value, base)) { + this.rules.error.innerHTML = this.errorHTML + this.rules.next(new ShowError(this.rules, this)) + return + } + + this.selectedNucleotide.value = base + this.rules.iterations-- + if (this.rules.isLastIteration) { + this.rules.next(new DoNothing(this.rules)) + } else { + this.rules.next(new CloneNucleotide(this.rules)) + } } } class DoNothing { constructor(rules) { - this.rules = rules + this.rules = rules this.id = 'print-results' - this._boundClickHandler = this.clickHandler.bind(this) + this._boundClickHandler = this.clickHandler.bind(this) } enter() { - this.rules.printButton.addEventListener('click', this._boundClickHandler) - this.rules.printButton.disabled = false + this.rules.printButton.addEventListener('click', this._boundClickHandler) + this.rules.printButton.disabled = false } exit() { - this.rules.printButton.disabled = true - this.rules.printButton.removeEventListener('click', this._boundClickHandler) + this.rules.printButton.disabled = true + this.rules.printButton.removeEventListener('click', this._boundClickHandler) } clickHandler() { - window.print() + window.print() } } class ShowError { constructor(rules, nextState) { - this.rules = rules - this.nextState = nextState + this.rules = rules + this.nextState = nextState - this._boundClickHandler = this.clickHandler.bind(this) + this._boundClickHandler = this.clickHandler.bind(this) } enter() { - this.rules.error.onClick = this._boundClickHandler - this.rules.error.show() + this.rules.error.onClick = this._boundClickHandler + this.rules.error.show() } exit() { - this.rules.error.hide() - this.rules.error.onClick = undefined + this.rules.error.hide() + this.rules.error.onClick = undefined } clickHandler() { - this.rules.next(this.nextState) + this.rules.next(this.nextState) } } class Rules { constructor(die, instructions, genomeList, nucleotideSelector, cloneButton, remainingIterations, printButton, errors) { - this.die = new Die(die) - this.instructions = instructions - this.genomeList = new GenomeList(genomeList) - this.nucleotideSelector = new NucleotideSelector(nucleotideSelector) - this.cloneButton = cloneButton - this.remainingIterations = remainingIterations - this.printButton = printButton - this.error = new Error(errors) - - this.iterations = Rules.maxIterations - this.cloneButton.disabled = true - this.genomeList.push(new Genome(Rules.initialGenomeBases)) - - if (false) { - this._debugStartAtRollForMutation() - } else if (false) { - this._debugStartAtPerformMutation(4) - } else if (false) { - this._debugStartWithError() - } else { - this.currentState = new CloneNucleotide(this) - } - this.enterState() + this.die = new Die(die) + this.instructions = instructions + this.genomeList = new GenomeList(genomeList) + this.nucleotideSelector = new NucleotideSelector(nucleotideSelector) + this.cloneButton = cloneButton + this.remainingIterations = remainingIterations + this.printButton = printButton + this.error = new Error(errors) + + this.iterations = Rules.maxIterations + this.cloneButton.disabled = true + this.genomeList.push(new Genome(Rules.initialGenomeBases)) + + if (false) { + this._debugStartAtRollForMutation() + } else if (false) { + this._debugStartAtPerformMutation(4) + } else if (false) { + this._debugStartWithError() + } else { + this.currentState = new CloneNucleotide(this) + } + this.enterState() } get iterations() { -- cgit v1.2.3