diff --git a/AquaMai.Config.Editor/src/components/ConfigEntry.tsx b/AquaMai.Config.Editor/src/components/ConfigEntry.tsx index 3357fa7c..e9316cb3 100644 --- a/AquaMai.Config.Editor/src/components/ConfigEntry.tsx +++ b/AquaMai.Config.Editor/src/components/ConfigEntry.tsx @@ -3,7 +3,7 @@ import { computed, defineComponent, type PropType } from 'vue'; import { useI18n } from 'vue-i18n'; import { ENTRY_LABEL_CLASS } from '../constants'; import { modComments } from '../modComments'; -import type { ConfigEntry as ConfigEntryModel, EntryState } from '../types'; +import type { ConfigEntry as ConfigEntryModel, ConfigValue, EntryState } from '../types'; import { KeyCodeID } from '../types/KeyCodeID'; import { KeyCodeName } from '../types/KeyCodeName'; import { VKCode } from '../types/VKCode'; @@ -44,6 +44,57 @@ export function optionsVKCode(t: (key: string) => string): { label: string; valu }); } +export function optionsSoundChannel(t: (key: string) => string): { label: string; value: string }[] { + return [ + 'None', + 'P1SpeakerLeft', + 'P1SpeakerRight', + 'P1HeadphoneLeft', + 'P1HeadphoneRight', + 'P2SpeakerLeft', + 'P2SpeakerRight', + 'P2HeadphoneLeft', + 'P2HeadphoneRight', + ].map((channel) => ({ + label: t(`mod.soundChannel.${channel}`), + value: channel, + })); +} + +export function formatConfigEntryValue( + entry: ConfigEntryModel, + value: ConfigValue, + t: (key: string) => string, +): string { + if (value === null || value === undefined) { + return '-'; + } + + const stringValue = String(value); + const choices = modComments.options[entry.path]; + if (choices) { + return choices.find((item) => item.value === stringValue)?.label ?? stringValue; + } + + switch (entry.fieldType) { + case 'System.Boolean': + return value ? t('mod.on') : t('mod.off'); + case 'AquaMai.Config.Types.KeyCodeOrName': + return optionsKeyCodeOrName(t).find((item) => item.value === stringValue)?.label ?? stringValue; + case 'AquaMai.Config.Types.KeyCodeID': + return Object.entries(KeyCodeID).find(([, itemValue]) => itemValue === stringValue)?.[0] ?? stringValue; + case 'AquaMai.Config.Types.IOKeyMap': + case 'AquaMai.Config.Types.AdxKeyMap': + return optionsIoKeyMap(t).find((item) => item.value === stringValue)?.label ?? stringValue; + case 'AquaMai.Config.Types.VKCode': + return optionsVKCode(t).find((item) => item.value === stringValue)?.label ?? stringValue; + case 'AquaMai.Config.Types.SoundChannel': + return optionsSoundChannel(t).find((item) => item.value === stringValue)?.label ?? stringValue; + default: + return stringValue; + } +} + export const ConfigEntry = defineComponent({ props: { entry: { type: Object as PropType, required: true }, @@ -51,20 +102,7 @@ export const ConfigEntry = defineComponent({ }, setup(props) { const { t, te, locale } = useI18n(); - const optionsSoundChannel = [ - 'None', - 'P1SpeakerLeft', - 'P1SpeakerRight', - 'P1HeadphoneLeft', - 'P1HeadphoneRight', - 'P2SpeakerLeft', - 'P2SpeakerRight', - 'P2HeadphoneLeft', - 'P2HeadphoneRight', - ].map((channel) => ({ - label: t(`mod.soundChannel.${channel}`), - value: channel, - })); + const soundChannelOptions = optionsSoundChannel(t); const comment = computed(() => { const localeKey = `mod.commentOverrides.${props.entry.path.replace(/\./g, '_')}`; @@ -122,7 +160,7 @@ export const ConfigEntry = defineComponent({ case 'AquaMai.Config.Types.VKCode': return ; + return