Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: GET_ORDERED_ALL_CHARACTERS_INFOを統合 #1819

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/components/Talk/EditorHome.vue
Original file line number Diff line number Diff line change
@@ -162,14 +162,14 @@
<hotkey-setting-dialog v-model="isHotkeySettingDialogOpenComputed" />
<header-bar-custom-dialog v-model="isToolbarSettingDialogOpenComputed" />
<character-order-dialog
v-if="orderedAllCharacterInfos.length > 0"
v-if="allCharacterInfos.length > 0"
v-model="isCharacterOrderDialogOpenComputed"
:character-infos="orderedAllCharacterInfos"
:character-infos="allCharacterInfos"
/>
<default-style-list-dialog
v-if="orderedTalkCharacterInfos.length > 0"
v-if="allTalkCharacterInfos.length > 0"
v-model="isDefaultStyleSelectDialogOpenComputed"
:character-infos="orderedTalkCharacterInfos"
:character-infos="allTalkCharacterInfos"
/>
Comment on lines 169 to 173
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こっちも実はorderedじゃないといけない説が・・・・・・・?

<dictionary-manage-dialog v-model="isDictionaryManageDialogOpenComputed" />
<engine-manage-dialog v-model="isEngineManageDialogOpenComputed" />
@@ -711,9 +711,9 @@ const isAcceptTermsDialogOpenComputed = computed({
});

// キャラクター並び替え
const orderedAllCharacterInfos = computed(
() => store.getters.GET_ORDERED_ALL_CHARACTER_INFOS
);
const allCharacterInfos = computed(() => [
...store.getters.GET_ALL_CHARACTER_INFOS.values(),
]);
const isCharacterOrderDialogOpenComputed = computed({
get: () =>
!store.state.isAcceptTermsDialogOpen &&
@@ -726,11 +726,8 @@ const isCharacterOrderDialogOpenComputed = computed({

// TODO: デフォルトスタイル選択(ソング)の実装
// デフォルトスタイル選択(トーク)
const orderedTalkCharacterInfos = computed(() => {
return filterCharacterInfosByStyleType(
store.getters.GET_ORDERED_ALL_CHARACTER_INFOS,
"talk"
);
const allTalkCharacterInfos = computed(() => {
return filterCharacterInfosByStyleType(allCharacterInfos.value, "talk");
});
const isDefaultStyleSelectDialogOpenComputed = computed({
get: () =>
43 changes: 4 additions & 39 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -52,49 +52,12 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
* 同じ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<IndexStoreTypes>({
},
};
});
return flattenCharacterInfos;
return new Map(
flattenCharacterInfos.map((c) => [c.metas.speakerUuid, c])
);
},
},

4 changes: 0 additions & 4 deletions src/store/type.ts
Original file line number Diff line number Diff line change
@@ -1190,10 +1190,6 @@ export type IndexStoreTypes = {
getter: Map<SpeakerId, CharacterInfo>;
};

GET_ORDERED_ALL_CHARACTER_INFOS: {
getter: CharacterInfo[];
};

GET_ALL_VOICES: {
getter: Voice[];
};

Unchanged files with check annotations Beta

import { AccentPhrase, Mora } from "@/openapi";
import {
CharacterInfo,
StyleInfo,

Check warning on line 5 in tests/unit/store/utility.spec.ts

GitHub Actions / lint

'StyleInfo' is defined but never used

Check warning on line 5 in tests/unit/store/utility.spec.ts

GitHub Actions / build-test

'StyleInfo' is defined but never used
EngineId,
SpeakerId,
StyleId,