#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: InputMapper Desc: See Header. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "InputMapper.h" #include "IniFile.h" #include "GameManager.h" #include "GameState.h" InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program InputMapper::InputMapper() { } InputMapper::~InputMapper() { // don't worry about releasing the Song array. Let the OS do it :-) SaveMappingsToDisk(); } void InputMapper::ReadMappingsFromDisk() { ASSERT( GAMEMAN != NULL ); IniFile ini; ini.SetPath( GAMESTATE->GetCurrentGameDef()->m_szName + CString("Map.ini") ); if( !ini.ReadFile() ) { return; // load nothing //throw RageException( "could not read config file" ); } IniFile::key* pKey = ini.GetKey( "Input" ); if( pKey == NULL ) return; for( int i=0; inames.GetSize(); i++ ) { CString name = pKey->names[i]; CString value = pKey->values[i]; GameInput GameI; GameI.fromString( name ); CStringArray sDeviceInputStrings; split( value, ",", sDeviceInputStrings, false ); for( int i=0; iGetCurrentGameDef()->m_szName + CString("Map.ini") ); // ini.ReadFile(); // don't read the file so that we overwrite everything there // iterate over our input map and write all mappings to the ini file for( int i=0; im_CurStyle == STYLE_NONE ) { StyleI.MakeBlank(); return; } StyleDef* pStyleDef = GAMESTATE->GetCurrentStyleDef(); StyleI = pStyleDef->GameInputToStyleInput( GameI ); } void InputMapper::GameToMenu( GameInput GameI, MenuInput &MenuI ) { GameDef* pGameDef = GAMESTATE->GetCurrentGameDef(); MenuI = pGameDef->GameInputToMenuInput( GameI ); } void InputMapper::StyleToGame( StyleInput StyleI, GameInput &GameI ) { StyleDef* pStyleDef = GAMESTATE->GetCurrentStyleDef(); GameI = pStyleDef->StyleInputToGameInput( StyleI ); } void InputMapper::MenuToGame( MenuInput MenuI, GameInput &GameI ) { GameDef* pGameDef = GAMESTATE->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 ); }