From b435b79456db9c90c125f9e8a587b61fffad3213 Mon Sep 17 00:00:00 2001 From: Smoren Date: Sat, 13 Jul 2024 12:27:36 +0300 Subject: [PATCH] Random types count fix. --- .../components/widgets/randomize-config-snippets.vue | 2 +- src/web/components/config-editor/config-editor.vue | 7 ++++++- .../components/config-editor/hooks/use-right-bar.ts | 3 ++- src/web/store/config.ts | 10 +++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/web/components/config-editor/components/widgets/randomize-config-snippets.vue b/src/web/components/config-editor/components/widgets/randomize-config-snippets.vue index 9470f57..446ad07 100644 --- a/src/web/components/config-editor/components/widgets/randomize-config-snippets.vue +++ b/src/web/components/config-editor/components/widgets/randomize-config-snippets.vue @@ -22,7 +22,7 @@ const removeSnippet = (index: number) => { } const applySnippet = (config: RandomTypesConfig) => { console.log('APPLY', config); - configStore.setRandomTypesConfig(config); + configStore.setRandomTypesConfig(config, ['TYPES_COUNT']); } diff --git a/src/web/components/config-editor/config-editor.vue b/src/web/components/config-editor/config-editor.vue index 5329b48..e8b9b4e 100644 --- a/src/web/components/config-editor/config-editor.vue +++ b/src/web/components/config-editor/config-editor.vue @@ -18,9 +18,11 @@ import WorldConfigSection from '@/web/components/config-editor/components/sectio import SummarySection from "@/web/components/config-editor/components/sections/summary-section.vue"; import ExchangeSection from "@/web/components/config-editor/components/sections/exchange-section.vue"; import LinkSection from "@/web/components/config-editor/components/sections/link-section.vue"; +import { useConfigStore } from "@/web/store/config"; const leftBarVisible = useSwitch(false); const activeAccordionItem = ref('collapse-world'); +const configStore = useConfigStore(); const { rightBarVisible, @@ -29,7 +31,10 @@ const { toggleRightBar, } = useRightBar(); -provide<() => boolean>(PROVIDED_TOGGLE_RANDOMIZE_CONFIG, () => toggleRightBar(rightBarModeMap.RANDOMIZE)); +provide<() => boolean>( + PROVIDED_TOGGLE_RANDOMIZE_CONFIG, + () => toggleRightBar(rightBarModeMap.RANDOMIZE, () => configStore.syncRandomTypesCount()), +); provide<() => boolean>(PROVIDED_TOGGLE_SUMMARY, () => toggleRightBar(rightBarModeMap.SUMMARY)); diff --git a/src/web/components/config-editor/hooks/use-right-bar.ts b/src/web/components/config-editor/hooks/use-right-bar.ts index ed7a075..b8eeeae 100644 --- a/src/web/components/config-editor/hooks/use-right-bar.ts +++ b/src/web/components/config-editor/hooks/use-right-bar.ts @@ -10,10 +10,11 @@ export const useRightBar = () => { const rightBarMode: Ref = ref(rightBarModeMap.RANDOMIZE); - const toggleRightBar = (mode: number): boolean => { + const toggleRightBar = (mode: number, onOpen?: () => void): boolean => { if (mode !== rightBarMode.value || !rightBarVisible.state.value) { rightBarMode.value = mode; rightBarVisible.on(); + if (onOpen) onOpen(); return true; } else { rightBarVisible.off(); diff --git a/src/web/store/config.ts b/src/web/store/config.ts index 01efe42..03de3cb 100644 --- a/src/web/store/config.ts +++ b/src/web/store/config.ts @@ -92,13 +92,20 @@ export const useConfigStore = defineStore("config", () => { setWorldConfigRaw(newConfig); } - const setRandomTypesConfig = (newConfig: RandomTypesConfig) => { + const setRandomTypesConfig = (newConfig: RandomTypesConfig, excludeKeys: string[] = []) => { const buf = fullCopyObject(newConfig); for (const i in newConfig) { + if (excludeKeys.includes(i)) { + continue; + } (randomTypesConfig.value[i as keyof RandomTypesConfig] as number) = buf[i as keyof RandomTypesConfig] as number; } } + const syncRandomTypesCount = () => { + randomTypesConfig.value.TYPES_COUNT = typesConfig.value.FREQUENCIES.length; + } + const exportConfig = () => { return { worldConfig: worldConfigRaw, @@ -273,6 +280,7 @@ export const useConfigStore = defineStore("config", () => { randomizeTypesConfig, setDefaultTypesConfig, setRandomTypesConfig, + syncRandomTypesCount, appendType, addTypesFromConfig, removeTypeFromConfig,