import { connect } from 'react-redux' ; import Redux from 'redux' ; import { setDialog } from '../../actions/Dialog' ; import { changeSettings } from '../../actions/Settings' ; import { logEvent } from '../../Logging' ; import { AppState , DifficultyType } from '../../reducers/StateTypes' ; import Settings , { DispatchProps , fontSizeValues , StateProps , timerValues } from './Settings' ; const mapStateToProps = ( state ) : StateProps => { return { settings : state . settings , multiplayer : state . multiplayer , } ; } ; const difficultyAdd = { EASY : 'NORMAL' , NORMAL : 'HARD' , HARD : 'IMPOSSIBLE' , IMPOSSIBLE : 'EASY' , } ; const difficultySub = { EASY : 'IMPOSSIBLE' , NORMAL : 'EASY' , HARD : 'NORMAL' , IMPOSSIBLE : 'HARD' , } ; const mapDispatchToProps = ( dispatch ) : DispatchProps => { return { onAudioChange : ( v ) => { dispatch ( changeSettings ( { audioEnabled : v } ) ) ; } , onAutoRollChange : ( v ) => { dispatch ( changeSettings ( { autoRoll : v } ) ) ; } , onDifficultyDelta : ( difficulty , i ) => { if ( i > 0 ) { difficulty = difficultyAdd [ difficulty ] ; } else { difficulty = difficultySub [ difficulty ] ; } dispatch ( changeSettings ( { difficulty } ) ) ; } , onExpansionSelect : ( ) => { dispatch ( setDialog ( 'EXPANSION_SELECT' ) ) ; } , onExperimentalChange : ( v ) => { logEvent ( 'settings' , 'experimental_settings_changed_to' , { label : v . toString ( ) } ) ; dispatch ( changeSettings ( { experimental : v } ) ) ; } , onFontSizeDelta : ( idx , delta ) => { let i = idx + delta ; if ( i >= fontSizeValues . length ) { i = 0 ; } else if ( i < 0 ) { i = fontSizeValues . length - 1 ; } dispatch ( changeSettings ( { fontSize : fontSizeValues [ i ] } ) ) ; } , onMultitouchChange : ( v ) => { dispatch ( changeSettings ( { multitouch : v } ) ) ; } , onPlayerChange : ( numLocalPlayers ) => { dispatch ( changeSettings ( { numLocalPlayers } ) ) ; } , onShowHelpChange : ( v ) => { dispatch ( changeSettings ( { showHelp : v } ) ) ; } , onTimerSecondsDelta : ( idx , delta ) => { let i = idx + delta ; if ( i >= timerValues . length ) { i = 0 ; } else if ( i < 0 ) { i = timerValues . length - 1 ; } dispatch ( changeSettings ( { timerSeconds : timerValues [ i ] } ) ) ; } , onVibrationChange : ( v ) => { dispatch ( changeSettings ( { vibration : v } ) ) ; } , } ; } ; const SettingsContainer = connect ( mapStateToProps , mapDispatchToProps ) ( Settings ) ; export default SettingsContainer ;