* refactor swing animation to controller * idle animator!!!! * implelment state switch transition * a huge fix for UI server edit! * adjust ui scaling so main menu elements clip less * view bobbing, new config name, ws: * EXTREMELY important fixes to entities rendering * a lot of fixes, add dns resolve fallback * improve f3 E, fix modal not found edge case * set correctly target for old browsers, should fix ios 14 crash * unecessary big refactor, to fix ts err * fix isWysiwyg check * fix entities rendering count
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { proxy, useSnapshot } from 'valtio'
|
|
import { subscribeKey } from 'valtio/utils'
|
|
import { useMedia } from 'react-use'
|
|
import { options, watchValue } from './optionsStorage'
|
|
import { useScale } from './react/UIProvider'
|
|
|
|
export const currentScaling = proxy({
|
|
scale: 1,
|
|
})
|
|
window.currentScaling = currentScaling
|
|
|
|
const setScale = () => {
|
|
const scaleValues = [
|
|
{ maxWidth: 980, maxHeight: null, scale: 2 },
|
|
{ maxWidth: null, maxHeight: 390, scale: 1.5 }, // todo allow to set the scaling at 360-400 (dynamic scaling setting)
|
|
{ maxWidth: 620, maxHeight: null, scale: 1 },
|
|
|
|
{ maxWidth: 620, minHeight: 240, scale: 1.4 },
|
|
]
|
|
|
|
const { innerWidth, innerHeight } = window
|
|
|
|
let result = options.guiScale
|
|
for (const { maxWidth, maxHeight, scale, minHeight } of scaleValues) {
|
|
if ((!maxWidth || innerWidth <= maxWidth) && (!maxHeight || innerHeight <= maxHeight) && (!minHeight || innerHeight >= minHeight)) {
|
|
result = scale
|
|
}
|
|
}
|
|
|
|
currentScaling.scale = result
|
|
}
|
|
|
|
|
|
setScale()
|
|
subscribeKey(options, 'guiScale', setScale)
|
|
watchValue(currentScaling, (c) => {
|
|
document.documentElement.style.setProperty('--guiScale', String(c.scale))
|
|
})
|
|
window.addEventListener('resize', setScale)
|
|
|
|
export const useAppScale = () => {
|
|
return useSnapshot(currentScaling).scale
|
|
}
|