From e4d87706f4c2b816cdc4c41ee2210a6b1ffc806d Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Fri, 2 Feb 2024 20:55:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Refactor:=20ORDERED=5FALL=5FCHARACTERS=5FIN?= =?UTF-8?q?FO=E3=82=92=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Talk/EditorHome.vue | 15 +++++------ src/store/index.ts | 43 +++--------------------------- src/store/type.ts | 4 --- 3 files changed, 10 insertions(+), 52 deletions(-) diff --git a/src/components/Talk/EditorHome.vue b/src/components/Talk/EditorHome.vue index 54e996276d..17716ead07 100644 --- a/src/components/Talk/EditorHome.vue +++ b/src/components/Talk/EditorHome.vue @@ -162,9 +162,9 @@ store.getters.GET_ORDERED_ALL_CHARACTER_INFOS -); +const allCharacterInfos = computed(() => [ + ...store.getters.GET_ALL_CHARACTER_INFOS.values(), +]); const isCharacterOrderDialogOpenComputed = computed({ get: () => !store.state.isAcceptTermsDialogOpen && @@ -727,10 +727,7 @@ const isCharacterOrderDialogOpenComputed = computed({ // TODO: デフォルトスタイル選択(ソング)の実装 // デフォルトスタイル選択(トーク) const orderedTalkCharacterInfos = computed(() => { - return filterCharacterInfosByStyleType( - store.getters.GET_ORDERED_ALL_CHARACTER_INFOS, - "talk" - ); + return filterCharacterInfosByStyleType(allCharacterInfos.value, "talk"); }); const isDefaultStyleSelectDialogOpenComputed = computed({ get: () => diff --git a/src/store/index.ts b/src/store/index.ts index 51072e8333..ae59077686 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -52,49 +52,12 @@ export const indexStore = createPartialStore({ * 同じspeakerUuidのキャラクター情報は、登録順が早いエンジンの情報を元に統合される。 * キャラクター情報が読み出されていないときは、空リストを返す。 */ - getter(state) { - const speakerUuids = [ - ...new Set( - state.engineIds.flatMap((engineId) => - (state.characterInfos[engineId] ?? []).map( - (c) => c.metas.speakerUuid - ) - ) - ), - ]; - const flattenCharacterInfos = speakerUuids.map((speakerUuid) => { - const characterInfos = state.engineIds.flatMap( - (engineId) => - state.characterInfos[engineId]?.find( - (c) => c.metas.speakerUuid === speakerUuid - ) ?? [] - ); - - // エンジンの登録順が早い方が優先される。 - return { - ...characterInfos[0], - metas: { - ...characterInfos[0].metas, - styles: characterInfos.flatMap((c) => c.metas.styles), - }, - }; - }); - return new Map( - flattenCharacterInfos.map((c) => [c.metas.speakerUuid, c]) - ); - }, - }, - /** - * すべてのエンジンのキャラクター情報のリスト。 - * GET_ALL_CHARACTER_INFOSとは違い、話者の順番が保持される。 - */ - GET_ORDERED_ALL_CHARACTER_INFOS: { getter(state) { const speakerUuids = state.engineIds .flatMap((engineId) => (state.characterInfos[engineId] ?? []).map((c) => c.metas.speakerUuid) ) - .filter((uuid, index, uuids) => uuids.indexOf(uuid) === index); // Setを使うと順番が保証されないのでindexOfで重複削除をする。 + .filter((uuid, index, uuids) => uuids.indexOf(uuid) === index); const flattenCharacterInfos = speakerUuids.map((speakerUuid) => { const characterInfos = state.engineIds.flatMap( (engineId) => @@ -112,7 +75,9 @@ export const indexStore = createPartialStore({ }, }; }); - return flattenCharacterInfos; + return new Map( + flattenCharacterInfos.map((c) => [c.metas.speakerUuid, c]) + ); }, }, diff --git a/src/store/type.ts b/src/store/type.ts index 6303454208..985b646b17 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -1190,10 +1190,6 @@ export type IndexStoreTypes = { getter: Map; }; - GET_ORDERED_ALL_CHARACTER_INFOS: { - getter: CharacterInfo[]; - }; - GET_ALL_VOICES: { getter: Voice[]; }; From 06a3e21cae40f03fc501d0f27313f75276c43d74 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 3 Feb 2024 21:53:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Change:=20=E5=A4=89=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E4=BD=93=E3=81=AB=E8=BF=BD=E5=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Talk/EditorHome.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Talk/EditorHome.vue b/src/components/Talk/EditorHome.vue index 17716ead07..c3441da271 100644 --- a/src/components/Talk/EditorHome.vue +++ b/src/components/Talk/EditorHome.vue @@ -167,9 +167,9 @@ :character-infos="allCharacterInfos" /> @@ -726,7 +726,7 @@ const isCharacterOrderDialogOpenComputed = computed({ // TODO: デフォルトスタイル選択(ソング)の実装 // デフォルトスタイル選択(トーク) -const orderedTalkCharacterInfos = computed(() => { +const allTalkCharacterInfos = computed(() => { return filterCharacterInfosByStyleType(allCharacterInfos.value, "talk"); }); const isDefaultStyleSelectDialogOpenComputed = computed({ From a36b45df118cfe04cefc43d85e257c48556f4703 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 3 Feb 2024 22:14:59 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Change:=20Map=E3=82=92=E6=B8=A1=E3=81=99?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dialog/CharacterOrderDialog.vue | 26 +++++++++---------- src/components/Talk/EditorHome.vue | 11 ++++---- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/components/Dialog/CharacterOrderDialog.vue b/src/components/Dialog/CharacterOrderDialog.vue index d190328212..b9f6e27f17 100644 --- a/src/components/Dialog/CharacterOrderDialog.vue +++ b/src/components/Dialog/CharacterOrderDialog.vue @@ -50,7 +50,7 @@ サンプルボイス一覧
; }>(); const emit = @@ -129,12 +129,8 @@ const modelValueComputed = computed({ set: (val) => emit("update:modelValue", val), }); -const characterInfosMap = computed(() => { - const map: { [key: SpeakerId]: CharacterInfo } = {}; - props.characterInfos.forEach((characterInfo) => { - map[characterInfo.metas.speakerUuid] = characterInfo; - }); - return map; +const characterInfosArray = computed(() => { + return [...props.characterInfos.values()]; }); // 新しいキャラクター @@ -145,13 +141,15 @@ const hasNewCharacter = computed(() => newCharacters.value.length > 0); const sampleCharacterOrder = ref([]); // 選択中のキャラクター -const selectedCharacter = ref(props.characterInfos[0].metas.speakerUuid); +const selectedCharacter = ref(characterInfosArray.value[0].metas.speakerUuid); const selectCharacter = (speakerUuid: SpeakerId) => { selectedCharacter.value = speakerUuid; }; const selectCharacterWithChangePortrait = (speakerUuid: SpeakerId) => { selectCharacter(speakerUuid); - portrait.value = characterInfosMap.value[speakerUuid].portraitPath; + const characterInfo = props.characterInfos.get(speakerUuid); + if (characterInfo == undefined) throw new Error("characterInfo is undefined"); + portrait.value = characterInfo.portraitPath; }; // キャラクター表示順序 @@ -168,7 +166,7 @@ watch( // サンプルの順番、新しいキャラクターは上に sampleCharacterOrder.value = [ ...newCharacters.value, - ...props.characterInfos + ...characterInfosArray.value .filter( (info) => !newCharacters.value.includes(info.metas.speakerUuid) ) @@ -180,11 +178,11 @@ watch( // 保存済みのキャラクターリストを取得 // FIXME: 不明なキャラを無視しているので、不明キャラの順番が保存時にリセットされてしまう characterOrder.value = store.state.userCharacterOrder - .map((speakerUuid) => characterInfosMap.value[speakerUuid]) + .map((speakerUuid) => props.characterInfos.get(speakerUuid)) .filter((info) => info != undefined) as CharacterInfo[]; // 含まれていないキャラクターを足す - const notIncludesCharacterInfos = props.characterInfos.filter( + const notIncludesCharacterInfos = characterInfosArray.value.filter( (characterInfo) => !characterOrder.value.find( (characterInfoInList) => @@ -261,7 +259,7 @@ const closeDialog = () => { }; const portrait = ref( - characterInfosMap.value[selectedCharacter.value].portraitPath + props.characterInfos.get(selectedCharacter.value)?.portraitPath ); const updatePortrait = (portraitPath: string) => { portrait.value = portraitPath; diff --git a/src/components/Talk/EditorHome.vue b/src/components/Talk/EditorHome.vue index c3441da271..d5b964c6f9 100644 --- a/src/components/Talk/EditorHome.vue +++ b/src/components/Talk/EditorHome.vue @@ -162,7 +162,7 @@ @@ -711,9 +711,7 @@ const isAcceptTermsDialogOpenComputed = computed({ }); // キャラクター並び替え -const allCharacterInfos = computed(() => [ - ...store.getters.GET_ALL_CHARACTER_INFOS.values(), -]); +const allCharacterInfos = computed(() => store.getters.GET_ALL_CHARACTER_INFOS); const isCharacterOrderDialogOpenComputed = computed({ get: () => !store.state.isAcceptTermsDialogOpen && @@ -727,7 +725,10 @@ const isCharacterOrderDialogOpenComputed = computed({ // TODO: デフォルトスタイル選択(ソング)の実装 // デフォルトスタイル選択(トーク) const allTalkCharacterInfos = computed(() => { - return filterCharacterInfosByStyleType(allCharacterInfos.value, "talk"); + return filterCharacterInfosByStyleType( + [...store.getters.GET_ALL_CHARACTER_INFOS.values()], + "talk" + ); }); const isDefaultStyleSelectDialogOpenComputed = computed({ get: () =>