From 901be28658b82ed11c4943cbf8a88ebdbb633c21 Mon Sep 17 00:00:00 2001 From: Samuel Gfeller Date: Wed, 6 Mar 2024 11:50:43 +0100 Subject: [PATCH] Added random selection when both patterns selected [SG-122] --- index.php | 2 +- src/assets/styles/style.css | 14 +++++- .../configuration/mic-sensitivity-option.js | 2 +- src/components/game-core/ui/note-displayer.js | 2 +- .../roadmap-selector/fret-pattern-selector.js | 8 +-- .../note-on-fretboard-generator.js | 4 +- .../note-on-fretboard-note-handler.js | 10 ++-- .../note-on-fretboard-progress-updater.js | 2 +- .../note-on-fretboard/range-selector.js | 6 +-- .../detected-note/detected-note-verifier.js | 4 +- .../frequency-bars-controller.js | 2 +- .../core-game-coordination-initializer.js | 12 ++--- .../game-configuration-manager.js | 2 +- .../game-initialization/game-initializer.js | 8 +-- src/features/game-core/game-loader.js | 2 +- .../game-progress/game-progress-updater.js | 2 +- .../game-start/core-game-coordinator.js | 10 ++-- .../game-ui/game-elements-visualizer.js | 2 +- .../game-core/game-ui/level-up-visualizer.js | 2 +- .../metronome-practice-coordinator.js | 4 +- .../metronome-practice-initializer.js | 6 +-- .../note-in-key-game-coordinator.js | 7 ++- .../note-in-key-game-initializer.js | 40 ++++++++------- .../note-in-key/note-in-key-game-no-guitar.js | 2 +- .../note-in-key/note-in-key-generator.js | 49 +++++++++++++------ .../fretboard-note-game-coordinator.js | 4 +- .../note-on-fretboard-event-handler.js | 6 +-- .../note-on-fretboard-event-listener-adder.js | 6 +-- .../note-on-fretboard-game-initializer.js | 10 ++-- .../note-in-key-note-handler.js | 6 +-- 30 files changed, 135 insertions(+), 101 deletions(-) diff --git a/index.php b/index.php index e21807f..0eb56a3 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ { + // If both are checked, it defaults to the first one const checkedPatternInput = document.querySelector('.custom-pattern-option input[type="checkbox"]:checked'); let fretboardNr = 1; if (checkedPatternInput) { diff --git a/src/features/game-modes/note-in-key/note-in-key-game-no-guitar.js b/src/features/game-modes/note-in-key/note-in-key-game-no-guitar.js index 9587cd5..f7cbc52 100644 --- a/src/features/game-modes/note-in-key/note-in-key-game-no-guitar.js +++ b/src/features/game-modes/note-in-key/note-in-key-game-no-guitar.js @@ -1,4 +1,4 @@ -import {GameProgressVisualizer} from "../../game-core/game-progress/game-progress-visualizer.js?v=2.1.6"; +import {GameProgressVisualizer} from "../../game-core/game-progress/game-progress-visualizer.js?v=2.2.0"; export class NoteInKeyGameNoGuitar { static diatonicNotesOnStrings; diff --git a/src/features/game-modes/note-in-key/note-in-key-generator.js b/src/features/game-modes/note-in-key/note-in-key-generator.js index 12a532b..e28573d 100644 --- a/src/features/game-modes/note-in-key/note-in-key-generator.js +++ b/src/features/game-modes/note-in-key/note-in-key-generator.js @@ -1,9 +1,9 @@ -import {ArrayShuffler} from "../../../components/shuffler/array-shuffler.js?v=2.1.6"; +import {ArrayShuffler} from "../../../components/shuffler/array-shuffler.js?v=2.2.0"; import { availableNotesOnStrings, pattern1keyNote, pattern2keyNote -} from "../../../components/configuration/config-data.js?v=2.1.6"; +} from "../../../components/configuration/config-data.js?v=2.2.0"; export class NoteInKeyGenerator { diatonicNotesOnStrings; @@ -13,6 +13,8 @@ export class NoteInKeyGenerator { shuffledCombinations; // Index of the current combination to be displayed from the shuffledCombinations array currentIndex = 0; + // Both patterns can be selected or only one. + selectedFretboardPattern = null; constructor() { } @@ -108,6 +110,8 @@ export class NoteInKeyGenerator { // Fill the combinationsToBeShuffled array with all possible combinations this.createArrayWithCombinationsToBeShuffled(); + // Reset currentIndex + this.currentIndex = 0; // Shuffle the array with the combinations this.shuffledCombinations = ArrayShuffler.shuffleArray(this.combinationsToBeShuffled, [keyString, keyNote]); } @@ -123,14 +127,25 @@ export class NoteInKeyGenerator { } /** - * @return {number|boolean} + * @return {number|boolean|null} */ getSelectedFretboardNr() { - const checkedPatternOption = document.querySelector('.custom-pattern-option input[type="checkbox"]:checked'); - if (!checkedPatternOption) { + console.log('selectedFretboardPattern', this.selectedFretboardPattern); + if (this.selectedFretboardPattern) { + return this.selectedFretboardPattern; + } + + const checkedPatternOptions = document.querySelectorAll('.custom-pattern-option input[type="checkbox"]:checked'); + if (!checkedPatternOptions) { return false; } - return parseInt(checkedPatternOption.dataset.fretboardNr); + + // If multiple checkedPatternOptions, return randomly the 1 or 2, if only one, return that one + const checkedPatternOption = + checkedPatternOptions.length === 1 ? checkedPatternOptions[0] : checkedPatternOptions[Math.floor(Math.random() * 2)]; + + this.selectedFretboardPattern = parseInt(checkedPatternOption.dataset.fretboardNr); + return this.selectedFretboardPattern; } /** @@ -204,19 +219,21 @@ export class NoteInKeyGenerator { getNextCombination() { + // Error below should be fixed with currentIndex reset in loadShuffledCombinations() + // Sometimes there is a bug after a few rounds where only the number 1 is displayed + // The error line 81 is Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) + // Either the shuffledCombinations is undefined or the shuffledCombinations[currentIndex] is undefined + console.log('currentIndex: ' + this.currentIndex, 'shuffledCombinations: ' + this.shuffledCombinations + + 'shuffledCombinations[currentIndex]' + this.shuffledCombinations[this.currentIndex]); + // If this.shuffledCombinations[this.currentIndex] is undefined, inform user with alert + if (this.currentIndex === undefined || !this.shuffledCombinations[this.currentIndex]) { + alert('There was an error and I don\'t know how to reproduce it. ' + + 'Please reload the page. ' + "\n" + 'currentIndex: ' + this.currentIndex + + ' | shuffledCombinations[currentIndex]: ' + this.shuffledCombinations[this.currentIndex]); + } // The note shuffler returns a string with the format 'string|note' let [string, note] = this.shuffledCombinations[this.currentIndex]; - /*Sometimes there is a bug after a few rounds where only the number 1 is displayed - The error line 81 is Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) - Either the shuffledCombinations is undefined or the shuffledCombinations[currentIndex] is undefined - console.log('currentIndex: ' + this.currentIndex, 'shuffledCombinations[currentIndex]' + this.shuffledCombinations[this.currentIndex]); - If this.shuffledCombinations[this.currentIndex] is undefined, inform user with alert - if (this.currentIndex === undefined || !this.shuffledCombinations[this.currentIndex]) { - alert('There was an error. Please reload the page. ' + "\n" + 'currentIndex: ' + this.currentIndex +' | shuffledCombinations[currentIndex]: ' + this.shuffledCombinations[this.currentIndex]); - }*/ - // bug above fixed by setting it to null if this.shuffledCombinations[this.currentIndex] is invalid - // If the current index is reached, re shuffle all the notes and reset it to 0 if (this.currentIndex >= this.shuffledCombinations.length - 1 || !this.shuffledCombinations[this.currentIndex]) { const previousCombination = this.shuffledCombinations[this.currentIndex]; diff --git a/src/features/game-modes/note-on-fretboard/fretboard-note-game-coordinator.js b/src/features/game-modes/note-on-fretboard/fretboard-note-game-coordinator.js index a246d2b..efcb5e7 100644 --- a/src/features/game-modes/note-on-fretboard/fretboard-note-game-coordinator.js +++ b/src/features/game-modes/note-on-fretboard/fretboard-note-game-coordinator.js @@ -1,7 +1,7 @@ import { NoteOnFretboardNoteHandler -} from "../../../components/game-modes/note-on-fretboard/note-on-fretboard-note-handler.js?v=2.1.6"; -import {NoteOnFretboardGameInitializer} from "./initialization/note-on-fretboard-game-initializer.js?v=2.1.6"; +} from "../../../components/game-modes/note-on-fretboard/note-on-fretboard-note-handler.js?v=2.2.0"; +import {NoteOnFretboardGameInitializer} from "./initialization/note-on-fretboard-game-initializer.js?v=2.2.0"; /** * Game mode "note-on-fretboard" core logic diff --git a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-handler.js b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-handler.js index ff7ceab..7f73160 100644 --- a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-handler.js +++ b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-handler.js @@ -1,6 +1,6 @@ -import {GameLevelTracker} from "../../../game-core/game-progress/game-level-tracker.js?v=2.1.6"; -import {GameElementsVisualizer} from "../../../game-core/game-ui/game-elements-visualizer.js?v=2.1.6"; -import {LevelUpVisualizer} from "../../../game-core/game-ui/level-up-visualizer.js?v=2.1.6"; +import {GameLevelTracker} from "../../../game-core/game-progress/game-level-tracker.js?v=2.2.0"; +import {GameElementsVisualizer} from "../../../game-core/game-ui/game-elements-visualizer.js?v=2.2.0"; +import {LevelUpVisualizer} from "../../../game-core/game-ui/level-up-visualizer.js?v=2.2.0"; export class NoteOnFretboardEventHandler{ diff --git a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-listener-adder.js b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-listener-adder.js index 8b015b3..5e11ce2 100644 --- a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-listener-adder.js +++ b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-event-listener-adder.js @@ -1,6 +1,6 @@ -import {GameProgressVisualizer} from "../../../game-core/game-progress/game-progress-visualizer.js?v=2.1.6"; -import {NoteOnFretboardEventHandler} from "./note-on-fretboard-event-handler.js?v=2.1.6"; -import {RangeSelector} from "../../../../components/game-modes/note-on-fretboard/range-selector.js?v=2.1.6"; +import {GameProgressVisualizer} from "../../../game-core/game-progress/game-progress-visualizer.js?v=2.2.0"; +import {NoteOnFretboardEventHandler} from "./note-on-fretboard-event-handler.js?v=2.2.0"; +import {RangeSelector} from "../../../../components/game-modes/note-on-fretboard/range-selector.js?v=2.2.0"; export class NoteOnFretboardEventListenerAdder { diff --git a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-game-initializer.js b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-game-initializer.js index bf65d25..d4fd34c 100644 --- a/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-game-initializer.js +++ b/src/features/game-modes/note-on-fretboard/initialization/note-on-fretboard-game-initializer.js @@ -1,8 +1,8 @@ -import {BpmInput} from "../../../../components/configuration/bpm-input.js?v=2.1.6"; -import {GameConfigurationManager} from "../../../game-core/game-initialization/game-configuration-manager.js?v=2.1.6"; -import {availableNotesOnStrings} from "../../../../components/configuration/config-data.js?v=2.1.6"; -import {GameLevelTracker} from "../../../game-core/game-progress/game-level-tracker.js?v=2.1.6"; -import {NoteOnFretboardEventListenerAdder} from "./note-on-fretboard-event-listener-adder.js?v=2.1.6"; +import {BpmInput} from "../../../../components/configuration/bpm-input.js?v=2.2.0"; +import {GameConfigurationManager} from "../../../game-core/game-initialization/game-configuration-manager.js?v=2.2.0"; +import {availableNotesOnStrings} from "../../../../components/configuration/config-data.js?v=2.2.0"; +import {GameLevelTracker} from "../../../game-core/game-progress/game-level-tracker.js?v=2.2.0"; +import {NoteOnFretboardEventListenerAdder} from "./note-on-fretboard-event-listener-adder.js?v=2.2.0"; export class NoteOnFretboardGameInitializer { diff --git a/src/features/practice-note-combination/note-in-key-note-handler.js b/src/features/practice-note-combination/note-in-key-note-handler.js index 11f0433..66089eb 100644 --- a/src/features/practice-note-combination/note-in-key-note-handler.js +++ b/src/features/practice-note-combination/note-in-key-note-handler.js @@ -1,6 +1,6 @@ -import {DetectedNoteVerifier} from "../detected-note/detected-note-verifier.js?v=2.1.6"; -import {GameProgressVisualizer} from "../game-core/game-progress/game-progress-visualizer.js?v=2.1.6"; -import {NoteDisplayer} from "../../components/game-core/ui/note-displayer.js?v=2.1.6"; +import {DetectedNoteVerifier} from "../detected-note/detected-note-verifier.js?v=2.2.0"; +import {GameProgressVisualizer} from "../game-core/game-progress/game-progress-visualizer.js?v=2.2.0"; +import {NoteDisplayer} from "../../components/game-core/ui/note-displayer.js?v=2.2.0"; /** * Note displayer for "practice" mode, which means