Skip to content

Commit

Permalink
add: キーバインドと型設定
Browse files Browse the repository at this point in the history
  • Loading branch information
tsym77yoshi committed Apr 28, 2024
1 parent 51833cd commit 8036a09
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/components/Talk/TalkEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ import {
SplitterPositionType,
Voice,
} from "@/type/preload";
import { parseUnshiftedDigit, useHotkeyManager } from "@/plugins/hotkeyPlugin";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
import onetimeWatch from "@/helpers/onetimeWatch";
const props = defineProps<{
Expand Down Expand Up @@ -246,34 +246,26 @@ registerHotkeyWithCleanup({
}
},
});
registerHotkeyWithCleanup({
editor: "talk",
enableInTextbox: true,
name: "N番目のキャラクターを選択",
callback: (e) => {
if (!uiLocked.value) {
onCharacterSelectHotkey(e);
}
},
});
for (let i = 0; i < 10; i++) {
registerHotkeyWithCleanup({
editor: "talk",
enableInTextbox: true,
name: `${i + 1}番目のキャラクターを選択`,
callback: () => {
if (!uiLocked.value) {
onCharacterSelectHotkey(i);
}
},
});
}
const removeAudioItem = async () => {
if (activeAudioKey.value == undefined) throw new Error();
audioCellRefs[activeAudioKey.value].removeCell();
};
const onCharacterSelectHotkey = async (e: KeyboardEvent) => {
const onCharacterSelectHotkey = async (selectedCharacterIndex: number) => {
if (activeAudioKey.value == undefined) throw new Error();
const convertToNumber = (str: string) => {
str = parseUnshiftedDigit(str);
if (/^[0-9]$/.test(str)) {
return parseInt(str, 10);
} else {
throw new Error(`onCharacterSelectHotkey Invalid key: ${str}`);
}
};
const convertedKey = convertToNumber(e.key);
const selectedCharacterIndex = convertedKey != 0 ? convertedKey - 1 : 9;
audioCellRefs[activeAudioKey.value].selectCharacterAt(selectedCharacterIndex);
};
Expand Down
13 changes: 13 additions & 0 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ export const defaultHotkeySettings: HotkeySettingType[] = [
action: "選択解除",
combination: HotkeyCombination("Escape"),
},
...Array.from({ length: 10 }, (_, index) => {
const roleKey = index == 9 ? 0 : index + 1;
return {
action: `${index + 1}番目のキャラクターを選択`,
combination: HotkeyCombination(
!isMac ? "Ctrl " + roleKey : "Meta " + roleKey,
),
};
}),
];

export const defaultToolbarButtonSetting: ToolbarSettingType = [
Expand Down Expand Up @@ -458,6 +467,10 @@ export const hotkeyActionNameSchema = z.enum([
"貼り付け",
"すべて選択",
"選択解除",
...Array.from(
{ length: 10 },
(_, index) => `${index + 1}番目のキャラクターを選択`,
),
]);

export type HotkeyActionNameType = z.infer<typeof hotkeyActionNameSchema>;
Expand Down

0 comments on commit 8036a09

Please sign in to comment.