Skip to content

Commit

Permalink
デフォルトスタイルダイアログが開かれたタイミングで初期値を代入する (VOICEVOX#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Nov 6, 2021
1 parent fc23302 commit b5a0102
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/components/DefaultStyleSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</template>

<script lang="ts">
import { defineComponent, computed, ref, PropType } from "vue";
import { defineComponent, computed, ref, PropType, watch } from "vue";
import { useStore } from "@/store";
import { CharacterInfo, StyleInfo } from "@/type/preload";
Expand All @@ -185,23 +185,34 @@ export default defineComponent({
});
const isFirstTime = ref(false);
store
.dispatch("IS_UNSET_DEFAULT_STYLE_IDS")
.then((isUnsetDefaultStyleIds) => {
isFirstTime.value = isUnsetDefaultStyleIds;
});
const selectedStyleIndexes = ref(
props.characterInfos.map((info) => {
const defaultStyleId = store.state.defaultStyleIds.find(
(x) => x.speakerUuid === info.metas.speakerUuid
)?.defaultStyleId;
const index = info.metas.styles.findIndex(
(style) => style.styleId === defaultStyleId
);
return index === -1 ? undefined : index;
})
const selectedStyleIndexes = ref<(number | undefined)[]>([]);
// ダイアログが開かれたときに初期値を求める
watch(
() => props.modelValue,
(newValue, oldValue) => {
if (!oldValue && newValue) {
store
.dispatch("IS_UNSET_DEFAULT_STYLE_IDS")
.then((isUnsetDefaultStyleIds) => {
isFirstTime.value = isUnsetDefaultStyleIds;
});
selectedStyleIndexes.value = props.characterInfos.map((info) => {
// FIXME: キャラクターごとにデフォルスタイル選択済みか保存できるようになるべき
if (isFirstTime.value) return undefined;
const defaultStyleId = store.state.defaultStyleIds.find(
(x) => x.speakerUuid === info.metas.speakerUuid
)?.defaultStyleId;
const index = info.metas.styles.findIndex(
(style) => style.styleId === defaultStyleId
);
return index === -1 ? undefined : index;
});
}
}
);
const selectStyleIndex = (characterIndex: number, styleIndex: number) => {
Expand Down

0 comments on commit b5a0102

Please sign in to comment.