use new scheme to simplify blank picking

This commit is contained in:
Eric House 2021-02-23 12:12:32 -08:00
parent ae05e62a5a
commit 280390990f
2 changed files with 9 additions and 26 deletions

View file

@ -998,29 +998,20 @@ typedef struct _BlankPickState {
int col, row;
int nTiles;
int playerNum;
char** faces;
} BlankPickState;
static void
onBlankPicked( void* closure, const char* face )
onBlankPicked( void* closure, const char* str )
{
XP_LOGFF( "face: %s", face );
XP_LOGFF( "index: %s", str );
BlankPickState* bps = (BlankPickState*)closure;
GameState* gs = bps->gs;
Globals* globals = gs->globals;
int indx = -1;
for ( int ii = 0; ii < bps->nTiles; ++ii ) {
char* oneFace = bps->faces[ii];
if ( indx < 0 && 0 == strcmp( face, oneFace ) ) {
indx = ii;
}
XP_FREE( globals->mpool, oneFace );
}
XP_FREE( globals->mpool, bps->faces );
if ( board_setBlankValue( gs->game.board, bps->playerNum,
bps->col, bps->row, indx ) ) {
int indx = atoi(str);
if ( 0 <= indx && indx < bps->nTiles
&& board_setBlankValue( gs->game.board, bps->playerNum,
bps->col, bps->row, indx ) ) {
updateScreen( gs, true );
}
@ -1037,12 +1028,7 @@ main_pickBlank( GameState* gs, int playerNum, int col, int row,
bps->col = col;
bps->playerNum = playerNum;
bps->nTiles = nTiles;
bps->faces = XP_CALLOC( gs->globals->mpool, nTiles * sizeof(bps->faces[0]) );
for ( int ii = 0; ii < nTiles; ++ii ) {
replaceStringIfDifferent( gs->globals->mpool, &bps->faces[ii], tileFaces[ii] );
}
call_pickBlank( "Pick for your blank", tileFaces, nTiles,
call_pickBlank( "Pick a tile for your blank", tileFaces, nTiles,
onBlankPicked, bps );
}

View file

@ -179,13 +179,10 @@ function nbBlankPick(title, buttons, proc, closure) {
const butProc = function(indx) {
dlg.parentNode.removeChild(dlg);
ccallString(proc, closure, buttons[indx]);
ccallString(proc, closure, indx.toString());
}
let ROWLEN = 6;
for (ii = 0; ii < buttons.length; ii += ROWLEN) {
dlg.appendChild( newButtonDiv( buttons.slice(ii, ii + ROWLEN), butProc ) );
}
dlg.appendChild( newButtonDiv( buttons, butProc ) );
addDepthNote(dlg);
}