Skip to content

Commit

Permalink
Instead of a dropdown to decide between whether to generate a random …
Browse files Browse the repository at this point in the history
…team or a most likely team, and then a single button to do the generating, there is one button for each option.
  • Loading branch information
davidstone committed Oct 11, 2024
1 parent 446a7eb commit 71ec90b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 14 additions & 6 deletions source/tm/team_predictor/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,30 @@ add_pokemon_button.addEventListener('click', () => {
}
});

document.getElementById('generate').addEventListener('click', send_data);
document.getElementById('generate-random').addEventListener('click', send_random_data);
document.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
// Without this, the data is submitted twice
event.preventDefault();
send_data();
send_random_data();
}
});
document.getElementById('generate-most-likely').addEventListener('click', send_most_likely_data);

function send_data() {
socket.send(JSON.stringify(team_to_json()));
function send_data(style) {
socket.send(JSON.stringify(team_to_json(style)));
}

function team_to_json() {
function send_random_data() {
send_data('random');
}

function send_most_likely_data() {
send_data('most likely');
}

function team_to_json(style) {
const generation = document.getElementById('generation').value;
const style = document.getElementById('style').value;
const team = [];
const pokemon_elements = document.querySelectorAll('.pokemon');

Expand Down
7 changes: 2 additions & 5 deletions source/tm/team_predictor/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
<div class="container">
<div class="inputs">
<select id="generation"></select>
<select id="style">
<option value="most likely" selected>Most Likely</option>
<option value="random">Random</option>
</select>
<div id="team"></div>
<div id="add-pokemon-container">
<button id="add-pokemon">Add Pokémon</button>
</div>
<div id="generate-container">
<button id="generate">Generate team</button>
<button id="generate-random">Generate random team</button>
<button id="generate-most-likely">Regenerate most likely team</button>
</div>
</div>
<pre id="predicted" class="predicted"></pre>
Expand Down

0 comments on commit 71ec90b

Please sign in to comment.