Skip to content

Commit

Permalink
Random types count fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Jul 13, 2024
1 parent b2b0800 commit b435b79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const removeSnippet = (index: number) => {
}
const applySnippet = (config: RandomTypesConfig) => {
console.log('APPLY', config);
configStore.setRandomTypesConfig(config);
configStore.setRandomTypesConfig(config, ['TYPES_COUNT']);
}
</script>
Expand Down
7 changes: 6 additions & 1 deletion src/web/components/config-editor/config-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
</script>
Expand Down
3 changes: 2 additions & 1 deletion src/web/components/config-editor/hooks/use-right-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const useRightBar = () => {

const rightBarMode: Ref<number> = 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();
Expand Down
10 changes: 9 additions & 1 deletion src/web/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -273,6 +280,7 @@ export const useConfigStore = defineStore("config", () => {
randomizeTypesConfig,
setDefaultTypesConfig,
setRandomTypesConfig,
syncRandomTypesCount,
appendType,
addTypesFromConfig,
removeTypeFromConfig,
Expand Down

0 comments on commit b435b79

Please sign in to comment.