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
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 6 additions & 9 deletions src/components/Talk/EditorHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
<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"
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved
/>
<default-style-list-dialog
v-if="orderedTalkCharacterInfos.length > 0"
Expand Down Expand Up @@ -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(),
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
]);
const isCharacterOrderDialogOpenComputed = computed({
get: () =>
!store.state.isAcceptTermsDialogOpen &&
Expand All @@ -727,10 +727,7 @@ const isCharacterOrderDialogOpenComputed = computed({
// TODO: デフォルトスタイル選択(ソング)の実装
// デフォルトスタイル選択(トーク)
const orderedTalkCharacterInfos = computed(() => {
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved
return filterCharacterInfosByStyleType(
store.getters.GET_ORDERED_ALL_CHARACTER_INFOS,
"talk"
);
return filterCharacterInfosByStyleType(allCharacterInfos.value, "talk");
});
const isDefaultStyleSelectDialogOpenComputed = computed({
get: () =>
Expand Down
43 changes: 4 additions & 39 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -112,7 +75,9 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
},
};
});
return flattenCharacterInfos;
return new Map(
flattenCharacterInfos.map((c) => [c.metas.speakerUuid, c])
);
},
},

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

GET_ORDERED_ALL_CHARACTER_INFOS: {
getter: CharacterInfo[];
};

GET_ALL_VOICES: {
getter: Voice[];
};
Expand Down
Loading