mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-14 08:59:16 +02:00
Controller customization feature
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { PrefKey, StorageKey } from "@/enums/pref-keys";
|
||||
import type { PrefKey, PrefTypeMap, StorageKey } from "@/enums/pref-keys";
|
||||
import type { NumberStepperParams, SettingAction, SettingDefinitions } from "@/types/setting-definition";
|
||||
import { t } from "../translation";
|
||||
import { SCRIPT_VARIANT } from "../global";
|
||||
@@ -63,20 +63,20 @@ export class BaseSettingsStore {
|
||||
return this.definitions[key];
|
||||
}
|
||||
|
||||
getSetting<T=boolean>(key: PrefKey, checkUnsupported = true): T {
|
||||
getSetting<T extends keyof PrefTypeMap>(key: T, checkUnsupported = true): PrefTypeMap[T] {
|
||||
const definition = this.definitions[key];
|
||||
|
||||
// Return default value if build variant is different
|
||||
if (definition.requiredVariants && !definition.requiredVariants.includes(SCRIPT_VARIANT)) {
|
||||
return definition.default as T;
|
||||
return definition.default as PrefTypeMap[T];
|
||||
}
|
||||
|
||||
// Return default value if the feature is not supported
|
||||
if (checkUnsupported && definition.unsupported) {
|
||||
if ('unsupportedValue' in definition) {
|
||||
return definition.unsupportedValue as T;
|
||||
return definition.unsupportedValue as PrefTypeMap[T];
|
||||
} else {
|
||||
return definition.default as T;
|
||||
return definition.default as PrefTypeMap[T];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ export class BaseSettingsStore {
|
||||
this.settings[key] = this.validateValue('get', key, null);
|
||||
}
|
||||
|
||||
return this.settings[key] as T;
|
||||
return this.settings[key] as PrefTypeMap[T];
|
||||
}
|
||||
|
||||
setSetting<T=any>(key: PrefKey, value: T, emitEvent = false) {
|
||||
|
@@ -8,7 +8,7 @@ import { CE } from "../html";
|
||||
import { t, SUPPORTED_LANGUAGES } from "../translation";
|
||||
import { UserAgent } from "../user-agent";
|
||||
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
|
||||
import { CodecProfile, StreamResolution, TouchControllerMode, TouchControllerStyleStandard, TouchControllerStyleCustom, GameBarPosition, DeviceVibrationMode, NativeMkbMode, UiLayout, UiSection, StreamPlayerType, StreamVideoProcessing, VideoRatio, StreamStat, VideoPosition, BlockFeature } from "@/enums/pref-values";
|
||||
import { CodecProfile, StreamResolution, TouchControllerMode, TouchControllerStyleStandard, TouchControllerStyleCustom, GameBarPosition, DeviceVibrationMode, NativeMkbMode, UiLayout, UiSection, StreamPlayerType, StreamVideoProcessing, VideoRatio, StreamStat, VideoPosition, BlockFeature, StreamStatPosition, VideoPowerPreference } from "@/enums/pref-values";
|
||||
import { MkbMappingDefaultPresetId } from "../local-db/mkb-mapping-presets-table";
|
||||
import { KeyboardShortcutDefaultId } from "../local-db/keyboard-shortcuts-table";
|
||||
import { GhPagesUtils } from "../gh-pages";
|
||||
@@ -322,7 +322,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||
label: t('enable-local-co-op-support'),
|
||||
default: false,
|
||||
note: () => CE('div', {},
|
||||
CE<HTMLAnchorElement>('a', {
|
||||
CE('a', {
|
||||
href: 'https://github.com/redphx/better-xcloud/discussions/275',
|
||||
target: '_blank',
|
||||
}, t('enable-local-co-op-support-note')),
|
||||
@@ -399,7 +399,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
|
||||
}
|
||||
|
||||
setting.unsupportedNote = () => CE<HTMLAnchorElement>('a', {
|
||||
setting.unsupportedNote = () => CE('a', {
|
||||
href: url,
|
||||
target: '_blank',
|
||||
}, '⚠️ ' + note);
|
||||
@@ -649,11 +649,11 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||
},
|
||||
[PrefKey.VIDEO_POWER_PREFERENCE]: {
|
||||
label: t('renderer-configuration'),
|
||||
default: 'default',
|
||||
default: VideoPowerPreference.DEFAULT,
|
||||
options: {
|
||||
default: t('default'),
|
||||
'low-power': t('battery-saving'),
|
||||
'high-performance': t('high-performance'),
|
||||
[VideoPowerPreference.DEFAULT]: t('default'),
|
||||
[VideoPowerPreference.LOW_POWER]: t('battery-saving'),
|
||||
[VideoPowerPreference.HIGH_PERFORMANCE]: t('high-performance'),
|
||||
},
|
||||
suggest: {
|
||||
highest: 'low-power',
|
||||
@@ -813,11 +813,11 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||
},
|
||||
[PrefKey.STATS_POSITION]: {
|
||||
label: t('position'),
|
||||
default: 'top-right',
|
||||
default: StreamStatPosition.TOP_RIGHT,
|
||||
options: {
|
||||
'top-left': t('top-left'),
|
||||
'top-center': t('top-center'),
|
||||
'top-right': t('top-right'),
|
||||
[StreamStatPosition.TOP_LEFT]: t('top-left'),
|
||||
[StreamStatPosition.TOP_CENTER]: t('top-center'),
|
||||
[StreamStatPosition.TOP_RIGHT]: t('top-right'),
|
||||
},
|
||||
},
|
||||
[PrefKey.STATS_TEXT_SIZE]: {
|
||||
|
Reference in New Issue
Block a user