#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: InputMapper Desc: See Header. Copyright (c) 2001-2002 by the persons listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "InputMapper.h" #include "IniFile.h" #include "GameManager.h" InputMapper* MAPPER = NULL; // global and accessable from anywhere in our program InputMapper::InputMapper() { m_sCurrentGame = GAME->m_sCurrentGame; ReadMappingsFromDisk(); } InputMapper::~InputMapper() { // don't worry about releasing the Song array. Let the OS do it :-) SaveMappingsToDisk(); } void InputMapper::ReadMappingsFromDisk() { ASSERT( GAME != NULL ); IniFile ini; ini.SetPath( m_sCurrentGame + ".ini" ); if( !ini.ReadFile() ) { return; // load nothing //FatalError( "could not read config file" ); } CMapStringToString* pKey = ini.GetKeyPointer("Input"); CString name_string, value_string; if( pKey != NULL ) { for( POSITION pos = pKey->GetStartPosition(); pos != NULL; ) { pKey->GetNextAssoc( pos, name_string, value_string ); GameInput GameI; GameI.fromString(name_string); CStringArray sDeviceInputStrings; split( value_string, ",", sDeviceInputStrings, false ); for( int i=0; iGetCurrentStyleDef(); StyleI = pStyleDef->GameInputToStyleInput( GameI ); } void InputMapper::GameToMenu( GameInput GameI, MenuInput &MenuI ) { GameDef* pGameDef = GAME->GetCurrentGameDef(); MenuI = pGameDef->GameInputToMenuInput( GameI ); } void InputMapper::StyleToGame( StyleInput StyleI, GameInput &GameI ) { StyleDef* pStyleDef = GAME->GetCurrentStyleDef(); GameI = pStyleDef->StyleInputToGameInput( StyleI ); } void InputMapper::MenuToGame( MenuInput MenuI, GameInput &GameI ) { GameDef* pGameDef = GAME->GetCurrentGameDef(); GameI = pGameDef->MenuInputToGameInput( MenuI ); } bool InputMapper::IsButtonDown( GameInput GameI ) { for( int i=0; iIsBeingPressed( DeviceI ) ) return true; } } return false; } bool InputMapper::IsButtonDown( MenuInput MenuI ) { GameInput GameI; MenuToGame( MenuI, GameI ); return IsButtonDown( GameI ); } bool InputMapper::IsButtonDown( StyleInput StyleI ) { GameInput GameI; StyleToGame( StyleI, GameI ); return IsButtonDown( GameI ); }