diff --git a/web/rolldice.html b/web/rolldice.html index 0c729be..dcc1f4b 100644 --- a/web/rolldice.html +++ b/web/rolldice.html @@ -4,53 +4,7 @@ Gamma World Die Roller - + diff --git a/web/rolldice.js b/web/rolldice.js new file mode 100644 index 0000000..3d398dd --- /dev/null +++ b/web/rolldice.js @@ -0,0 +1,48 @@ +window.onload = function () { + document.getElementById('diceForm').addEventListener('submit', function (event) { + event.preventDefault(); // Prevent the form from submitting the normal way + + const quantity = parseInt(document.getElementById('quantity').value, 10); + const geometry = parseInt(document.getElementById('geometry').value, 10); + const discard = document.getElementById('discard').checked; + + fetch('https://gammaworld.gmgauthier.com/roll/dice', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + quantity: quantity, + geometry: geometry, + discard_lowest: discard + }), + }) + .then(response => response.json()) + .then(data => { + const resultsDiv = document.getElementById('results'); + let html = ''; + if (data['dice-set']) { + let diceSet = data['dice-set']; + html += '

Dice Set:

'; + html += ``; + } + if (data['rolls'] && quantity > 1) { + html += `

Rolls:

${data['rolls'].join(', ')}

`; + } + if (data['discarded']) { + html += `

Discarded:

${data['discarded']}

`; + } + if (data['result']) { + html += `

Result:

${data['result']}

`; + } + resultsDiv.innerHTML = html; + }) + .catch(error => { + console.error('Error:', error); + }); + }); +} \ No newline at end of file