-
Notifications
You must be signed in to change notification settings - Fork 101
/
PlayerMap.java
139 lines (124 loc) · 3.89 KB
/
PlayerMap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Mupen64PlusAE, an N64 emulator for the Android platform
*
* Copyright (C) 2013 Paul Lamb
*
* This file is part of Mupen64PlusAE.
*
* Mupen64PlusAE is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Mupen64PlusAE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Mupen64PlusAE. If
* not, see <http://www.gnu.org/licenses/>.
*
* Authors: littleguy77
*/
package paulscode.android.mupen64plusae.input.map;
import org.mupen64plusae.v3.alpha.dmult.R;
import paulscode.android.mupen64plusae.input.provider.AbstractProvider;
import android.content.Context;
import android.util.Log;
public class PlayerMap extends SerializableMap
{
/** Flag indicating whether hardware filtering is enabled. */
boolean mDisabled = true;
/**
* Instantiates a new player map.
*/
public PlayerMap()
{
}
/**
* Instantiates a new player map from a serialization.
*
* @param serializedMap The serialization of the map.
*/
public PlayerMap( String serializedMap )
{
super( serializedMap );
}
public boolean testHardware( int hardwareId, int player )
{
return mDisabled || mMap.get( hardwareId, 0 ) == player;
}
public boolean isEnabled()
{
return !mDisabled;
}
public void setEnabled( boolean value )
{
mDisabled = !value;
}
/**
* Gets a human-readable summary of the devices mapped to a player.
*
* @param context The activity context.
* @param player The index to the player.
*
* @return Description of the devices mapped to the given player.
*/
public String getDeviceSummary( Context context, int player )
{
String result = "";
for( int i = 0; i < mMap.size(); i++ )
{
if( mMap.valueAt( i ) == player )
{
int deviceId = mMap.keyAt( i );
String name = AbstractProvider.getHardwareName( deviceId );
if( name == null )
result += context.getString( R.string.playerMap_deviceWithoutName, deviceId );
else
result += context.getString( R.string.playerMap_deviceWithName, deviceId, name );
result += "\n";
}
}
return result.trim();
}
public boolean isMapped( int player )
{
return mMap.indexOfValue( player ) >= 0;
}
public void map( int hardwareId, int player )
{
if( player > 0 && player < 5 )
mMap.put( hardwareId, player );
else
Log.w( "InputMap", "Invalid player specified in map(.,.): " + player );
}
public void unmap( int hardwareId )
{
mMap.delete( hardwareId );
}
public void unmapPlayer( int player )
{
for( int index = mMap.size() - 1; index >= 0; index-- )
{
if( mMap.valueAt( index ) == player )
mMap.removeAt( index );
}
}
public void removeUnavailableMappings()
{
for( int i = mMap.size() - 1; i >= 0; i-- )
{
int id = mMap.keyAt( i );
if( !AbstractProvider.isHardwareAvailable( id ) )
{
Log.v( "PlayerMap", "Removing device " + id + " from map" );
mMap.removeAt( i );
}
}
}
@Override
public void deserialize( String s )
{
super.deserialize( s );
removeUnavailableMappings();
}
}