diff --git a/src/index.ts b/src/index.ts index cb5d44d46..92c446c2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,7 @@ watchFov() // Create three.js context, add to page const renderer = new THREE.WebGLRenderer({ - powerPreference: options.highPerformanceGpu ? 'high-performance' : 'default', + powerPreference: options.gpuPreference, }) initWithRenderer(renderer.domElement) window.renderer = renderer diff --git a/src/optionsGuiScheme.tsx b/src/optionsGuiScheme.tsx index 07242f371..93d63cdb3 100644 --- a/src/optionsGuiScheme.tsx +++ b/src/optionsGuiScheme.tsx @@ -11,7 +11,7 @@ import { getResourcePackName, resourcePackState, uninstallTexturePack } from './ import { resetLocalStorageWithoutWorld } from './browserfs' export const guiOptionsScheme: { - [t in OptionsGroupType]: Array<{ [k in keyof AppOptions]?: Partial } & { custom?}> + [t in OptionsGroupType]: Array<{ [K in keyof AppOptions]?: Partial> } & { custom?}> } = { render: [ { @@ -31,10 +31,11 @@ export const guiOptionsScheme: { } }, { - highPerformanceGpu: { + gpuPreference: { // todo reimplement to gpu preference to allow use low-energy instead - text: 'Use Dedicated GPU', + text: 'GPU Preference', // willHaveNoEffect: isIos + values: [['default', 'Auto'], ['high-performance', 'Dedicated'], ['low-power', 'Low Power']] }, }, { diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index 8d13cb395..41678aa8b 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -26,7 +26,7 @@ const defaultOptions = { touchButtonsSize: 40, touchButtonsOpacity: 80, touchButtonsPosition: 12, - highPerformanceGpu: false, + gpuPreference: 'default' as 'default' | 'high-performance' | 'low-power', /** @unstable */ disableAssets: false, /** @unstable */ @@ -52,11 +52,19 @@ const defaultOptions = { mutedSounds: [] as string[] } +const migrateOptions = (options) => { + if (options.highPerformanceGpu) { + options.gpuPreference = 'high-performance' + delete options.highPerformanceGpu + } + return options +} + export type AppOptions = typeof defaultOptions export const options: AppOptions = proxy({ ...defaultOptions, - ...JSON.parse(localStorage.options || '{}') + ...migrateOptions(JSON.parse(localStorage.options || '{}')) }) window.options = window.settings = options diff --git a/src/react/OptionsGroup.tsx b/src/react/OptionsGroup.tsx index ebed90989..bbfac00e7 100644 --- a/src/react/OptionsGroup.tsx +++ b/src/react/OptionsGroup.tsx @@ -3,8 +3,8 @@ import { options } from '../optionsStorage' import { OptionsGroupType, guiOptionsScheme } from '../optionsGuiScheme' import OptionsItems, { OptionMeta } from './OptionsItems' -const optionValueToType = (optionValue: any) => { - if (typeof optionValue === 'boolean') return 'toggle' +const optionValueToType = (optionValue: any, item: OptionMeta) => { + if (typeof optionValue === 'boolean' || item.values) return 'toggle' if (typeof optionValue === 'number') return 'slider' if (typeof optionValue === 'string') return 'element' } @@ -14,7 +14,7 @@ const finalItemsScheme: Record = Ob return Object.entries(optionsObj).map(([optionKey, metaMerge]) => { const optionValue = options[optionKey] - const type = optionValueToType(optionValue) + const type = optionValueToType(optionValue, metaMerge) const meta: OptionMeta = { id: optionKey === 'custom' ? undefined : optionKey, type, diff --git a/src/react/OptionsItems.tsx b/src/react/OptionsItems.tsx index 92f1de5e2..5c0941e63 100644 --- a/src/react/OptionsItems.tsx +++ b/src/react/OptionsItems.tsx @@ -7,15 +7,16 @@ import Button from './Button' import Slider from './Slider' import Screen from './Screen' -type GeneralItem = { +type GeneralItem = { id?: string text?: string, disabledReason?: string, tooltip?: string willHaveNoEffect?: boolean + values?: Array } -export type OptionMeta = GeneralItem & ({ +export type OptionMeta = GeneralItem & ({ type: 'toggle', } | { type: 'slider' @@ -32,10 +33,45 @@ export type OptionMeta = GeneralItem & ({ export const OptionButton = ({ item }: { item: Extract }) => { const optionValue = useSnapshot(options)[item.id!] + const valuesTitlesMap = useMemo(() => { + if (!item.values) { + return { + true: 'ON', + false: 'OFF', + } + } + return Object.fromEntries(item.values.map((value) => { + if (typeof value === 'string') { + return [value, titleCase(noCase(value))] + } else { + return [value[0], value[1]] + } + })) + }, [item.values]) + return