From 80ccfcc08d74fd13300c2c00daecc0707d25569c Mon Sep 17 00:00:00 2001 From: Smoren Date: Mon, 29 Apr 2024 20:45:20 +0300 Subject: [PATCH] Refactor and fix complete. --- .../sections/initial-config-section.vue | 17 +++++++++--- .../sections/randomize-config-section.vue | 2 +- src/store/config.ts | 26 ------------------- src/store/simulation.ts | 6 ----- 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/components/config-editor/components/sections/initial-config-section.vue b/src/components/config-editor/components/sections/initial-config-section.vue index a5ea98d..c6e4b6c 100644 --- a/src/components/config-editor/components/sections/initial-config-section.vue +++ b/src/components/config-editor/components/sections/initial-config-section.vue @@ -5,6 +5,9 @@ import { useSimulationStore } from "@/store/simulation"; import ConfigCoordsBounds from "@/components/config-editor/components/inputs/config-coords-bounds.vue"; import ConfigSection from "@/components/config-editor/components/containers/config-section.vue"; import InputHeader from "@/components/config-editor/components/base/input-header.vue"; +import type { InitialConfig } from "@/lib/types/config"; +import { ref, type Ref, watch } from "vue"; +import { getViewModeConfig } from "@/lib/helpers"; withDefaults(defineProps<{ withButtons?: boolean; @@ -13,11 +16,17 @@ withDefaults(defineProps<{ }); const configStore = useConfigStore(); -const { initialConfig } = configStore; +const { refillAtoms } = useSimulationStore(); -const { - refillAtoms, -} = useSimulationStore(); +const getActualInitialConfig = () => { + return getViewModeConfig(configStore.worldConfig).INITIAL; +} + +const initialConfig: Ref = ref(getActualInitialConfig()); + +watch(() => configStore.worldConfig.VIEW_MODE, () => { + initialConfig.value = getActualInitialConfig(); +}); const refill = () => { if (confirm('Are you sure?')) { diff --git a/src/components/config-editor/components/sections/randomize-config-section.vue b/src/components/config-editor/components/sections/randomize-config-section.vue index 15f91e4..27451e7 100644 --- a/src/components/config-editor/components/sections/randomize-config-section.vue +++ b/src/components/config-editor/components/sections/randomize-config-section.vue @@ -10,7 +10,7 @@ import Flag from "@/components/config-editor/components/inputs/flag.vue"; import InputHeader from "@/components/config-editor/components/base/input-header.vue"; const configStore = useConfigStore(); -const { randomTypesConfig, initialConfig } = configStore; +const { randomTypesConfig } = configStore; const { clearAtoms, diff --git a/src/store/config.ts b/src/store/config.ts index b6df52c..d094ac6 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -1,7 +1,6 @@ import { type Ref, ref, watch } from "vue"; import { defineStore } from "pinia"; import type { - InitialConfig, RandomTypesConfig, TypesSymmetricConfig, TypesConfig, @@ -15,7 +14,6 @@ import { createDefaultRandomTypesConfig, createRandomTypesConfig, } from "@/lib/config/types"; -import { create3dBaseInitialConfig } from "@/lib/config/initial"; import { fullCopyObject } from "@/helpers/utils"; import { concatArrays, @@ -30,11 +28,9 @@ import { useFlash } from '@/hooks/use-flash'; export const useConfigStore = defineStore("config", () => { const worldConfigRaw: WorldConfig = createBaseWorldConfig(); const typesConfigRaw: TypesConfig = createBaseTypesConfig(); - const initialConfigRaw: InitialConfig = create3dBaseInitialConfig(); const worldConfig: Ref = ref(fullCopyObject(worldConfigRaw)); const typesConfig: Ref = ref(fullCopyObject(typesConfigRaw)); - const initialConfig: Ref = ref(fullCopyObject(initialConfigRaw)); const randomTypesConfig: Ref = ref(createDefaultRandomTypesConfig(typesConfigRaw.COLORS.length)); const flash = useFlash(); @@ -51,7 +47,6 @@ export const useConfigStore = defineStore("config", () => { return { worldConfig: worldConfigRaw, typesConfig: typesConfigRaw, - initialConfig: initialConfigRaw, } } @@ -60,21 +55,6 @@ export const useConfigStore = defineStore("config", () => { worldConfigRaw.VIEW_MODE = viewMode; } - const setInitialConfigRaw = (newConfig: InitialConfig) => { - const buf = fullCopyObject(newConfig); - for (const i in newConfig) { - (initialConfigRaw[i as keyof InitialConfig] as T) = buf[i as keyof InitialConfig] as T; - } - } - - const setInitialConfig = (newConfig: InitialConfig) => { - const buf = fullCopyObject(newConfig); - for (const i in newConfig) { - (initialConfig.value[i as keyof InitialConfig] as T) = buf[i as keyof InitialConfig] as T; - } - setInitialConfigRaw(newConfig); - } - const setTypesConfigRaw = (newConfig: TypesConfig) => { const buf = fullCopyObject(newConfig); for (const i in newConfig) { @@ -333,19 +313,13 @@ export const useConfigStore = defineStore("config", () => { setTypesConfigRaw(newConfig); }, { deep: true }); - watch(initialConfig, (newConfig: InitialConfig) => { - setInitialConfigRaw(newConfig); - }, { deep: true }); - return { worldConfig, typesConfig, - initialConfig, randomTypesConfig, typesSymmetricConfig, getConfigValues, setViewMode, - setInitialConfig, setTypesConfig, setWorldConfig, randomizeTypesConfig, diff --git a/src/store/simulation.ts b/src/store/simulation.ts index 36522d5..1a6bda9 100644 --- a/src/store/simulation.ts +++ b/src/store/simulation.ts @@ -51,18 +51,12 @@ export const useSimulationStore = defineStore("simulation", () => { } const start3dSimulation = async () => { - configStore.setInitialConfig(create3dBaseInitialConfig()); - await init(); - simulation3d?.start(); }; const start2dSimulation = async () => { - configStore.setInitialConfig(create2dBaseInitialConfig()); - await init(); - simulation2d?.start(); };