Skip to content

Commit

Permalink
Fix デフォルトプリセットの再登録が機能してないバグ(#1996)を修正 (#2053)
Browse files Browse the repository at this point in the history
* GET_ALL_VOICES getter change to getter function with a argument of styleType

* add migration process but version is temporary for dev

* add check length of defaultPresetsKeys

* fix crusth at unit test, check to can migrate from 0.13

* change target migration version

* rename

* 文脈コメントと型を追加

---------

Co-authored-by: Hiroshiba Kazuyuki <[email protected]>
  • Loading branch information
madosuki and Hiroshiba authored May 6, 2024
1 parent 0fb559d commit 25e1176
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
41 changes: 41 additions & 0 deletions src/backend/common/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
HotkeySettingType,
ExperimentalSettingType,
HotkeyCombination,
VoiceId,
PresetKey,
} from "@/type/preload";

const lockKey = "save";
Expand Down Expand Up @@ -181,6 +183,45 @@ const migrations: [string, (store: Record<string, unknown>) => unknown][] = [
});
config.hotkeySettings = newHotkeySettings;

// バグで追加されたソング・ハミングスタイルのデフォルトプリセットを削除する
(() => {
const defaultPresetKeys = config.defaultPresetKeys as
| ConfigType["defaultPresetKeys"]
| undefined;
if (
defaultPresetKeys == undefined ||
Object.keys(defaultPresetKeys).length == 0
)
return;

const singStyleVoiceId: VoiceId[] = Object.keys(
defaultPresetKeys,
).filter((voiceId) => {
// VoiceIdの3番目はスタイルIDなので、それが3000以上3085以下または6000のものをソング・ハミングスタイルとみなす
const splited = voiceId.split(":");
if (splited.length < 3) return false;

const styleId = parseInt(splited[2]);
return (styleId >= 3000 && styleId <= 3085) || styleId === 6000;
}) as VoiceId[];

const presets = config.presets as ConfigType["presets"];
const singerPresetKeys: PresetKey[] = [];
for (const voiceId of singStyleVoiceId) {
const defaultPresetKey = defaultPresetKeys[voiceId];
if (defaultPresetKey == undefined) continue;
singerPresetKeys.push(defaultPresetKey);
delete presets.items[defaultPresetKey];
delete defaultPresetKeys[voiceId];
}

if (singerPresetKeys.length === 0) return;
const newPresetKeys = presets.keys.filter(
(key) => !singerPresetKeys.includes(key),
);
presets.keys = newPresetKeys;
})();

return config;
},
],
Expand Down
11 changes: 9 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { dictionaryStoreState, dictionaryStore } from "./dictionary";
import { proxyStore, proxyStoreState } from "./proxy";
import { createPartialStore } from "./vuex";
import { engineStoreState, engineStore } from "./engine";
import { filterCharacterInfosByStyleType } from "./utility";
import {
DefaultStyleId,
EngineId,
Expand Down Expand Up @@ -124,10 +125,16 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
},

GET_ALL_VOICES: {
getter(state) {
const flattenCharacters = Object.values(state.characterInfos).flatMap(
getter: (state) => (styleType: "all" | "singerLike" | "talk") => {
let flattenCharacters = Object.values(state.characterInfos).flatMap(
(characterInfos) => characterInfos,
);
if (styleType !== "all") {
flattenCharacters = filterCharacterInfosByStyleType(
flattenCharacters,
styleType,
);
}
const flattenVoices: Voice[] = flattenCharacters.flatMap((c) =>
c.metas.styles.map((s) => ({
engineId: EngineId(s.engineId),
Expand Down
2 changes: 1 addition & 1 deletion src/store/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const presetStore = createPartialStore<PresetStoreTypes>({

CREATE_ALL_DEFAULT_PRESET: {
async action({ state, dispatch, getters }) {
const voices = getters.GET_ALL_VOICES;
const voices = getters.GET_ALL_VOICES("talk");

for (const voice of voices) {
const voiceId = VoiceId(voice);
Expand Down
2 changes: 1 addition & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ export type IndexStoreTypes = {
};

GET_ALL_VOICES: {
getter: Voice[];
getter(styleType: "all" | "singerLike" | "talk"): Voice[];
};

GET_HOW_TO_USE_TEXT: {
Expand Down

0 comments on commit 25e1176

Please sign in to comment.