mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
Save and restore per-player dicts; load games that have 'em correctly.
Robots default to BasEnglish dict and humans to CollegeEng. Add new per-game default for robot dict. Still need to deal with language changes and non-English case in general.
This commit is contained in:
parent
96254ad8b5
commit
c6cd60deef
12 changed files with 156 additions and 53 deletions
|
@ -10,7 +10,7 @@ local_C_INCLUDES+= \
|
||||||
|
|
||||||
local_LDLIBS += -llog
|
local_LDLIBS += -llog
|
||||||
|
|
||||||
# local_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING
|
local_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING
|
||||||
local_DEFINES += \
|
local_DEFINES += \
|
||||||
$(local_DEBUG) \
|
$(local_DEBUG) \
|
||||||
-DXWFEATURE_RELAY \
|
-DXWFEATURE_RELAY \
|
||||||
|
|
|
@ -422,6 +422,30 @@ and_dictionary_make_empty( MPFORMAL JNIEnv* env, JNIUtilCtxt* jniutil )
|
||||||
return (DictionaryCtxt*)anddict;
|
return (DictionaryCtxt*)anddict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
|
||||||
|
jobjectArray jdicts, jobjectArray jnames )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
int ii;
|
||||||
|
jsize len = (*env)->GetArrayLength( env, jdicts );
|
||||||
|
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) );
|
||||||
|
|
||||||
|
for ( ii = 0; ii < VSIZE(dicts->dicts); ++ii ) {
|
||||||
|
DictionaryCtxt* dict = NULL;
|
||||||
|
if ( ii < len ) {
|
||||||
|
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );
|
||||||
|
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
|
||||||
|
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname );
|
||||||
|
XP_ASSERT( !!dict );
|
||||||
|
(*env)->DeleteLocalRef( env, jdict );
|
||||||
|
(*env)->DeleteLocalRef( env, jname );
|
||||||
|
}
|
||||||
|
dicts->dicts[ii] = dict;
|
||||||
|
}
|
||||||
|
LOG_RETURN_VOID();
|
||||||
|
}
|
||||||
|
|
||||||
DictionaryCtxt*
|
DictionaryCtxt*
|
||||||
makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
|
makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
|
||||||
jstring jname )
|
jstring jname )
|
||||||
|
@ -449,3 +473,16 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
|
||||||
|
|
||||||
return (DictionaryCtxt*)anddict;
|
return (DictionaryCtxt*)anddict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
destroyDicts( PlayerDicts* dicts )
|
||||||
|
{
|
||||||
|
DictionaryCtxt** ctxts = dicts->dicts;
|
||||||
|
for ( ; ; ) {
|
||||||
|
if ( !*ctxts ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dict_destroy( *ctxts );
|
||||||
|
++ctxts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes,
|
||||||
DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
|
DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
|
||||||
jbyteArray bytes, jstring jname );
|
jbyteArray bytes, jstring jname );
|
||||||
|
|
||||||
|
void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
|
||||||
|
jobjectArray jdicts, jobjectArray jnames );
|
||||||
|
|
||||||
|
void destroyDicts( PlayerDicts* dicts );
|
||||||
|
|
||||||
DictionaryCtxt* and_dictionary_make_empty( MPFORMAL JNIEnv *env,
|
DictionaryCtxt* and_dictionary_make_empty( MPFORMAL JNIEnv *env,
|
||||||
JNIUtilCtxt* jniutil );
|
JNIUtilCtxt* jniutil );
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ JNIEXPORT void JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
||||||
( JNIEnv* env, jclass C, jint gamePtr, jobject j_gi, jobject j_util,
|
( JNIEnv* env, jclass C, jint gamePtr, jobject j_gi, jobject j_util,
|
||||||
jobject jniu, jobject j_draw, jobject j_cp, jobject j_procs,
|
jobject jniu, jobject j_draw, jobject j_cp, jobject j_procs,
|
||||||
jbyteArray jDictBytes, jstring jDictName )
|
jobjectArray j_dicts, jobjectArray j_names )
|
||||||
{
|
{
|
||||||
XWJNI_START_GLOBALS();
|
XWJNI_START_GLOBALS();
|
||||||
CurGameInfo* gi = makeGI( MPPARM(mpool) env, j_gi );
|
CurGameInfo* gi = makeGI( MPPARM(mpool) env, j_gi );
|
||||||
|
@ -398,16 +398,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
||||||
game_makeNewGame( MPPARM(mpool) &state->game, gi, globals->util, dctx, &cp,
|
game_makeNewGame( MPPARM(mpool) &state->game, gi, globals->util, dctx, &cp,
|
||||||
globals->xportProcs );
|
globals->xportProcs );
|
||||||
|
|
||||||
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, globals->jniutil,
|
PlayerDicts dicts;
|
||||||
jDictBytes, jDictName );
|
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, j_dicts, j_names );
|
||||||
#ifdef STUBBED_DICT
|
#ifdef STUBBED_DICT
|
||||||
if ( !dict ) {
|
if ( !dict ) {
|
||||||
XP_LOGF( "falling back to stubbed dict" );
|
XP_LOGF( "falling back to stubbed dict" );
|
||||||
dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) );
|
dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
XP_ASSERT( !!dict );
|
model_setPlayerDicts( state->game.model, &dicts );
|
||||||
model_setDictionary( state->game.model, dict );
|
|
||||||
XWJNI_END();
|
XWJNI_END();
|
||||||
} /* makeNewGame */
|
} /* makeNewGame */
|
||||||
|
|
||||||
|
@ -439,19 +438,19 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
( JNIEnv* env, jclass C, jint gamePtr, jbyteArray jstream,
|
( JNIEnv* env, jclass C, jint gamePtr, jbyteArray jstream, jobject /*out*/jgi,
|
||||||
jobject /*out*/jgi, jbyteArray jdict, jstring jdictName, jobject jutil,
|
jobjectArray jdicts, jobjectArray jdictNames, jobject jutil, jobject jniu,
|
||||||
jobject jniu, jobject jdraw, jobject jcp, jobject jprocs )
|
jobject jdraw, jobject jcp, jobject jprocs )
|
||||||
{
|
{
|
||||||
jboolean result;
|
jboolean result;
|
||||||
|
PlayerDicts dicts;
|
||||||
XWJNI_START_GLOBALS();
|
XWJNI_START_GLOBALS();
|
||||||
|
|
||||||
globals->gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*globals->gi) );
|
globals->gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*globals->gi) );
|
||||||
globals->util = makeUtil( MPPARM(mpool) &state->env,
|
globals->util = makeUtil( MPPARM(mpool) &state->env,
|
||||||
jutil, globals->gi, globals );
|
jutil, globals->gi, globals );
|
||||||
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
|
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
|
||||||
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, globals->jniutil,
|
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, jdicts, jdictNames );
|
||||||
jdict, jdictName );
|
|
||||||
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
|
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
|
||||||
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );
|
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );
|
||||||
|
|
||||||
|
@ -461,7 +460,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
CommonPrefs cp;
|
CommonPrefs cp;
|
||||||
loadCommonPrefs( env, &cp, jcp );
|
loadCommonPrefs( env, &cp, jcp );
|
||||||
result = game_makeFromStream( MPPARM(mpool) stream, &state->game,
|
result = game_makeFromStream( MPPARM(mpool) stream, &state->game,
|
||||||
globals->gi, dict, NULL,
|
globals->gi, NULL, &dicts,
|
||||||
globals->util, globals->dctx, &cp,
|
globals->util, globals->dctx, &cp,
|
||||||
globals->xportProcs );
|
globals->xportProcs );
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
|
@ -474,8 +473,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
} else {
|
} else {
|
||||||
destroyDraw( &globals->dctx );
|
destroyDraw( &globals->dctx );
|
||||||
destroyXportProcs( &globals->xportProcs );
|
destroyXportProcs( &globals->xportProcs );
|
||||||
dict_destroy( dict );
|
destroyDicts( &dicts );
|
||||||
dict = NULL;
|
|
||||||
destroyUtil( &globals->util );
|
destroyUtil( &globals->util );
|
||||||
destroyJNIUtil( &globals->jniutil );
|
destroyJNIUtil( &globals->jniutil );
|
||||||
destroyGI( MPPARM(mpool) &globals->gi );
|
destroyGI( MPPARM(mpool) &globals->gi );
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
<string name="key_board_size">key_board_size</string>
|
<string name="key_board_size">key_board_size</string>
|
||||||
<string name="key_initial_player_minutes">key_initial_player_minutes</string>
|
<string name="key_initial_player_minutes">key_initial_player_minutes</string>
|
||||||
<string name="key_default_dict">key_default_dict</string>
|
<string name="key_default_dict">key_default_dict</string>
|
||||||
|
<string name="key_default_robodict">key_default_robodict</string>
|
||||||
<string name="key_default_phonies">key_default_phonies2</string>
|
<string name="key_default_phonies">key_default_phonies2</string>
|
||||||
<string name="key_default_timerenabled">key_default_timerenabled</string>
|
<string name="key_default_timerenabled">key_default_timerenabled</string>
|
||||||
<string name="key_connect_frequency">key_connect_frequency</string>
|
<string name="key_connect_frequency">key_connect_frequency</string>
|
||||||
|
|
|
@ -269,7 +269,9 @@
|
||||||
<string name="network_behavior_summary">Settings that apply to
|
<string name="network_behavior_summary">Settings that apply to
|
||||||
networked games</string>
|
networked games</string>
|
||||||
|
|
||||||
<string name="default_dict">Game dictionary</string>
|
<string name="default_dict">Dictionary for humans</string>
|
||||||
|
<string name="default_robodict">Dictionary for robots</string>
|
||||||
|
|
||||||
<string name="default_phonies">Handle phonies</string>
|
<string name="default_phonies">Handle phonies</string>
|
||||||
<string name="phonies_spinner_prompt">How to handle \"phonies\"
|
<string name="phonies_spinner_prompt">How to handle \"phonies\"
|
||||||
(words not in dictionary)</string>
|
(words not in dictionary)</string>
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
android:defaultValue="CollegeEng_2to8"
|
android:defaultValue="CollegeEng_2to8"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<org.eehouse.android.xw4.DictListPreference
|
||||||
|
android:key="@string/key_default_robodict"
|
||||||
|
android:title="@string/default_robodict"
|
||||||
|
android:defaultValue="BasEnglish2to8"
|
||||||
|
/>
|
||||||
|
|
||||||
<CheckBoxPreference android:key="@string/key_init_hintsallowed"
|
<CheckBoxPreference android:key="@string/key_init_hintsallowed"
|
||||||
android:title="@string/hints_allowed"
|
android:title="@string/hints_allowed"
|
||||||
android:summary="@string/hints_allowed_sum"
|
android:summary="@string/hints_allowed_sum"
|
||||||
|
|
|
@ -995,8 +995,8 @@ public class BoardActivity extends XWActivity
|
||||||
XwJNI.gi_from_stream( m_gi, stream );
|
XwJNI.gi_from_stream( m_gi, stream );
|
||||||
|
|
||||||
Utils.logf( "loadGame: dict name: %s", m_gi.dictName );
|
Utils.logf( "loadGame: dict name: %s", m_gi.dictName );
|
||||||
byte[] dictBytes = GameUtils.openDict( this, m_gi.dictName );
|
String[] dictNames = m_gi.dictNames();
|
||||||
Assert.assertNotNull( dictBytes );
|
byte[][] dictBytes = GameUtils.openDicts( this, dictNames );
|
||||||
m_jniGamePtr = XwJNI.initJNI();
|
m_jniGamePtr = XwJNI.initJNI();
|
||||||
|
|
||||||
if ( m_gi.serverRole != DeviceRole.SERVER_STANDALONE ) {
|
if ( m_gi.serverRole != DeviceRole.SERVER_STANDALONE ) {
|
||||||
|
@ -1007,12 +1007,12 @@ public class BoardActivity extends XWActivity
|
||||||
CommonPrefs cp = CommonPrefs.get( this );
|
CommonPrefs cp = CommonPrefs.get( this );
|
||||||
if ( null == stream ||
|
if ( null == stream ||
|
||||||
! XwJNI.game_makeFromStream( m_jniGamePtr, stream,
|
! XwJNI.game_makeFromStream( m_jniGamePtr, stream,
|
||||||
m_gi, dictBytes,
|
m_gi, dictBytes, dictNames,
|
||||||
m_gi.dictName, m_utils, m_jniu,
|
m_utils, m_jniu,
|
||||||
m_view, cp, m_xport ) ) {
|
m_view, cp, m_xport ) ) {
|
||||||
XwJNI.game_makeNewGame( m_jniGamePtr, m_gi, m_utils, m_jniu,
|
XwJNI.game_makeNewGame( m_jniGamePtr, m_gi, m_utils, m_jniu,
|
||||||
m_view, cp, m_xport,
|
m_view, cp, m_xport,
|
||||||
dictBytes, m_gi.dictName );
|
dictBytes, dictNames );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jniThread = new
|
m_jniThread = new
|
||||||
|
|
|
@ -172,7 +172,8 @@ public class GameUtils {
|
||||||
// loadMakeGame, if makinga new game, will add comms as long
|
// loadMakeGame, if makinga new game, will add comms as long
|
||||||
// as DeviceRole.SERVER_STANDALONE != gi.serverRole
|
// as DeviceRole.SERVER_STANDALONE != gi.serverRole
|
||||||
loadMakeGame( context, gamePtr, gi, lockSrc );
|
loadMakeGame( context, gamePtr, gi, lockSrc );
|
||||||
byte[] dictBytes = GameUtils.openDict( context, gi.dictName );
|
String[] dictNames = gi.dictNames();
|
||||||
|
byte[][] dictBytes = openDicts( context, dictNames );
|
||||||
|
|
||||||
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
||||||
addr = new CommsAddrRec( context );
|
addr = new CommsAddrRec( context );
|
||||||
|
@ -190,7 +191,7 @@ public class GameUtils {
|
||||||
gamePtr = XwJNI.initJNI();
|
gamePtr = XwJNI.initJNI();
|
||||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
||||||
CommonPrefs.get( context ), dictBytes,
|
CommonPrefs.get( context ), dictBytes,
|
||||||
gi.dictName );
|
dictNames );
|
||||||
if ( null != addr ) {
|
if ( null != addr ) {
|
||||||
XwJNI.comms_setAddr( gamePtr, addr );
|
XwJNI.comms_setAddr( gamePtr, addr );
|
||||||
}
|
}
|
||||||
|
@ -285,17 +286,18 @@ public class GameUtils {
|
||||||
{
|
{
|
||||||
byte[] stream = savedGame( context, lock );
|
byte[] stream = savedGame( context, lock );
|
||||||
XwJNI.gi_from_stream( gi, stream );
|
XwJNI.gi_from_stream( gi, stream );
|
||||||
byte[] dictBytes = GameUtils.openDict( context, gi.dictName );
|
String[] dictNames = gi.dictNames();
|
||||||
|
byte[][] dictBytes = openDicts( context, dictNames );
|
||||||
|
|
||||||
boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
||||||
JNIUtilsImpl.get(), gi,
|
JNIUtilsImpl.get(), gi,
|
||||||
dictBytes, gi.dictName,
|
dictBytes, dictNames,
|
||||||
util,
|
util,
|
||||||
CommonPrefs.get(context));
|
CommonPrefs.get(context));
|
||||||
if ( !madeGame ) {
|
if ( !madeGame ) {
|
||||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
||||||
CommonPrefs.get(context), dictBytes,
|
CommonPrefs.get(context), dictBytes,
|
||||||
gi.dictName );
|
dictNames );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,6 +488,22 @@ public class GameUtils {
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[][] openDicts( Context context, String[] names )
|
||||||
|
{
|
||||||
|
byte[][] result = new byte[names.length][];
|
||||||
|
HashMap<String,byte[]> seen = new HashMap<String,byte[]>();
|
||||||
|
for ( int ii = 0; ii < names.length; ++ii ) {
|
||||||
|
String name = names[ii];
|
||||||
|
byte[] bytes = seen.get( name );
|
||||||
|
if ( null == bytes ) {
|
||||||
|
bytes = openDict( context, name );
|
||||||
|
seen.put( name, bytes );
|
||||||
|
}
|
||||||
|
result[ii] = bytes;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean saveDict( Context context, String name, InputStream in )
|
public static boolean saveDict( Context context, String name, InputStream in )
|
||||||
{
|
{
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
@ -618,23 +636,24 @@ public class GameUtils {
|
||||||
public static void replaceDict( Context context, String path,
|
public static void replaceDict( Context context, String path,
|
||||||
String dict )
|
String dict )
|
||||||
{
|
{
|
||||||
GameLock lock = new GameLock( path, true ).lock();
|
Assert.fail();
|
||||||
byte[] stream = savedGame( context, lock );
|
// GameLock lock = new GameLock( path, true ).lock();
|
||||||
CurGameInfo gi = new CurGameInfo( context );
|
// byte[] stream = savedGame( context, lock );
|
||||||
byte[] dictBytes = GameUtils.openDict( context, dict );
|
// CurGameInfo gi = new CurGameInfo( context );
|
||||||
|
// byte[] dictBytes = openDict( context, dict );
|
||||||
|
|
||||||
int gamePtr = XwJNI.initJNI();
|
// int gamePtr = XwJNI.initJNI();
|
||||||
XwJNI.game_makeFromStream( gamePtr, stream,
|
// XwJNI.game_makeFromStream( gamePtr, stream,
|
||||||
JNIUtilsImpl.get(), gi,
|
// JNIUtilsImpl.get(), gi,
|
||||||
dictBytes, dict,
|
// dictBytes, dict,
|
||||||
CommonPrefs.get( context ) );
|
// CommonPrefs.get( context ) );
|
||||||
gi.dictName = dict;
|
// gi.dictName = dict;
|
||||||
|
|
||||||
saveGame( context, gamePtr, gi, lock, false );
|
// saveGame( context, gamePtr, gi, lock, false );
|
||||||
|
|
||||||
summarizeAndClose( context, lock, gamePtr, gi );
|
// summarizeAndClose( context, lock, gamePtr, gi );
|
||||||
|
|
||||||
lock.unlock();
|
// lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void applyChanges( Context context, CurGameInfo gi,
|
public static void applyChanges( Context context, CurGameInfo gi,
|
||||||
|
@ -645,7 +664,8 @@ public class GameUtils {
|
||||||
// somesuch. But: do we have a way to save changes to a gi
|
// somesuch. But: do we have a way to save changes to a gi
|
||||||
// that don't reset the game, e.g. player name for standalone
|
// that don't reset the game, e.g. player name for standalone
|
||||||
// games?
|
// games?
|
||||||
byte[] dictBytes = GameUtils.openDict( context, gi.dictName );
|
String[] dictNames = gi.dictNames();
|
||||||
|
byte[][] dictBytes = openDicts( context, dictNames );
|
||||||
int gamePtr = XwJNI.initJNI();
|
int gamePtr = XwJNI.initJNI();
|
||||||
boolean madeGame = false;
|
boolean madeGame = false;
|
||||||
CommonPrefs cp = CommonPrefs.get( context );
|
CommonPrefs cp = CommonPrefs.get( context );
|
||||||
|
@ -653,18 +673,18 @@ public class GameUtils {
|
||||||
if ( forceNew ) {
|
if ( forceNew ) {
|
||||||
tellRelayDied( context, lock, true );
|
tellRelayDied( context, lock, true );
|
||||||
} else {
|
} else {
|
||||||
byte[] stream = GameUtils.savedGame( context, lock );
|
byte[] stream = savedGame( context, lock );
|
||||||
// Will fail if there's nothing in the stream but a gi.
|
// Will fail if there's nothing in the stream but a gi.
|
||||||
madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
||||||
JNIUtilsImpl.get(),
|
JNIUtilsImpl.get(),
|
||||||
new CurGameInfo(context),
|
new CurGameInfo(context),
|
||||||
dictBytes, gi.dictName, cp );
|
dictBytes, dictNames, cp );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( forceNew || !madeGame ) {
|
if ( forceNew || !madeGame ) {
|
||||||
gi.setInProgress( false );
|
gi.setInProgress( false );
|
||||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
|
||||||
cp, dictBytes, gi.dictName );
|
cp, dictBytes, dictNames );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null != car ) {
|
if ( null != car ) {
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class CommonPrefs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefaultDict( Context context )
|
public static String getDefaultHumanDict( Context context )
|
||||||
{
|
{
|
||||||
String value = getString( context, R.string.key_default_dict );
|
String value = getString( context, R.string.key_default_dict );
|
||||||
if ( value.equals("") || !GameUtils.dictExists( context, value ) ) {
|
if ( value.equals("") || !GameUtils.dictExists( context, value ) ) {
|
||||||
|
@ -210,6 +210,15 @@ public class CommonPrefs {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDefaultRobotDict( Context context )
|
||||||
|
{
|
||||||
|
String value = getString( context, R.string.key_default_robodict );
|
||||||
|
if ( value.equals("") || !GameUtils.dictExists( context, value ) ) {
|
||||||
|
value = getDefaultHumanDict( context );
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public static CurGameInfo.XWPhoniesChoice
|
public static CurGameInfo.XWPhoniesChoice
|
||||||
getDefaultPhonies( Context context )
|
getDefaultPhonies( Context context )
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class CurGameInfo {
|
||||||
players = new LocalPlayer[MAX_NUM_PLAYERS];
|
players = new LocalPlayer[MAX_NUM_PLAYERS];
|
||||||
serverRole = isNetworked ? DeviceRole.SERVER_ISCLIENT
|
serverRole = isNetworked ? DeviceRole.SERVER_ISCLIENT
|
||||||
: DeviceRole.SERVER_STANDALONE;
|
: DeviceRole.SERVER_STANDALONE;
|
||||||
dictName = CommonPrefs.getDefaultDict( context );
|
dictName = CommonPrefs.getDefaultHumanDict( context );
|
||||||
dictLang = DictLangCache.getDictLangCode( context, dictName );
|
dictLang = DictLangCache.getDictLangCode( context, dictName );
|
||||||
hintsNotAllowed = !CommonPrefs.getDefaultHintsAllowed( context );
|
hintsNotAllowed = !CommonPrefs.getDefaultHintsAllowed( context );
|
||||||
phoniesAction = CommonPrefs.getDefaultPhonies( context );
|
phoniesAction = CommonPrefs.getDefaultPhonies( context );
|
||||||
|
@ -235,6 +235,17 @@ public class CurGameInfo {
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] dictNames()
|
||||||
|
{
|
||||||
|
assignDicts();
|
||||||
|
|
||||||
|
String[] result = new String[nPlayers];
|
||||||
|
for ( int ii = 0; ii < nPlayers; ++ii ) {
|
||||||
|
result[ii] = players[ii].dictName;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addPlayer()
|
public boolean addPlayer()
|
||||||
{
|
{
|
||||||
boolean added = nPlayers < MAX_NUM_PLAYERS;
|
boolean added = nPlayers < MAX_NUM_PLAYERS;
|
||||||
|
@ -306,4 +317,18 @@ public class CurGameInfo {
|
||||||
}
|
}
|
||||||
return canJuggle;
|
return canJuggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assignDicts()
|
||||||
|
{
|
||||||
|
String humanDict = CommonPrefs.getDefaultHumanDict( m_context );
|
||||||
|
int lang = DictLangCache.getDictLangCode( m_context, humanDict );
|
||||||
|
Assert.assertTrue( lang == dictLang );
|
||||||
|
String robotDict = CommonPrefs.getDefaultRobotDict( m_context );
|
||||||
|
for ( int ii = 0; ii < nPlayers; ++ii ) {
|
||||||
|
LocalPlayer lp = players[ii];
|
||||||
|
if ( null == lp.dictName ) {
|
||||||
|
lp.dictName = lp.isRobot() ? robotDict : humanDict;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,13 @@ public class XwJNI {
|
||||||
JNIUtils jniu,
|
JNIUtils jniu,
|
||||||
DrawCtx draw, CommonPrefs cp,
|
DrawCtx draw, CommonPrefs cp,
|
||||||
TransportProcs procs,
|
TransportProcs procs,
|
||||||
byte[] dict, String dictName );
|
byte[][] dicts, String[] dictNames );
|
||||||
|
|
||||||
public static native boolean game_makeFromStream( int gamePtr,
|
public static native boolean game_makeFromStream( int gamePtr,
|
||||||
byte[] stream,
|
byte[] stream,
|
||||||
CurGameInfo gi,
|
CurGameInfo gi,
|
||||||
byte[] dict,
|
byte[][] dicts,
|
||||||
String dictName,
|
String[] dictNames,
|
||||||
UtilCtxt util,
|
UtilCtxt util,
|
||||||
JNIUtils jniu,
|
JNIUtils jniu,
|
||||||
DrawCtx draw,
|
DrawCtx draw,
|
||||||
|
@ -76,19 +76,19 @@ public class XwJNI {
|
||||||
// played
|
// played
|
||||||
public static void game_makeNewGame( int gamePtr, CurGameInfo gi,
|
public static void game_makeNewGame( int gamePtr, CurGameInfo gi,
|
||||||
JNIUtils jniu, CommonPrefs cp,
|
JNIUtils jniu, CommonPrefs cp,
|
||||||
byte[] dict, String dictName ) {
|
byte[][] dicts, String[] dictNames ) {
|
||||||
game_makeNewGame( gamePtr, gi, (UtilCtxt)null, jniu,
|
game_makeNewGame( gamePtr, gi, (UtilCtxt)null, jniu,
|
||||||
(DrawCtx)null, cp, (TransportProcs)null,
|
(DrawCtx)null, cp, (TransportProcs)null,
|
||||||
dict, dictName );
|
dicts, dictNames );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean game_makeFromStream( int gamePtr,
|
public static boolean game_makeFromStream( int gamePtr,
|
||||||
byte[] stream,
|
byte[] stream,
|
||||||
JNIUtils jniu,
|
JNIUtils jniu,
|
||||||
CurGameInfo gi,
|
CurGameInfo gi,
|
||||||
byte[] dict, String dictName,
|
byte[][] dicts, String[] dictNames,
|
||||||
CommonPrefs cp ) {
|
CommonPrefs cp ) {
|
||||||
return game_makeFromStream( gamePtr, stream, gi, dict, dictName,
|
return game_makeFromStream( gamePtr, stream, gi, dicts, dictNames,
|
||||||
(UtilCtxt)null, jniu, (DrawCtx)null, cp,
|
(UtilCtxt)null, jniu, (DrawCtx)null, cp,
|
||||||
(TransportProcs)null );
|
(TransportProcs)null );
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,10 @@ public class XwJNI {
|
||||||
byte[] stream,
|
byte[] stream,
|
||||||
JNIUtils jniu,
|
JNIUtils jniu,
|
||||||
CurGameInfo gi,
|
CurGameInfo gi,
|
||||||
byte[] dict, String dictName,
|
byte[][] dicts, String[] dictNames,
|
||||||
UtilCtxt util,
|
UtilCtxt util,
|
||||||
CommonPrefs cp ) {
|
CommonPrefs cp ) {
|
||||||
return game_makeFromStream( gamePtr, stream, gi, dict, dictName,
|
return game_makeFromStream( gamePtr, stream, gi, dicts, dictNames,
|
||||||
util, jniu, (DrawCtx)null, cp,
|
util, jniu, (DrawCtx)null, cp,
|
||||||
(TransportProcs)null );
|
(TransportProcs)null );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue