From 1f199dfd7a227ea06c52bcf819d043feec2eb59a Mon Sep 17 00:00:00 2001 From: aoirint Date: Wed, 22 Jun 2022 00:24:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=A9=E3=82=AF=E3=82=BF?= =?UTF-8?q?=E3=83=BC=E4=B8=A6=E3=81=B3=E6=9B=BF=E3=81=88=E3=83=80=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=AD=E3=82=B0:=20speakerUuid=E3=81=8C=E7=95=B0?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=ABstyleId=E3=81=AE?= =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=82=92=E8=A8=B1=E5=AE=B9=E3=81=99=E3=82=8B?= =?UTF-8?q?=20(#754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CharacterOrderDialog: allow duplication of styleId when speakerUuid is different * remove unneeded undefined check --- src/components/CharacterOrderDialog.vue | 46 +++++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/components/CharacterOrderDialog.vue b/src/components/CharacterOrderDialog.vue index 9d0cb80243..9305b54528 100644 --- a/src/components/CharacterOrderDialog.vue +++ b/src/components/CharacterOrderDialog.vue @@ -65,7 +65,7 @@ ]" @click=" selectCharacter(speakerUuid); - togglePlayOrStop(selectedStyles[speakerUuid], 0); + togglePlayOrStop(speakerUuid, selectedStyles[speakerUuid], 0); " >
@@ -126,6 +126,7 @@ outline :icon=" playing != undefined && + speakerUuid === playing.speakerUuid && selectedStyles[speakerUuid].styleId === playing.styleId && voiceSampleIndex === playing.index @@ -139,6 +140,7 @@ @click.stop=" selectCharacter(speakerUuid); togglePlayOrStop( + speakerUuid, selectedStyles[speakerUuid], voiceSampleIndex ); @@ -238,21 +240,14 @@ export default defineComponent({ const sampleCharacterOrder = ref([]); // 選択中のスタイル - const selectedStyleIndexes = ref( - Object.fromEntries( - props.characterInfos.map((characterInfo) => [ - characterInfo.metas.speakerUuid, - 0, - ]) - ) - ); + const selectedStyleIndexes = ref>({}); const selectedStyles = computed(() => { const map: { [key: string]: StyleInfo } = {}; props.characterInfos.forEach((characterInfo) => { + const selectedStyleIndex: number | undefined = + selectedStyleIndexes.value[characterInfo.metas.speakerUuid]; map[characterInfo.metas.speakerUuid] = - characterInfo.metas.styles[ - selectedStyleIndexes.value[characterInfo.metas.speakerUuid] - ]; + characterInfo.metas.styles[selectedStyleIndex ?? 0]; }); return map; }); @@ -317,18 +312,23 @@ export default defineComponent({ const isHoverableItem = ref(true); // 音声再生 - const playing = ref<{ styleId: number; index: number }>(); + const playing = + ref<{ speakerUuid: string; styleId: number; index: number }>(); const audio = new Audio(); audio.volume = 0.5; audio.onended = () => stop(); - const play = ({ styleId, voiceSamplePaths }: StyleInfo, index: number) => { + const play = ( + speakerUuid: string, + { styleId, voiceSamplePaths }: StyleInfo, + index: number + ) => { if (audio.src !== "") stop(); audio.src = voiceSamplePaths[index]; audio.play(); - playing.value = { styleId, index }; + playing.value = { speakerUuid, styleId, index }; }; const stop = () => { if (audio.src === "") return; @@ -339,13 +339,18 @@ export default defineComponent({ }; // 再生していたら停止、再生していなかったら再生 - const togglePlayOrStop = (styleInfo: StyleInfo, index: number) => { + const togglePlayOrStop = ( + speakerUuid: string, + styleInfo: StyleInfo, + index: number + ) => { if ( playing.value === undefined || + speakerUuid !== playing.value.speakerUuid || styleInfo.styleId !== playing.value.styleId || index !== playing.value.index ) { - play(styleInfo, index); + play(speakerUuid, styleInfo, index); } else { stop(); } @@ -355,14 +360,17 @@ export default defineComponent({ const rollStyleIndex = (speakerUuid: string, diff: number) => { // 0 <= index <= length に収める const length = characterInfosMap.value[speakerUuid].metas.styles.length; - let styleIndex = selectedStyleIndexes.value[speakerUuid] + diff; + const selectedStyleIndex: number | undefined = + selectedStyleIndexes.value[speakerUuid]; + + let styleIndex = (selectedStyleIndex ?? 0) + diff; styleIndex = styleIndex < 0 ? length - 1 : styleIndex % length; selectedStyleIndexes.value[speakerUuid] = styleIndex; // 音声を再生する。同じstyleIndexだったら停止する。 const selectedStyleInfo = characterInfosMap.value[speakerUuid].metas.styles[styleIndex]; - togglePlayOrStop(selectedStyleInfo, 0); + togglePlayOrStop(speakerUuid, selectedStyleInfo, 0); }; // ドラッグ中かどうか