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 all 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
26 changes: 12 additions & 14 deletions src/components/Dialog/CharacterOrderDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<span class="text-h6 q-py-md">サンプルボイス一覧</span>
<div>
<CharacterTryListenCard
v-for="characterInfo of characterInfos"
v-for="characterInfo of characterInfosArray"
:key="characterInfo.metas.speakerUuid"
:character-info="characterInfo"
:is-selected="
Expand Down Expand Up @@ -114,7 +114,7 @@ import { CharacterInfo, SpeakerId, StyleId, StyleInfo } from "@/type/preload";
const props =
defineProps<{
modelValue: boolean;
characterInfos: CharacterInfo[];
characterInfos: Map<SpeakerId, CharacterInfo>;
}>();

const emit =
Expand All @@ -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()];
});

// 新しいキャラクター
Expand All @@ -145,13 +141,15 @@ const hasNewCharacter = computed(() => newCharacters.value.length > 0);
const sampleCharacterOrder = ref<SpeakerId[]>([]);

// 選択中のキャラクター
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;
};

// キャラクター表示順序
Expand All @@ -168,7 +166,7 @@ watch(
// サンプルの順番、新しいキャラクターは上に
sampleCharacterOrder.value = [
...newCharacters.value,
...props.characterInfos
...characterInfosArray.value
.filter(
Comment on lines 166 to 170
Copy link
Member

@Hiroshiba Hiroshiba Feb 4, 2024

Choose a reason for hiding this comment

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

こーーーーーーれ、characterInfosArrayはorderedな必要がある気がしてきました・・・・・・・。
(順番が大事っぽい。)

(info) => !newCharacters.value.includes(info.metas.speakerUuid)
)
Expand All @@ -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) =>
Expand Down Expand Up @@ -261,7 +259,7 @@ const closeDialog = () => {
};

const portrait = ref<string | undefined>(
characterInfosMap.value[selectedCharacter.value].portraitPath
props.characterInfos.get(selectedCharacter.value)?.portraitPath
);
const updatePortrait = (portraitPath: string) => {
portrait.value = portraitPath;
Expand Down
16 changes: 7 additions & 9 deletions src/components/Talk/EditorHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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.size > 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"
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" />
Expand Down Expand Up @@ -711,9 +711,7 @@ const isAcceptTermsDialogOpenComputed = computed({
});

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

// TODO: デフォルトスタイル選択(ソング)の実装
// デフォルトスタイル選択(トーク)
const orderedTalkCharacterInfos = computed(() => {
const allTalkCharacterInfos = computed(() => {
return filterCharacterInfosByStyleType(
store.getters.GET_ORDERED_ALL_CHARACTER_INFOS,
[...store.getters.GET_ALL_CHARACTER_INFOS.values()],
"talk"
);
});
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