mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
store langauge name, display in title
This commit is contained in:
parent
575e61059c
commit
21b8cc0d95
3 changed files with 41 additions and 26 deletions
|
@ -65,6 +65,7 @@
|
||||||
#define KEY_GAME "game_data"
|
#define KEY_GAME "game_data"
|
||||||
#define KEY_NAME "game_name"
|
#define KEY_NAME "game_name"
|
||||||
#define KEY_NEXT_GAME "next_game"
|
#define KEY_NEXT_GAME "next_game"
|
||||||
|
#define KEY_LANG_NAME "lang_name"
|
||||||
|
|
||||||
#define BUTTON_OK "OK"
|
#define BUTTON_OK "OK"
|
||||||
#define BUTTON_CANCEL "Cancel"
|
#define BUTTON_CANCEL "Cancel"
|
||||||
|
@ -113,8 +114,8 @@ static void saveName( GameState* gs );
|
||||||
static bool isVisible( GameState* gs );
|
static bool isVisible( GameState* gs );
|
||||||
static int countDicts( Globals* globals );
|
static int countDicts( Globals* globals );
|
||||||
|
|
||||||
typedef void (*GotDictProc)(void* closure, const char* lc, const char* name,
|
typedef void (*GotDictProc)(void* closure, const char* lc, const char* langName,
|
||||||
uint8_t* data, int len);
|
const char* dictName, uint8_t* data, int len);
|
||||||
|
|
||||||
EM_JS(void, call_get_dict, (const char* lc, GotDictProc proc,
|
EM_JS(void, call_get_dict, (const char* lc, GotDictProc proc,
|
||||||
void* closure), {
|
void* closure), {
|
||||||
|
@ -492,10 +493,19 @@ updateGameButtons( Globals* globals )
|
||||||
static void
|
static void
|
||||||
showName( GameState* gs )
|
showName( GameState* gs )
|
||||||
{
|
{
|
||||||
|
Globals* globals = gs->globals;
|
||||||
const char* title = gs->gameName;
|
const char* title = gs->gameName;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
if ( true || 1 < countDicts( gs->globals ) ) {
|
if ( true || 1 < countDicts( globals ) ) {
|
||||||
sprintf( buf, "%s (%s)", gs->gameName, lcToLocale(gs->gi.dictLang) );
|
char langName[32];
|
||||||
|
const char* lc = lcToLocale(gs->gi.dictLang);
|
||||||
|
const XP_UCHAR* keys[] = {KEY_DICTS, lc, KEY_LANG_NAME, NULL };
|
||||||
|
XP_U32 len = sizeof(langName);
|
||||||
|
dutil_loadPtr( globals->dutil, NULL, keys, langName, &len );
|
||||||
|
if ( 0 != len ) {
|
||||||
|
lc = langName;
|
||||||
|
}
|
||||||
|
sprintf( buf, "%s (%s)", title, lc );
|
||||||
title = buf;
|
title = buf;
|
||||||
}
|
}
|
||||||
show_name( title );
|
show_name( title );
|
||||||
|
@ -800,11 +810,11 @@ onMqttMsg(void* closure, const uint8_t* data, int len )
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
storeAsDict(Globals* globals, const char* lc, const char* name,
|
storeAsDict(Globals* globals, const char* lc, const char* langName,
|
||||||
uint8_t* data, int len )
|
const char* dictName, uint8_t* data, int len )
|
||||||
{
|
{
|
||||||
char shortName[32];
|
char shortName[32];
|
||||||
sprintf( shortName, "%s", name );
|
sprintf( shortName, "%s", dictName );
|
||||||
char* dot = strstr(shortName, ".xwd");
|
char* dot = strstr(shortName, ".xwd");
|
||||||
if ( !!dot ) {
|
if ( !!dot ) {
|
||||||
*dot = '\0';
|
*dot = '\0';
|
||||||
|
@ -821,17 +831,20 @@ storeAsDict(Globals* globals, const char* lc, const char* name,
|
||||||
|
|
||||||
const XP_UCHAR* keys[] = {KEY_DICTS, lc, shortName, NULL};
|
const XP_UCHAR* keys[] = {KEY_DICTS, lc, shortName, NULL};
|
||||||
dutil_storePtr( globals->dutil, NULL, keys, data, len );
|
dutil_storePtr( globals->dutil, NULL, keys, data, len );
|
||||||
|
keys[2] = KEY_LANG_NAME;
|
||||||
|
dutil_storePtr( globals->dutil, NULL, keys, langName,
|
||||||
|
strlen(langName) + 1 );
|
||||||
}
|
}
|
||||||
LOG_RETURNF( "%d", success );
|
LOG_RETURNF( "%d", success );
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
onGotDict( void* closure, const char* lc, const char* name,
|
onGotDict( void* closure, const char* lc, const char* langName,
|
||||||
uint8_t* data, int len)
|
const char* dictName, uint8_t* data, int len)
|
||||||
{
|
{
|
||||||
CAST_GLOB(Globals*, globals, closure);
|
CAST_GLOB(Globals*, globals, closure);
|
||||||
if ( storeAsDict( globals, lc, name, data, len ) ) {
|
if ( storeAsDict( globals, lc, langName, dictName, data, len ) ) {
|
||||||
if ( 0 == countGames(globals) ) {
|
if ( 0 == countGames(globals) ) {
|
||||||
loadAndDraw( globals, NULL, NULL, NULL );
|
loadAndDraw( globals, NULL, NULL, NULL );
|
||||||
}
|
}
|
||||||
|
@ -947,13 +960,13 @@ typedef struct _DictDownState {
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
onDictForInvite( void* closure, const char* lc, const char* name,
|
onDictForInvite( void* closure, const char* lc, const char* langName,
|
||||||
uint8_t* data, int len )
|
const char* dictName, uint8_t* data, int len )
|
||||||
{
|
{
|
||||||
DictDownState* dds = (DictDownState*)closure;
|
DictDownState* dds = (DictDownState*)closure;
|
||||||
if ( !!data
|
if ( !!data
|
||||||
&& 0 < len
|
&& 0 < len
|
||||||
&& storeAsDict( dds->globals, lc, name, data, len ) ) {
|
&& storeAsDict( dds->globals, lc, langName, dictName, data, len ) ) {
|
||||||
loadAndDraw( dds->globals, &dds->invite, NULL, NULL );
|
loadAndDraw( dds->globals, &dds->invite, NULL, NULL );
|
||||||
} else {
|
} else {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
|
@ -1769,10 +1782,12 @@ cbckString( StringProc proc, void* closure, const char* str )
|
||||||
|
|
||||||
void
|
void
|
||||||
gotDictBinary( GotDictProc proc, void* closure, const char* xwd,
|
gotDictBinary( GotDictProc proc, void* closure, const char* xwd,
|
||||||
const char* lc, uint8_t* data, int len )
|
const char* lc, const char* langName,
|
||||||
|
uint8_t* data, int len )
|
||||||
{
|
{
|
||||||
XP_LOGFF( "lc: %s, xwd: %s; len: %d", lc, xwd, len );
|
XP_LOGFF( "lc: %s, langName: %s, xwd: %s; len: %d",
|
||||||
(*proc)(closure, lc, xwd, data, len);
|
lc, langName, xwd, len );
|
||||||
|
(*proc)(closure, lc, langName, xwd, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -196,11 +196,11 @@ wasm_dictionary_make( Globals* globals, XWEnv xwe, const char* name,
|
||||||
if ( !!result ) {
|
if ( !!result ) {
|
||||||
(void)dict_ref( &result->super, xwe );
|
(void)dict_ref( &result->super, xwe );
|
||||||
|
|
||||||
XP_U16 nf = dict_numTileFaces( &result->super );
|
/* XP_U16 nf = dict_numTileFaces( &result->super ); */
|
||||||
for ( Tile tile = 0; tile < nf; ++tile ) {
|
/* for ( Tile tile = 0; tile < nf; ++tile ) { */
|
||||||
const XP_UCHAR* face = dict_getTileString( &result->super, tile );
|
/* const XP_UCHAR* face = dict_getTileString( &result->super, tile ); */
|
||||||
XP_LOGFF( "faces[%d]: %s", tile, face );
|
/* XP_LOGFF( "faces[%d]: %s", tile, face ); */
|
||||||
}
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_RETURNF( "%p", &result->super );
|
LOG_RETURNF( "%p", &result->super );
|
||||||
|
|
|
@ -54,10 +54,10 @@ function handleFetchErrors(response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDict(langs, proc, closure) {
|
function getDict(langs, proc, closure) {
|
||||||
function callWhenDone(xwd, lc, data, len) {
|
function callWhenDone(xwd, lc, langName, data, len) {
|
||||||
Module.ccall('gotDictBinary', null,
|
Module.ccall('gotDictBinary', null,
|
||||||
['number', 'number', 'string', 'string', 'array', 'number'],
|
['number', 'number', 'string', 'string', 'string', 'array', 'number'],
|
||||||
[proc, closure, xwd, lc, data, len ]);
|
[proc, closure, xwd, lc, langName, data, len ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let gots = {}; // for later
|
let gots = {}; // for later
|
||||||
|
@ -100,10 +100,10 @@ function getDict(langs, proc, closure) {
|
||||||
// Copy data to Emscripten heap
|
// Copy data to Emscripten heap
|
||||||
var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, len);
|
var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, len);
|
||||||
dataHeap.set( new Uint8Array(data) );
|
dataHeap.set( new Uint8Array(data) );
|
||||||
callWhenDone(gots.xwd, gots.lc, dataHeap, len);
|
callWhenDone(gots.xwd, gots.lc, gots.langName, dataHeap, len);
|
||||||
Module._free(dataPtr);
|
Module._free(dataPtr);
|
||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
callWhenDone(null, null, [], 0);
|
callWhenDone(null, null, null, [], 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue