From 3fd5bd838300fc44f33512241a2de3470c2542d4 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Mon, 2 Oct 2023 23:25:48 +0200 Subject: [PATCH] Add the possibility to load or not the demo songs --- index.html | 5 +++++ src/AppSettings.ts | 5 +++++ src/main.ts | 51 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index e658ccf..a905713 100644 --- a/index.html +++ b/index.html @@ -235,6 +235,11 @@ +
+ + +
+
diff --git a/src/AppSettings.ts b/src/AppSettings.ts index 3cd2908..ff6e7f2 100644 --- a/src/AppSettings.ts +++ b/src/AppSettings.ts @@ -53,6 +53,7 @@ export interface Settings { selected_universe: string; line_numbers: boolean; time_position: boolean; + load_demo_songs: boolean; tips: boolean; } @@ -122,6 +123,7 @@ export class AppSettings { public line_numbers: boolean = true; public time_position: boolean = true; public tips: boolean = true; + public load_demo_songs: boolean = true; constructor() { const settingsFromStorage = JSON.parse( @@ -139,6 +141,7 @@ export class AppSettings { this.line_numbers = settingsFromStorage.line_numbers; this.time_position = settingsFromStorage.time_position; this.tips = settingsFromStorage.tips; + this.load_demo_songs = settingsFromStorage.load_demo_songs; } else { this.universes = template_universes; } @@ -162,6 +165,7 @@ export class AppSettings { line_numbers: this.line_numbers, time_position: this.time_position, tips: this.tips, + load_demo_songs: this.load_demo_songs, }; } @@ -183,6 +187,7 @@ export class AppSettings { this.line_numbers = settings.line_numbers; this.time_position = settings.time_position; this.tips = settings.tips; + this.load_demo_songs = settings.load_demo_songs; localStorage.setItem("topos", JSON.stringify(this.data)); } } diff --git a/src/main.ts b/src/main.ts index ec39307..81dc2da 100644 --- a/src/main.ts +++ b/src/main.ts @@ -193,6 +193,11 @@ export class Editor { "show-tips" ) as HTMLInputElement; + // Loading demo songs when starting + load_demo_songs: HTMLInputElement = document.getElementById( + "load-demo-songs" + ) as HTMLInputElement; + // Editor mode selection normal_mode_button: HTMLButtonElement = document.getElementById( "normal-mode" @@ -225,18 +230,10 @@ export class Editor { public hydra: any = this.hydra_backend.synth; constructor() { - // ================================================================================ - // Loading the universe from local storage - // ================================================================================ - this.universes = { ...this.settings.universes, ...template_universes }; - this.selected_universe = "Welcome"; - this.universe_viewer.innerHTML = `Topos: ${this.selected_universe}`; - - // Picking a random example to populate the landing page - let random_example = examples[Math.floor(Math.random() * examples.length)]; - this.universes[this.selected_universe].global.committed = random_example; - this.universes[this.selected_universe].global.candidate = random_example; + // ================================================================================ + // Loading the settings + // ================================================================================ this.line_numbers_checkbox.checked = this.settings.line_numbers; this.time_position_checkbox.checked = this.settings.time_position; @@ -244,6 +241,29 @@ export class Editor { if (!this.settings.time_position) { document.getElementById("timeviewer")!.classList.add("hidden"); } + this.load_demo_songs.checked = this.settings.load_demo_songs; + + // ================================================================================ + // Loading the universe from local storage + // ================================================================================ + + this.universes = { + ...this.settings.universes, + ...template_universes + }; + + if (this.settings.load_demo_songs) { + let random_example = examples[Math.floor(Math.random() * examples.length)]; + this.selected_universe = "Welcome" + this.universes[this.selected_universe].global.committed = random_example; + this.universes[this.selected_universe].global.candidate = random_example; + } else { + this.selected_universe = this.settings.selected_universe; + if (this.universes[this.selected_universe] === undefined) + this.universes[this.selected_universe] = structuredClone(template_universe) + } + this.universe_viewer.innerHTML = `Topos: ${this.selected_universe}`; + // ================================================================================ // Audio context and clock @@ -499,7 +519,7 @@ export class Editor { button.addEventListener("click", () => { this.setButtonHighlighting("clear", true); if (confirm("Do you want to reset the current universe?")) { - this.universes[this.selected_universe] = template_universe; + this.universes[this.selected_universe] = structuredClone(template_universe); this.updateEditorView(); } }); @@ -559,6 +579,7 @@ export class Editor { this.line_numbers_checkbox.checked = this.settings.line_numbers; this.time_position_checkbox.checked = this.settings.time_position; this.tips_checkbox.checked = this.settings.tips; + this.load_demo_songs.checked = this.settings.load_demo_songs; if (this.settings.vimMode) { let vim = document.getElementById("vim-mode-radio") as HTMLInputElement; @@ -654,6 +675,12 @@ export class Editor { }); }); + this.load_demo_songs.addEventListener("change", () => { + let checked = this.load_demo_songs.checked ? true : false; + this.settings.load_demo_songs = checked; + }); + + this.vim_mode_button.addEventListener("click", () => { this.settings.vimMode = true; this.view.dispatch({