Skip to content

Commit 01b41ad

Browse files
committed
refactor: 抽取出支持翻译的optionsIoKeyMap函数,减少冗余代码
1 parent 21d4da4 commit 01b41ad

3 files changed

Lines changed: 18 additions & 29 deletions

File tree

MaiChartManager/Front/src/views/ModManager/ConfigEntry.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ import { useI18n } from 'vue-i18n';
1010
import { locale } from "@/locales";
1111
import { ENTRY_LABEL_CLASS } from "./constants";
1212

13+
/* t需要传入是Vue的i18n翻译函数 */
14+
export function optionsIoKeyMap(t: (key: string) => string): { label: string, value: string }[] {
15+
return [
16+
{ label: t('mod.ioKeyMap.disabled'), value: 'None' },
17+
{ label: t('mod.ioKeyMap.select'), value: 'Select' },
18+
{ label: t('mod.ioKeyMap.select1P'), value: 'Select1P' },
19+
{ label: t('mod.ioKeyMap.select2P'), value: 'Select2P' },
20+
{ label: t('mod.ioKeyMap.service'), value: 'Service' },
21+
{ label: t('mod.ioKeyMap.test'), value: 'Test' },
22+
];
23+
}
24+
1325
export default defineComponent({
1426
props: {
1527
entry: { type: Object as PropType<Entry>, required: true },
@@ -18,15 +30,6 @@ export default defineComponent({
1830
setup(props, { emit }) {
1931
const { t, te } = useI18n();
2032

21-
const optionsIoKeyMap = [
22-
{ label: t('mod.ioKeyMap.disabled'), value: 'None' },
23-
{ label: t('mod.ioKeyMap.select'), value: 'Select' },
24-
{ label: t('mod.ioKeyMap.select1P'), value: 'Select1P' },
25-
{ label: t('mod.ioKeyMap.select2P'), value: 'Select2P' },
26-
{ label: t('mod.ioKeyMap.service'), value: 'Service' },
27-
{ label: t('mod.ioKeyMap.test'), value: 'Test' },
28-
];
29-
3033
const optionsSoundChannel = ['None', 'P1SpeakerLeft', 'P1SpeakerRight', 'P1HeadphoneLeft', 'P1HeadphoneRight', 'P2SpeakerLeft', 'P2SpeakerRight', 'P2HeadphoneLeft', 'P2HeadphoneRight']
3134
.map(channel => ({ label: t('mod.soundChannel.' + channel), value: channel }));
3235

@@ -78,9 +81,9 @@ export default defineComponent({
7881
case 'AquaMai.Config.Types.KeyCodeID':
7982
return <Select v-model:value={props.entryState.value} options={Object.entries(KeyCodeID).map(([label, value]) => ({label, value}))}/>;
8083
case 'AquaMai.Config.Types.IOKeyMap':
81-
return <Select v-model:value={props.entryState.value} options={optionsIoKeyMap}/>;
84+
return <Select v-model:value={props.entryState.value} options={optionsIoKeyMap(t)}/>;
8285
case 'AquaMai.Config.Types.AdxKeyMap':
83-
return <Select v-model:value={props.entryState.value} options={optionsIoKeyMap}/>;
86+
return <Select v-model:value={props.entryState.value} options={optionsIoKeyMap(t)}/>;
8487
case 'AquaMai.Config.Types.SoundChannel':
8588
return <Select v-model:value={props.entryState.value} options={optionsSoundChannel}/>;
8689
}

MaiChartManager/Front/src/views/ModManager/sectionPanelOverride/GameSystem.AdxHidInput/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button, Select } from '@munet/ui';
44
import api from "@/client/api";
55
import { modInfo, updateModInfo } from "@/store/refs";
66
import { useI18n } from 'vue-i18n';
7-
import ConfigEntry from '../../ConfigEntry';
7+
import ConfigEntry, {optionsIoKeyMap} from '../../ConfigEntry';
88
import { ENTRY_GROUP_PADDING, ENTRY_LABEL_CLASS } from '../../constants';
99

1010
export default defineComponent({
@@ -23,14 +23,7 @@ export default defineComponent({
2323
'GameSystem.AdxHidInput.Button3',
2424
'GameSystem.AdxHidInput.Button4',
2525
];
26-
const options = [
27-
{ label: t('mod.ioKeyMap.disabled'), value: 'None' },
28-
{ label: t('mod.ioKeyMap.select'), value: 'Select' },
29-
{ label: t('mod.ioKeyMap.select1P'), value: 'Select1P' },
30-
{ label: t('mod.ioKeyMap.select2P'), value: 'Select2P' },
31-
{ label: t('mod.ioKeyMap.service'), value: 'Service' },
32-
{ label: t('mod.ioKeyMap.test'), value: 'Test' },
33-
];
26+
const options = optionsIoKeyMap(t);
3427

3528
const del = async () => {
3629
load.value = true

MaiChartManager/Front/src/views/ModManager/sectionPanelOverride/GameSystem.MaimollerIO/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { globalCapture, modInfo, updateModInfo } from '@/store/refs';
55
import { useAsyncState } from '@vueuse/core';
66
import { Button, Select, CheckBox } from '@munet/ui';
77
import { defineComponent, PropType, ref, computed, watch } from 'vue';
8-
import ConfigEntry from '../../ConfigEntry';
8+
import ConfigEntry, {optionsIoKeyMap} from '../../ConfigEntry';
99
import { ENTRY_GROUP_PADDING, ENTRY_LABEL_CLASS } from '../../constants';
1010

1111
export default defineComponent({
@@ -25,14 +25,7 @@ export default defineComponent({
2525
},
2626
})
2727

28-
const options = [
29-
{ label: t('mod.ioKeyMap.disabled'), value: 'None' },
30-
{ label: t('mod.ioKeyMap.select'), value: 'Select' },
31-
{ label: t('mod.ioKeyMap.select1P'), value: 'Select1P' },
32-
{ label: t('mod.ioKeyMap.select2P'), value: 'Select2P' },
33-
{ label: t('mod.ioKeyMap.service'), value: 'Service' },
34-
{ label: t('mod.ioKeyMap.test'), value: 'Test' },
35-
];
28+
const options = optionsIoKeyMap(t);
3629

3730
const PREFIX = 'GameSystem.MaimollerIO.';
3831
const useLegacyEntryPath = PREFIX + 'UseLegacy';

0 commit comments

Comments
 (0)