import { ConcreteWindow } from '../OverwolfWindows/consts' ; const debugLocations = { default : { x : 7728.177 , y : 1988.299 } as Vector2 , city : { x : 8912 , y : 5783 } as Vector2 , } ; type DeprecatedInterpolation = 'cosine-interpolation' | 'linear-interpolation' | 'cosine-extrapolation' | 'linear-extrapolation' | 'none' ; const deprecatedInterpolationKey = 'interpolation' ; const deprecatedFriendServerUrlKey = 'friendServerUrl' ; export const simpleStorageDefaultSettings = { showHeader : true , showToolbar : NWMM_APP_WINDOW === 'desktop' , transparentHeader : true , transparentToolbar : true , showText : false , showPlayerCoordinates : false , iconScale : 1.5 , zoomLevel : 2 , opacity : 1 , shape : 'none' , compassMode : true , townZoomLevel : 1 , townZoom : true , animationInterpolation : 'cosine' as AnimationInterpolation , extrapolateLocation : false , shareLocation : false , resamplingRate : 30 , lastKnownPosition : debugLocations . default , channelsServerUrl : '' , showNavMesh : false , alwaysLaunchDesktop : false , autoLaunchInGame : true , rotationSource : 'api' as RotationSource , } ; { const deprecatedInterpolation = loadUntyped ( deprecatedInterpolationKey , '' ) as DeprecatedInterpolation ; switch ( deprecatedInterpolation ) { case 'cosine-extrapolation' : store ( 'animationInterpolation' , 'cosine' ) ; store ( 'extrapolateLocation' , true ) ; break ; case 'cosine-interpolation' : store ( 'animationInterpolation' , 'cosine' ) ; store ( 'extrapolateLocation' , false ) ; break ; case 'linear-extrapolation' : store ( 'animationInterpolation' , 'linear' ) ; store ( 'extrapolateLocation' , true ) ; break ; case 'linear-interpolation' : store ( 'animationInterpolation' , 'linear' ) ; store ( 'extrapolateLocation' , false ) ; break ; } localStorage . removeItem ( deprecatedInterpolationKey ) ; } localStorage . removeItem ( deprecatedFriendServerUrlKey ) ; export type SimpleStorageSetting = typeof simpleStorageDefaultSettings ; export const scopedSettings = [ 'iconScale' , 'showHeader' , 'showText' , 'showToolbar' , 'transparentHeader' , 'transparentToolbar' , 'zoomLevel' , 'townZoomLevel' , 'townZoom' , 'animationInterpolation' , 'extrapolateLocation' , 'resamplingRate' , 'showNavMesh' , 'rotationSource' , ] ; export const iconSettingStorageScope = 'icon' ; export type KnownStorageScope = ConcreteWindow | typeof iconSettingStorageScope ; export const knownStorageScopes = [ 'desktop' , 'icon' , 'inGame' ] ; const defaultHiddenIconCategories = [ 'npc' , 'pois' ] ; export const zoomLevelSettingBounds = [ 0.5 , 50 ] as const ; /** Stores a simple storage setting. A scope will be added to the key, if the setting is a scoped setting. */ export function store < TKey extends keyof SimpleStorageSetting > ( key , value ) { let storageKey = key ; if ( scopedSettings . includes ( key ) && NWMM_APP_WINDOW ) { storageKey = NWMM_APP_WINDOW + '::' + key ; } localStorage . setItem ( storageKey , JSON . stringify ( value ) ) ; } /** Loads a simple storage setting. A scope will be added to the key, if the setting is a scoped setting. */ export function load < TKey extends keyof SimpleStorageSetting > ( key ) { let storageKey = key ; if ( scopedSettings . includes ( key ) && NWMM_APP_WINDOW ) { storageKey = NWMM_APP_WINDOW + '::' + key ; } const retrieved = localStorage . getItem ( storageKey ) ; if ( retrieved ) { return JSON . parse ( retrieved ) ; } return simpleStorageDefaultSettings [ key ] ; } function storeUntyped < T > ( key , value ) { localStorage . setItem ( key , JSON . stringify ( value ) ) ; } function loadUntyped < T > ( key , defaultValue ) { const retrieved = localStorage . getItem ( key ) ; if ( retrieved ) { return JSON . parse ( retrieved ) ; } return defaultValue ; } const iconCategoryTypeSeparator = '--' ; function getIconPropertySettingKey ( category , type , property ) { return type ? `${ iconSettingStorageScope }::${ category }${ iconCategoryTypeSeparator }${ type }.${ property }` : `${ iconSettingStorageScope }::${ category }.${ property }` ; } export function storeIconConfiguration ( category , type , property , value ) { const key = getIconPropertySettingKey ( category , type , property ) ; return storeUntyped ( key , value ) ; } export function loadIconConfiguration ( category , type , property ) { const key = getIconPropertySettingKey ( category , type , property ) ; return loadUntyped ( key , getDefaultIconConfigurationValue ( category , type , property ) ) as boolean ; } function getDefaultIconConfigurationValue ( category , type , property ) { switch ( property ) { case 'showLabel' : return true ; case 'visible' : return type ? true : ! defaultHiddenIconCategories . includes ( category ) ; } } /** Splits a storage key into its scope (if it exists and is known), and the rest of the key (which is called the identifier). */ export function getStorageKeyScope ( key ) { const potentialScope = key . split ( '::' , 2 ) as [ KnownStorageScope , string ] ; return knownStorageScopes . includes ( potentialScope [ 0 ] ) ? [ potentialScope [ 0 ] , potentialScope [ 1 ] ?? '' ] : [ undefined , key ] ; } const iconProperties = [ 'showLabel' , 'visible' ] ; param identifier returns export function deconstructIconStorageKey ( identifier ) { const propertySplit = identifier . split ( '.' ) ; if ( propertySplit . length !== 2 ) { return undefined ; } if ( ! iconProperties . includes ( propertySplit [ 1 ] as IconProperty ) ) { return undefined ; } const categoryAndType = propertySplit [ 0 ] . split ( '--' ) ; if ( categoryAndType . length < 1 || categoryAndType . length > 2 ) { return undefined ; } return { property : propertySplit [ 1 ] as IconProperty , category : categoryAndType [ 0 ] , type : categoryAndType . length === 2 ? categoryAndType [ 1 ] : undefined , } ; }