make stuff better

This commit is contained in:
Eric House 2021-02-19 17:49:20 -08:00
parent d5b1e429ea
commit b386abcf9d
5 changed files with 46 additions and 24 deletions

View file

@ -530,7 +530,7 @@ initDeviceGlobals( Globals* globals )
{ {
globals->cp.showBoardArrow = XP_TRUE; globals->cp.showBoardArrow = XP_TRUE;
globals->cp.allowPeek = XP_TRUE; globals->cp.allowPeek = XP_TRUE;
// globals->cp.showRobotScores = XP_TRUE; globals->cp.showRobotScores = XP_TRUE;
globals->cp.sortNewTiles = XP_TRUE; globals->cp.sortNewTiles = XP_TRUE;
globals->cp.showColors = XP_TRUE; globals->cp.showColors = XP_TRUE;
@ -626,6 +626,7 @@ onReplaceConfirmed( void* closure, bool confirmed )
globals->dict, NULL, globals->dict, NULL,
globals->gs.util, globals->draw, globals->gs.util, globals->draw,
&globals->cp, &globals->procs ); &globals->cp, &globals->procs );
ensureName( globals );
const char* name = get_stored_value( KEY_PLAYER_NAME ); const char* name = get_stored_value( KEY_PLAYER_NAME );
if ( NULL != name ) { if ( NULL != name ) {
@ -789,7 +790,7 @@ loadAndDraw( Globals* globals, const NetLaunchInfo* invite,
&globals->gs.game, &globals->gs.gi, &globals->gs.game, &globals->gs.gi,
globals->gs.util, globals->draw, globals->gs.util, globals->draw,
&globals->cp, &globals->procs ); &globals->cp, &globals->procs );
nameGame( globals ); ensureName( globals );
if ( !!globals->gs.game.comms ) { if ( !!globals->gs.game.comms ) {
CommsAddrRec addr = {0}; CommsAddrRec addr = {0};
makeSelfAddr( globals, &addr ); makeSelfAddr( globals, &addr );
@ -817,7 +818,7 @@ main_onGameMessage( Globals* globals, XP_U32 gameID,
updateScreen( globals, true ); updateScreen( globals, true );
} }
} else { } else {
XP_LOGFF( "dropping packet for wrong game" ); call_alert( "dropping packet for wrong game" );
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(globals->mpool) XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(globals->mpool)
globals->vtMgr ); globals->vtMgr );
@ -1127,6 +1128,12 @@ updateScreen( Globals* globals, bool doSave )
} }
} }
void
main_updateScreen( Globals* globals )
{
updateScreen( globals, true );
}
static void static void
looper( void* closure ) looper( void* closure )
{ {

View file

@ -82,5 +82,6 @@ void main_showGameOver( Globals* globals );
void main_showRemaining( Globals* globals ); void main_showRemaining( Globals* globals );
void main_pickBlank( Globals* globals, int playerNum, int col, int row, void main_pickBlank( Globals* globals, int playerNum, int col, int row,
const char** tileFaces, int nTiles ); const char** tileFaces, int nTiles );
void main_updateScreen( Globals* globals );
#endif #endif

View file

@ -27,7 +27,7 @@ typedef struct _WasmUtilCtx {
XW_UtilCtxt super; XW_UtilCtxt super;
XW_DUtilCtxt* dctxt; XW_DUtilCtxt* dctxt;
void* closure; Globals* closure;
} WasmUtilCtx; } WasmUtilCtx;
static XWStreamCtxt* static XWStreamCtxt*
@ -36,7 +36,7 @@ wasm_util_makeStreamFromAddr( XW_UtilCtxt* uc, XWEnv xwe, XP_PlayerAddr channelN
LOG_FUNC(); LOG_FUNC();
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
XWStreamCtxt* stream = mem_stream_make( MPPARM(uc->mpool) XWStreamCtxt* stream = mem_stream_make( MPPARM(uc->mpool)
globals->vtMgr, globals, globals->vtMgr, globals,
channelNo, main_sendOnClose ); channelNo, main_sendOnClose );
@ -216,7 +216,7 @@ static void
wasm_util_userError( XW_UtilCtxt* uc, XWEnv xwe, UtilErrID id ) wasm_util_userError( XW_UtilCtxt* uc, XWEnv xwe, UtilErrID id )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
XP_Bool silent; XP_Bool silent;
const XP_UCHAR* str = wasm_getErrString( id, &silent ); const XP_UCHAR* str = wasm_getErrString( id, &silent );
if ( !silent ) { if ( !silent ) {
@ -229,10 +229,10 @@ query_proc_notifyMove( void* closure, XP_Bool confirmed )
{ {
if ( confirmed ) { if ( confirmed ) {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)closure; WasmUtilCtx* wuctxt = (WasmUtilCtx*)closure;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
if ( board_commitTurn( globals->gs.game.board, NULL, if ( board_commitTurn( globals->gs.game.board, NULL,
XP_TRUE, XP_TRUE, NULL ) ) { XP_TRUE, XP_TRUE, NULL ) ) {
board_draw( globals->gs.game.board, NULL ); main_updateScreen( globals );
} }
} }
} }
@ -241,7 +241,7 @@ static void
wasm_util_notifyMove( XW_UtilCtxt* uc, XWEnv xwe, XWStreamCtxt* stream ) wasm_util_notifyMove( XW_UtilCtxt* uc, XWEnv xwe, XWStreamCtxt* stream )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
XP_U16 len = stream_getSize( stream ); XP_U16 len = stream_getSize( stream );
XP_UCHAR buf[len+1]; XP_UCHAR buf[len+1];
@ -255,7 +255,7 @@ wasm_util_notifyTrade( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR** tiles,
XP_U16 nTiles ) XP_U16 nTiles )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
XP_UCHAR buf[128]; XP_UCHAR buf[128];
XP_SNPRINTF( buf, sizeof(buf), XP_SNPRINTF( buf, sizeof(buf),
"Are you sure you want to trade the %d selected tiles?", nTiles ); "Are you sure you want to trade the %d selected tiles?", nTiles );
@ -268,7 +268,7 @@ wasm_util_notifyPickTileBlank( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 playerNum,
const XP_UCHAR** tileFaces, XP_U16 nTiles ) const XP_UCHAR** tileFaces, XP_U16 nTiles )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_pickBlank( globals, playerNum, col, row, tileFaces, nTiles ); main_pickBlank( globals, playerNum, col, row, tileFaces, nTiles );
} }
@ -327,7 +327,7 @@ wasm_util_informMove( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 turn,
buf[len] = '\0'; buf[len] = '\0';
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_alert( globals, buf ); main_alert( globals, buf );
} }
@ -351,7 +351,7 @@ static void
wasm_util_notifyGameOver( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 quitter ) wasm_util_notifyGameOver( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 quitter )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_showGameOver( globals ); main_showGameOver( globals );
} }
@ -368,7 +368,7 @@ wasm_util_setTimer( XW_UtilCtxt* uc, XWEnv xwe, XWTimerReason why, XP_U16 when,
{ {
XP_LOGFF( "(why: %d)", why ); XP_LOGFF( "(why: %d)", why );
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_set_timer( globals, why, when, proc, closure ); main_set_timer( globals, why, when, proc, closure );
LOG_RETURN_VOID(); LOG_RETURN_VOID();
} }
@ -378,7 +378,7 @@ wasm_util_clearTimer( XW_UtilCtxt* uc, XWEnv xwe, XWTimerReason why )
{ {
LOG_FUNC(); LOG_FUNC();
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_clear_timer( globals, why ); main_clear_timer( globals, why );
} }
@ -386,7 +386,7 @@ static XP_Bool
on_idle( void* closure ) on_idle( void* closure )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)closure; WasmUtilCtx* wuctxt = (WasmUtilCtx*)closure;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
return server_do( globals->gs.game.server, NULL ); return server_do( globals->gs.game.server, NULL );
} }
@ -394,7 +394,7 @@ static void
wasm_util_requestTime( XW_UtilCtxt* uc, XWEnv xwe ) wasm_util_requestTime( XW_UtilCtxt* uc, XWEnv xwe )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_set_idle( globals, on_idle, wuctxt ); main_set_idle( globals, on_idle, wuctxt );
} }
@ -433,7 +433,7 @@ wasm_util_notifyIllegalWords( XW_UtilCtxt* uc, XWEnv xwe, BadWordInfo* bwi,
"dictionary (%s). Use anyway?", words, bwi->dictName ); "dictionary (%s). Use anyway?", words, bwi->dictName );
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_query( globals, buf, query_proc_notifyMove, uc ); main_query( globals, buf, query_proc_notifyMove, uc );
} }
@ -441,7 +441,7 @@ static void
wasm_util_remSelected( XW_UtilCtxt* uc, XWEnv xwe ) wasm_util_remSelected( XW_UtilCtxt* uc, XWEnv xwe )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_showRemaining( globals ); main_showRemaining( globals );
} }
@ -471,7 +471,7 @@ static void
wasm_util_playerScoreHeld( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 player ) wasm_util_playerScoreHeld( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 player )
{ {
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc; WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
Globals* globals = (Globals*)wuctxt->closure; Globals* globals = wuctxt->closure;
main_playerScoreHeld( globals, player ); main_playerScoreHeld( globals, player );
} }
@ -529,7 +529,7 @@ wasm_util_getDevUtilCtxt( XW_UtilCtxt* uc, XWEnv xwe )
} }
XW_UtilCtxt* XW_UtilCtxt*
wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, void* closure ) wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, Globals* closure )
{ {
LOG_FUNC(); LOG_FUNC();
WasmUtilCtx* wuctxt = XP_MALLOC( mpool, sizeof(*wuctxt) ); WasmUtilCtx* wuctxt = XP_MALLOC( mpool, sizeof(*wuctxt) );

View file

@ -23,7 +23,7 @@
#include "dutil.h" #include "dutil.h"
XW_UtilCtxt* wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dutil, XW_UtilCtxt* wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dutil,
void* closure ); Globals* closure );
void wasm_util_destroy( XW_UtilCtxt* util ); void wasm_util_destroy( XW_UtilCtxt* util );
#endif #endif

View file

@ -87,6 +87,15 @@ function mqttSend( topic, ptr ) {
return canSend; return canSend;
} }
function addDepthNote(dlg) {
let depth = dlg.parentNode.childElementCount;
if ( depth > 1 ) {
let div = document.createElement('div');
div.textContent = '(Depth: ' + depth + ')';
dlg.appendChild(div);
}
}
function newDlgWMsg(msg) { function newDlgWMsg(msg) {
let container = document.getElementById('nbalert'); let container = document.getElementById('nbalert');
@ -124,6 +133,7 @@ function nbDialog(msg, buttons, proc, closure) {
dlg.parentNode.removeChild(dlg); dlg.parentNode.removeChild(dlg);
} }
dlg.appendChild( newButtonDiv( buttons, butProc ) ); dlg.appendChild( newButtonDiv( buttons, butProc ) );
addDepthNote(dlg);
} }
function nbBlankPick(title, buttons, proc, closure) { function nbBlankPick(title, buttons, proc, closure) {
@ -139,6 +149,7 @@ function nbBlankPick(title, buttons, proc, closure) {
for (ii = 0; ii < buttons.length; ii += ROWLEN) { for (ii = 0; ii < buttons.length; ii += ROWLEN) {
dlg.appendChild( newButtonDiv( buttons.slice(ii, ii + ROWLEN), butProc ) ); dlg.appendChild( newButtonDiv( buttons.slice(ii, ii + ROWLEN), butProc ) );
} }
addDepthNote(dlg);
} }
function nbGamePick(title, gameMap, proc, closure) { function nbGamePick(title, gameMap, proc, closure) {
@ -159,6 +170,7 @@ function nbGamePick(title, gameMap, proc, closure) {
} }
dlg.appendChild( newButtonDiv( buttons, butProc ) ); dlg.appendChild( newButtonDiv( buttons, butProc ) );
addDepthNote(dlg);
} }
function setDivButtons(divid, buttons, proc, closure) { function setDivButtons(divid, buttons, proc, closure) {
@ -198,6 +210,7 @@ function nbGetString(msg, dflt, proc, closure) {
} }
} }
dlg.appendChild( newButtonDiv( buttons, butProc ) ); dlg.appendChild( newButtonDiv( buttons, butProc ) );
addDepthNote(dlg);
} }
function newRadio(txt, id, proc) { function newRadio(txt, id, proc) {
@ -238,6 +251,7 @@ function nbGetNewGame(closure, msg) {
} }
dlg.appendChild( newButtonDiv( ['Cancel', 'OK'], butProc ) ); dlg.appendChild( newButtonDiv( ['Cancel', 'OK'], butProc ) );
addDepthNote(dlg);
} }
for ( let one of ['paho-mqtt.js'] ) { for ( let one of ['paho-mqtt.js'] ) {