include various options, e.g. whether hints are allowed, in data used

to clone a game prior to a rematch so they're not lost. Thanks A.B.!
This commit is contained in:
Eric House 2016-02-18 06:48:48 -08:00
parent ee0caad464
commit 33916761fb
4 changed files with 64 additions and 15 deletions

View file

@ -2679,8 +2679,7 @@ public class BoardDelegate extends DelegateBase
CommsConnTypeSet connTypes = summary.conTypes; CommsConnTypeSet connTypes = summary.conTypes;
String newName = summary.getRematchName(); String newName = summary.getRematchName();
Intent intent = GamesListDelegate Intent intent = GamesListDelegate
.makeRematchIntent( activity, rowid, gi.dictName, .makeRematchIntent( activity, rowid, gi, connTypes, btAddr,
gi.dictLang, connTypes, btAddr,
phone, relayID, newName ); phone, relayID, newName );
if ( null != intent ) { if ( null != intent ) {
activity.startActivity( intent ); activity.startActivity( intent );

View file

@ -470,7 +470,7 @@ public class GameUtils {
return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC, return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
addr, new int[] {nli.lang}, addr, new int[] {nli.lang},
new String[] { nli.dict }, nli.nPlayersT, new String[] { nli.dict }, null, nli.nPlayersT,
nli.nPlayersH, nli.forceChannel, nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID(), nli.inviteID(), nli.gameID(),
nli.gameName, false ); nli.gameName, false );
@ -479,23 +479,24 @@ public class GameUtils {
public static long makeNewMultiGame( Context context, long groupID, public static long makeNewMultiGame( Context context, long groupID,
String gameName ) String gameName )
{ {
return makeNewMultiGame( context, groupID, null, 0, return makeNewMultiGame( context, groupID, null, 0, null,
(CommsConnTypeSet)null, gameName ); (CommsConnTypeSet)null, gameName );
} }
public static long makeNewMultiGame( Context context, long groupID, public static long makeNewMultiGame( Context context, long groupID,
String dict, int lang, String dict, int lang, String jsonData,
CommsConnTypeSet addrSet, CommsConnTypeSet addrSet,
String gameName ) String gameName )
{ {
String inviteID = makeRandomID(); String inviteID = makeRandomID();
return makeNewMultiGame( context, groupID, inviteID, dict, lang, return makeNewMultiGame( context, groupID, inviteID, dict, lang,
addrSet, gameName ); jsonData, addrSet, gameName );
} }
private static long makeNewMultiGame( Context context, long groupID, private static long makeNewMultiGame( Context context, long groupID,
String inviteID, String dict, String inviteID, String dict,
int lang, CommsConnTypeSet addrSet, int lang, String jsonData,
CommsConnTypeSet addrSet,
String gameName ) String gameName )
{ {
int[] langArray = {lang}; int[] langArray = {lang};
@ -507,14 +508,16 @@ public class GameUtils {
addr.populate( context ); addr.populate( context );
int forceChannel = 0; int forceChannel = 0;
return makeNewMultiGame( context, (MultiMsgSink)null, (UtilCtxt)null, return makeNewMultiGame( context, (MultiMsgSink)null, (UtilCtxt)null,
groupID, addr, langArray, dictArray, 2, 1, groupID, addr, langArray, dictArray, jsonData,
forceChannel, inviteID, 0, gameName, true ); 2, 1, forceChannel, inviteID, 0, gameName,
true );
} }
private static long makeNewMultiGame( Context context, MultiMsgSink sink, private static long makeNewMultiGame( Context context, MultiMsgSink sink,
UtilCtxt util, long groupID, UtilCtxt util, long groupID,
CommsAddrRec addr, CommsAddrRec addr,
int[] lang, String[] dict, int[] lang, String[] dict,
String jsonData,
int nPlayersT, int nPlayersH, int nPlayersT, int nPlayersH,
int forceChannel, String inviteID, int forceChannel, String inviteID,
int gameID, String gameName, int gameID, String gameName,
@ -524,6 +527,7 @@ public class GameUtils {
Assert.assertNotNull( inviteID ); Assert.assertNotNull( inviteID );
CurGameInfo gi = new CurGameInfo( context, inviteID ); CurGameInfo gi = new CurGameInfo( context, inviteID );
gi.setFrom( jsonData );
gi.setLang( lang[0], dict[0] ); gi.setLang( lang[0], dict[0] );
gi.forceChannel = forceChannel; gi.forceChannel = forceChannel;
lang[0] = gi.dictLang; lang[0] = gi.dictLang;
@ -599,7 +603,7 @@ public class GameUtils {
} }
String inviteID = GameUtils.formatGameID( gameID ); String inviteID = GameUtils.formatGameID( gameID );
return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr, return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr,
langa, dicta, nPlayersT, nPlayersH, langa, dicta, null, nPlayersT, nPlayersH,
forceChannel, inviteID, gameID, gameName, forceChannel, inviteID, gameID, gameName,
isHost ); isHost );
} }

View file

@ -89,6 +89,7 @@ public class GamesListDelegate extends ListDelegateBase
private static final String REMATCH_ROWID_EXTRA = "rm_rowid"; private static final String REMATCH_ROWID_EXTRA = "rm_rowid";
private static final String REMATCH_DICT_EXTRA = "rm_dict"; private static final String REMATCH_DICT_EXTRA = "rm_dict";
private static final String REMATCH_LANG_EXTRA = "rm_lang"; private static final String REMATCH_LANG_EXTRA = "rm_lang";
private static final String REMATCH_PREFS_EXTRA = "rm_prefs";
private static final String REMATCH_NEWNAME_EXTRA = "rm_nnm"; private static final String REMATCH_NEWNAME_EXTRA = "rm_nnm";
private static final String REMATCH_ADDRS_EXTRA = "rm_addrs"; private static final String REMATCH_ADDRS_EXTRA = "rm_addrs";
private static final String REMATCH_BTADDR_EXTRA = "rm_btaddr"; private static final String REMATCH_BTADDR_EXTRA = "rm_btaddr";
@ -2058,6 +2059,7 @@ public class GamesListDelegate extends ListDelegateBase
String relayID = intent.getStringExtra( REMATCH_RELAYID_EXTRA ); String relayID = intent.getStringExtra( REMATCH_RELAYID_EXTRA );
String dict = intent.getStringExtra( REMATCH_DICT_EXTRA ); String dict = intent.getStringExtra( REMATCH_DICT_EXTRA );
int lang = intent.getIntExtra( REMATCH_LANG_EXTRA, -1 ); int lang = intent.getIntExtra( REMATCH_LANG_EXTRA, -1 );
String json = intent.getStringExtra( REMATCH_PREFS_EXTRA );
int bits = intent.getIntExtra( REMATCH_ADDRS_EXTRA, -1 ); int bits = intent.getIntExtra( REMATCH_ADDRS_EXTRA, -1 );
CommsConnTypeSet addrs = new CommsConnTypeSet( bits ); CommsConnTypeSet addrs = new CommsConnTypeSet( bits );
@ -2068,7 +2070,7 @@ public class GamesListDelegate extends ListDelegateBase
} else { } else {
long groupID = DBUtils.getGroupForGame( m_activity, srcRowID ); long groupID = DBUtils.getGroupForGame( m_activity, srcRowID );
newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict, newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict,
lang, addrs, gameName ); lang, json, addrs, gameName );
DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, DBUtils.addRematchInfo( m_activity, newid, btAddr, phone,
relayID ); relayID );
} }
@ -2508,7 +2510,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
public static Intent makeRematchIntent( Context context, long rowid, public static Intent makeRematchIntent( Context context, long rowid,
String dict, int lang, CurGameInfo gi,
CommsConnTypeSet addrTypes, CommsConnTypeSet addrTypes,
String btAddr, String phone, String btAddr, String phone,
String relayID, String newName ) String relayID, String newName )
@ -2517,8 +2519,9 @@ public class GamesListDelegate extends ListDelegateBase
if ( XWApp.REMATCH_SUPPORTED ) { if ( XWApp.REMATCH_SUPPORTED ) {
intent = makeSelfIntent( context ); intent = makeSelfIntent( context );
intent.putExtra( REMATCH_ROWID_EXTRA, rowid ); intent.putExtra( REMATCH_ROWID_EXTRA, rowid );
intent.putExtra( REMATCH_DICT_EXTRA, dict ); intent.putExtra( REMATCH_DICT_EXTRA, gi.dictName );
intent.putExtra( REMATCH_LANG_EXTRA, lang ); intent.putExtra( REMATCH_LANG_EXTRA, gi.dictLang );
intent.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() );
intent.putExtra( REMATCH_NEWNAME_EXTRA, newName ); intent.putExtra( REMATCH_NEWNAME_EXTRA, newName );
if ( null != addrTypes ) { if ( null != addrTypes ) {

View file

@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import junit.framework.Assert; import junit.framework.Assert;
import org.json.JSONObject;
import org.eehouse.android.xw4.DbgUtils; import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.DictUtils; import org.eehouse.android.xw4.DictUtils;
@ -37,6 +38,12 @@ public class CurGameInfo {
public static final int MAX_NUM_PLAYERS = 4; public static final int MAX_NUM_PLAYERS = 4;
private static final String BOARD_SIZE = "BOARD_SIZE";
private static final String NO_HINTS = "NO_HINTS";
private static final String TIMER = "TIMER";
private static final String ALLOW_PICK = "ALLOW_PICK";
private static final String PHONIES = "PHONIES";
public enum XWPhoniesChoice { PHONIES_IGNORE, PHONIES_WARN, PHONIES_DISALLOW }; public enum XWPhoniesChoice { PHONIES_IGNORE, PHONIES_WARN, PHONIES_DISALLOW };
public enum DeviceRole { SERVER_STANDALONE, SERVER_ISSERVER, SERVER_ISCLIENT }; public enum DeviceRole { SERVER_STANDALONE, SERVER_ISSERVER, SERVER_ISCLIENT };
@ -143,6 +150,42 @@ public class CurGameInfo {
} }
} }
public String getJSONData()
{
String jsonData = null;
try {
JSONObject obj = new JSONObject()
.put( BOARD_SIZE, boardSize )
.put( NO_HINTS, hintsNotAllowed )
.put( TIMER, timerEnabled )
.put( ALLOW_PICK, allowPickTiles )
.put( PHONIES, phoniesAction.ordinal() )
;
jsonData = obj.toString();
} catch ( org.json.JSONException jse ) {
DbgUtils.loge( jse );
}
return jsonData;
}
public void setFrom( String jsonData )
{
if ( null != jsonData ) {
try {
JSONObject obj = new JSONObject( jsonData );
boardSize = obj.optInt( BOARD_SIZE, boardSize );
hintsNotAllowed = obj.optBoolean( NO_HINTS, hintsNotAllowed );
timerEnabled = obj.optBoolean( TIMER, timerEnabled );
allowPickTiles = obj.optBoolean( ALLOW_PICK, allowPickTiles );
int tmp = obj.optInt( PHONIES, phoniesAction.ordinal() );
phoniesAction = XWPhoniesChoice.values()[tmp];
} catch ( org.json.JSONException jse ) {
DbgUtils.loge( jse );
}
}
}
public void setServerRole( DeviceRole newRole ) public void setServerRole( DeviceRole newRole )
{ {
serverRole = newRole; serverRole = newRole;