From 905f603e4fe58fbc588731c047ad52ec606a6174 Mon Sep 17 00:00:00 2001 From: Wojciech Polak Date: Thu, 11 Aug 2022 17:57:13 +0200 Subject: [PATCH] Creating Single Macros --- src/syrin/components/MacroManager.svelte | 31 ++---- src/syrin/components/Playlist.svelte | 4 +- .../components/macromanager/MMMood.svelte | 101 ++++++++++++++++++ .../components/macromanager/MMSoundset.svelte | 79 +++++--------- src/syrin/services/game.ts | 19 ++++ src/syrin/services/stores.ts | 12 ++- src/syrin/ui/macromanager.ts | 2 +- 7 files changed, 168 insertions(+), 80 deletions(-) create mode 100644 src/syrin/components/macromanager/MMMood.svelte diff --git a/src/syrin/components/MacroManager.svelte b/src/syrin/components/MacroManager.svelte index cdd54f0..9e9445b 100644 --- a/src/syrin/components/MacroManager.svelte +++ b/src/syrin/components/MacroManager.svelte @@ -95,10 +95,10 @@ let selectedMoods = Array.from(filteredSelectedSoundsets.values()) .filter((id) => id.includes(';')) .map((id) => id.split(';')); - const folder = await Folder.create({ - name: 'Syrinscape Soundsets', - type: 'Macro' - }); + // const folder = await Folder.create({ + // name: 'Syrinscape Soundsets', + // type: 'Macro' + // }); let folders = new Map(); for (const entry of selectedMoods) { const [soundsetId, moodId] = entry; @@ -112,26 +112,15 @@ ssFolder = await Folder.create({ name: soundset.name, type: 'Macro', - parent: folder.id + // parent: folder.id }); folders.set(soundset.id, ssFolder); } - const commandArg = JSON.stringify({ - soundset: { - id: soundset.id, - name: soundset.name - }, - mood: mood - }); - const macro = await Macro.create({ - name: mood.name, - type: 'script', - folder: ssFolder.id, - img: 'icons/svg/sound.svg', - command: 'game.syrinscape.playMood(' + commandArg + ')' - }); + ctx.game.createMoodMacro(soundset, mood, ssFolder.id); } - ctx.game.notifyInfo(`SyrinControl | Created macro folder "${folder.name}"`) + Array.from(folders.values()).forEach((folder) => { + ctx.game.notifyInfo(`SyrinControl | Created macro folder "${folder.name}"`) + }); } // Utils @@ -161,7 +150,7 @@ {#each soundsetsList as item, idx} - + {/each} diff --git a/src/syrin/components/Playlist.svelte b/src/syrin/components/Playlist.svelte index d180168..f4b1988 100644 --- a/src/syrin/components/Playlist.svelte +++ b/src/syrin/components/Playlist.svelte @@ -237,8 +237,8 @@ diff --git a/src/syrin/components/macromanager/MMMood.svelte b/src/syrin/components/macromanager/MMMood.svelte new file mode 100644 index 0000000..c3ce758 --- /dev/null +++ b/src/syrin/components/macromanager/MMMood.svelte @@ -0,0 +1,101 @@ + + + + + + + + + {mood.name} + + + + + + + + + + + diff --git a/src/syrin/components/macromanager/MMSoundset.svelte b/src/syrin/components/macromanager/MMSoundset.svelte index f1fd961..5cae451 100644 --- a/src/syrin/components/macromanager/MMSoundset.svelte +++ b/src/syrin/components/macromanager/MMSoundset.svelte @@ -3,6 +3,8 @@ import type { Mood, Soundset } from '@/models'; import Context from '@/services/context'; import Toggable from '@/components/Toggable.svelte'; + import MMMood from './MMMood.svelte'; + import { openElements } from '@/ui/elements'; // Context const ctx = Context(); @@ -18,6 +20,7 @@ let isSoundsetPartiallyChecked = false; let soundsetCheckboxTitle: string = ""; let soundsetButtonTitle: string = ""; + let loading = false; // Reactive Blocks const reactiveIsSoundsetChecked = (filteredSelectedSoundsets, item) => { @@ -34,16 +37,21 @@ const reactiveButtonTitle = (expanded, item) => { soundsetButtonTitle = (expanded ? 'Collapse: ' : 'Expand: ') + item.name; }; + const reactiveLoading = (item) => { + loading = false; + }; $: reactiveIsSoundsetChecked(filteredSelectedSoundsets, item); $: reactiveIsSoundsetPartiallyChecked(isSoundsetChecked, item, filteredSelectedSoundsets); $: reactiveSoundsetCheckboxTitle(isSoundsetChecked, item); $: reactiveButtonTitle(expanded, item); + $: reactiveLoading(item); // Event handlers function onExpand() { expanded = !expanded; if (expanded) { + loading = true; dispatcher('expand', item); } } @@ -61,34 +69,13 @@ dispatcher('expand', item); } - function onSelectMood(mood: Mood) { - const key = item.id + ';' + mood.id; - return function (event) { - if (event.target.checked) { - $managerApp.selectedSoundsets.add(key); - } else { - $managerApp.selectedSoundsets.delete(key); - } - $managerApp = $managerApp; - }; - } - - function onPlayMood(mood: Mood) { - if(mood === undefined || isPlaying(mood, $current.mood)) { - return async function () { - await ctx.syrin.stopAll(); - }; - } - return async function () { - await ctx.syrin.setMood(item, mood); - }; - } - // Utils - function isPlaying(m: Mood | undefined, current: Mood | undefined) { - if (!current) return false; - - return current?.id === m?.id; - } + async function onSoundsetElements() { + ctx.stores.elementsApp.update(p => { + p.addTab({ soundset: item, kind: 'soundset' }); + return p; + }); + openElements(ctx); + } @@ -104,41 +91,25 @@ {item.name} + {#if loading} + (Loading ...) + {/if} - + + + + + + {#if expanded} {#each item.moods as mood} - - - - - - - {mood.name} - - - - - - + {/each} {/if}