boardzilla / boardzilla-core

Boardzilla core library
GNU Affero General Public License v3.0
174 stars 2 forks source link

redundant prompts in enterText actions #36

Open rizen opened 4 months ago

rizen commented 4 months ago

given:

game.defineActions({
    solve: player => action({ prompt: 'Solve the puzzle' })
      .enterText('guess', { prompt: 'Solve the puzzle', initial: '' })
      .do(({ guess }) => {
        if (guess.toLowerCase() == game.solution.toLowerCase())
          game.finish(player)
        else
          game.message(`${player} guessed ${guess} which was wrong`)
      }),
  });

Note how you have to define the prompt twice? The prompt inside the action is ignored and just the text box is displayed until you fill in the prompt in the options for enterText.

I'm thinking maybe enterText should inherit the prompt from the action, or just use the one from the action and get rid of the option. This eliminates redundancy.

rizen commented 4 months ago

Interestingly, if I change the code to this:

solve: player => action({ prompt: 'Solve the puzzle' })
      .chooseFrom('yes', ['Solve the Puzzle'], { skipIf: 'never' })
      .enterText('guess', { prompt: 'Solve the puzzle', initial: '' })
      .do(({ guess }) => {
        if (guess.toLowerCase() == game.solution.toLowerCase())
          game.finish(player)
        else
          game.message(`${player} guessed ${guess} which was wrong`)
      }),
Screenshot 2024-03-06 at 10 39 09 PM

Then on the subsequent after hitting the "solve the puzzle" button, it shows both prompts:

Screenshot 2024-03-06 at 10 38 11 PM

Whereas before it looked like this:

Screenshot 2024-03-06 at 10 39 56 PM

So apparently it should already work as I expected, but just doesn't