move code to unpack players list into same file as the code packing

it; add boolean, now always passed as false, to code printing names
for game config list of players to include the dictionary.  It's
useful for debugging, and I think it'd make a good optional setting,
but nobody else thinks so.  Once it's checked in the change can go if
I'm not using it.
This commit is contained in:
Andy2 2011-09-03 21:05:08 -07:00
parent a3566bc063
commit 1af358b269
5 changed files with 42 additions and 35 deletions

View file

@ -92,6 +92,7 @@
<string name="logging_on">Enable logging</string>
<string name="relay_port">Relay game port</string>
<string name="proxy_port">Relay device port</string>
<string name="name_dict_fmt">%1$s/%2$s</string>
<!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string-->

View file

@ -128,11 +128,11 @@ public class DBUtils {
setGiFlags( cursor.getInt(cursor.
getColumnIndex(DBHelper.GIFLAGS))
);
summary.players =
parsePlayers( cursor.getString(cursor.
getColumnIndex(DBHelper.
PLAYERS)),
summary.nPlayers );
String players = cursor.
getString(cursor.getColumnIndex( DBHelper.PLAYERS ));
summary.readPlayers( players );
summary.dictLang =
cursor.getInt(cursor.
getColumnIndex(DBHelper.DICTLANG));
@ -761,31 +761,6 @@ public class DBUtils {
}
}
private static String[] parsePlayers( final String players, int nPlayers ){
String[] result = null;
if ( null != players ) {
result = new String[nPlayers];
String sep = "vs. ";
if ( players.contains("\n") ) {
sep = "\n";
}
int ii, nxt;
for ( ii = 0, nxt = 0; ; ++ii ) {
int prev = nxt;
nxt = players.indexOf( sep, nxt );
String name = -1 == nxt ?
players.substring( prev ) : players.substring( prev, nxt );
result[ii] = name;
if ( -1 == nxt ) {
break;
}
nxt += sep.length();
}
}
return result;
}
private static void initDB( Context context )
{
if ( null == s_dbHelper ) {

View file

@ -625,7 +625,7 @@ public class GameConfig extends XWActivity
{
m_playerLayout.removeAllViews();
String[] names = m_gi.visibleNames();
String[] names = m_gi.visibleNames( false );
// only enable delete if one will remain (or two if networked)
boolean canDelete = names.length > 2
|| (m_notNetworkedGame && names.length > 1);

View file

@ -235,18 +235,22 @@ public class CurGameInfo {
return !consistent;
}
public String[] visibleNames()
public String[] visibleNames( boolean withDicts )
{
String nameFmt = withDicts? m_context.getString( R.string.name_dict_fmt )
: "%s";
String[] names = new String[nPlayers];
for ( int ii = 0; ii < nPlayers; ++ii ) {
LocalPlayer lp = players[ii];
if ( lp.isLocal || serverRole == DeviceRole.SERVER_STANDALONE ) {
String name;
if ( lp.isRobot() ) {
String format = m_context.getString( R.string.robot_namef );
names[ii] = String.format( format, lp.name );
name = String.format( format, lp.name );
} else {
names[ii] = lp.name;
name = lp.name;
}
names[ii] = String.format( nameFmt, name, dictName(lp) );
} else {
names[ii] = m_context.getString( R.string.guest_name );
}

View file

@ -97,6 +97,33 @@ public class GameSummary {
return result;
}
public void readPlayers( String playersStr )
{
if ( null != playersStr ) {
players = new String[nPlayers];
String sep;
if ( playersStr.contains("\n") ) {
sep = "\n";
} else {
sep = m_context.getString( R.string.vs_join );
}
int ii, nxt;
for ( ii = 0, nxt = 0; ; ++ii ) {
int prev = nxt;
nxt = playersStr.indexOf( sep, nxt );
String name = -1 == nxt ?
playersStr.substring( prev ) :
playersStr.substring( prev, nxt );
players[ii] = name;
if ( -1 == nxt ) {
break;
}
nxt += sep.length();
}
}
}
public void setPlayerSummary( String summary )
{
m_playersSummary = summary;
@ -213,7 +240,7 @@ public class GameSummary {
{
String[] names = null;
if ( null != m_gi ) {
names = m_gi.visibleNames();
names = m_gi.visibleNames( false );
} else if ( null != m_playersSummary ) {
names = TextUtils.split( m_playersSummary, "\n" );
}