import Redux from 'redux' ; import { NODE_ENV } from 'shared/schema/Constants' ; import { ChangeSettingsAction } from '../actions/ActionTypes' ; import { getStorageBoolean , getStorageJson , getStorageNumber , getStorageString , setStorageKeyValue } from '../LocalStorage' ; import { ContentSetsType , DifficultyType , FontSizeType , SettingsType } from './StateTypes' ; export const initialSettings = { audioEnabled : getStorageBoolean ( 'audioEnabled' , false ) , autoRoll : getStorageBoolean ( 'autoRoll' , false ) , contentSets : getStorageJson ( 'contentSets' , { horror : null } ) as ContentSetsType , difficulty : getStorageString ( 'difficulty' , 'NORMAL' ) as DifficultyType , experimental : getStorageBoolean ( 'experimental' , false ) || NODE_ENV === 'dev' , fontSize : getStorageString ( 'fontSize' , 'NORMAL' ) as FontSizeType , multitouch : getStorageBoolean ( 'multitouch' , true ) , numLocalPlayers : getStorageNumber ( 'numLocalPlayers' , 1 ) , showHelp : getStorageBoolean ( 'showHelp' , true ) , simulator : false , timerSeconds : getStorageNumber ( 'timerSeconds' , 10 ) , vibration : getStorageBoolean ( 'vibration' , true ) , } ; export function settings ( state = initialSettings , action ) { switch ( action . type ) { case 'CHANGE_SETTINGS' : const csa = action as ChangeSettingsAction ; const changes = csa . settings || { } ; if ( csa && csa . settings . contentSets ) { changes . contentSets = { ... state . contentSets , ... csa . settings . contentSets } ; } Object . keys ( changes ) . forEach ( ( key ) => { setStorageKeyValue ( key , changes [ key ] ) ; } ) ; return { ... state , ... changes } ; default : return state ; } }