Skip to content

Commit

Permalink
デフォルトスタイル選択ダイアログの仕様変更 (#706)
Browse files Browse the repository at this point in the history
* デフォルトスタイル選択の仕様変更

* 名称修正
  • Loading branch information
Hiroshiba authored Feb 27, 2022
1 parent c29f56f commit 12efd7a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
4 changes: 0 additions & 4 deletions src/components/AudioCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,6 @@ export default defineComponent({
textfield.value.focus();
};
// キャラクター選択
const isOpenedCharacterList = ref(false);
return {
characterInfos,
audioItem,
Expand Down Expand Up @@ -420,7 +417,6 @@ export default defineComponent({
textfield,
focusTextField,
blurCell,
isOpenedCharacterList,
};
},
});
Expand Down
21 changes: 15 additions & 6 deletions src/components/DefaultStyleSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
round
outline
:icon="
style.styleId === playing?.styleId &&
playing != undefined &&
style.styleId === playing.styleId &&
voiceSampleIndex === playing.index
? 'stop'
: 'play_arrow'
Expand All @@ -141,7 +142,8 @@
@mouseenter="isHoverableStyleItem = false"
@mouseleave="isHoverableStyleItem = true"
@click.stop="
style.styleId === playing?.styleId &&
playing != undefined &&
style.styleId === playing.styleId &&
voiceSampleIndex === playing.index
? stop()
: play(style, voiceSampleIndex)
Expand Down Expand Up @@ -199,10 +201,17 @@ export default defineComponent({
set: (val) => emit("update:modelValue", val),
});
// アップデートで増えたキャラ・スタイルがあれば、それらに対して起動時にデフォルトスタイル選択・試聴を問うための変数
// 複数スタイルあるキャラクター
const multiStyleCharacterInfos = computed(() => {
return props.characterInfos.filter(
(characterInfo) => characterInfo.metas.styles.length > 1
);
});
// アップデートで増えたスタイルがあれば、それらに対して起動時にデフォルトスタイル選択を問うための変数
// その他の場合は、characterInfosと同じになる
// FIXME: 現状はスタイルが増えてもデフォルトスタイルを問えないので、そこを改修しなければならない
const showCharacterInfos = ref(props.characterInfos);
const showCharacterInfos = ref(multiStyleCharacterInfos.value);
const isFirstTime = ref(false);
const selectedStyleIndexes = ref<(number | undefined)[]>([]);
Expand All @@ -214,7 +223,7 @@ export default defineComponent({
if (!oldValue && newValue) {
showCharacterInfos.value = [];
selectedStyleIndexes.value = await Promise.all(
props.characterInfos.map(async (info) => {
multiStyleCharacterInfos.value.map(async (info) => {
const styles = info.metas.styles;
const isUnsetDefaultStyleId = await store.dispatch(
"IS_UNSET_DEFAULT_STYLE_ID",
Expand All @@ -237,7 +246,7 @@ export default defineComponent({
})
);
if (!isFirstTime.value) {
showCharacterInfos.value = props.characterInfos;
showCharacterInfos.value = multiStyleCharacterInfos.value;
} else {
selectedStyleIndexes.value = showCharacterInfos.value.map(
(info) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export default defineComponent({
},
{
type: "button",
label: "デフォルトスタイル・試聴",
label: "デフォルトスタイル",
onClick() {
store.dispatch("IS_DEFAULT_STYLE_SELECT_DIALOG_OPEN", {
isDefaultStyleSelectDialogOpen: true,
Expand Down
32 changes: 19 additions & 13 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,27 @@ export const indexStore: VoiceVoxStoreOptions<
return await window.electron.isUnsetDefaultStyleId(speakerUuid);
},
async LOAD_DEFAULT_STYLE_IDS({ commit, state }) {
const storeDefaultStyleIds = await window.electron.getDefaultStyleIds();
if (storeDefaultStyleIds.length === 0) {
const characterInfos = await state.characterInfos;
if (characterInfos == undefined)
throw new Error("state.characterInfos == undefined");
const defaultStyleIds = characterInfos.map<DefaultStyleId>((info) => ({
let defaultStyleIds = await window.electron.getDefaultStyleIds();

if (!state.characterInfos) throw new Error("characterInfos is undefined");

// デフォルトスタイルが設定されていない場合は0をセットする
// FIXME: 保存しているものとstateのものが異なってしまうので良くない。デフォルトスタイルが未設定の場合はAudioCellsを表示しないようにすべき
const unsetCharacterInfos = state.characterInfos.filter(
(characterInfo) =>
!defaultStyleIds.some(
(styleId) => styleId.speakerUuid == characterInfo.metas.speakerUuid
)
);
defaultStyleIds = [
...defaultStyleIds,
...unsetCharacterInfos.map<DefaultStyleId>((info) => ({
speakerUuid: info.metas.speakerUuid,
defaultStyleId: info.metas.styles[0].styleId,
}));
commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
} else {
commit("SET_DEFAULT_STYLE_IDS", {
defaultStyleIds: storeDefaultStyleIds,
});
}
})),
];

commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
},
async SET_DEFAULT_STYLE_IDS({ commit }, defaultStyleIds) {
commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
Expand Down
10 changes: 6 additions & 4 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,15 @@ export default defineComponent({
await store.dispatch("LOAD_CHARACTER");
await store.dispatch("LOAD_DEFAULT_STYLE_IDS");
// スタイルが複数あって未選択なキャラがいる場合はデフォルトスタイル選択ダイアログを表示
let isUnsetDefaultStyleIds = false;
if (characterInfos.value == undefined) throw new Error();
for (const info of characterInfos.value) {
isUnsetDefaultStyleIds ||= await store.dispatch(
"IS_UNSET_DEFAULT_STYLE_ID",
{ speakerUuid: info.metas.speakerUuid }
);
isUnsetDefaultStyleIds ||=
info.metas.styles.length > 1 &&
(await store.dispatch("IS_UNSET_DEFAULT_STYLE_ID", {
speakerUuid: info.metas.speakerUuid,
}));
}
isDefaultStyleSelectDialogOpenComputed.value = isUnsetDefaultStyleIds;
Expand Down

0 comments on commit 12efd7a

Please sign in to comment.