86 lines
3.2 KiB
HTML
86 lines
3.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<link rel="stylesheet" type="text/css" href="styles.css">
|
|
<script src="config.js"></script>
|
|
<title>Ability Checks</title>
|
|
<style>
|
|
#results {
|
|
text-align: center; /* Center the text */
|
|
display: flex; /* Set up for centering the image */
|
|
flex-direction: column; /* Stack the content and the image vertically */
|
|
justify-content: center; /* Center the content and the image vertically */
|
|
align-items: center; /* Center the content and the image horizontally */
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<h2>Will You Succeed?</h2>
|
|
|
|
|
|
<div class="content-container">
|
|
<form id="abilityCheckForm">
|
|
<div class="form-row">
|
|
<div class="form-field" style="margin-right: 15px">
|
|
<label for="score" style="margin-right: 2px">Ability Score</label>
|
|
<input type="number" name="score" id="score" min="3" max="24" value="10">
|
|
</div>
|
|
<div class="form-field" style="margin-left: 15px">
|
|
<label for="multiplier">Multiplier</label>
|
|
<input type="number" name="multiplier" id="multiplier" min="2" max="10" value="5">
|
|
</div>
|
|
<div class="form-field" style="margin: 5px">
|
|
<button type="submit" style="margin: 3px">Roll</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<hr/>
|
|
<div id="results"></div>
|
|
|
|
<script>
|
|
document.getElementById("abilityCheckForm").addEventListener("submit", function (event) {
|
|
event.preventDefault();
|
|
|
|
let ability_score = parseInt(document.getElementById('score').value);
|
|
let multiplier = parseInt(document.getElementById('multiplier').value);
|
|
|
|
const queryParams = new URLSearchParams({
|
|
score: ability_score,
|
|
multiplier: multiplier
|
|
});
|
|
|
|
let imgElement = document.createElement('img');
|
|
imgElement.src = 'img/ability_check_loading.gif';
|
|
let results = document.getElementById('results');
|
|
results.innerHTML = '';
|
|
results.appendChild(imgElement);
|
|
|
|
fetch(`${window.BASE_URL}/gameplay/ability/check?${queryParams}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
setTimeout(() => {
|
|
results.textContent = '';
|
|
let thresholdsRolledtag = document.createElement("div");
|
|
thresholdsRolledtag.innerHTML = "<b>Roll Below: </b>" + data.threshold + " "
|
|
+ "<b>You Rolled: </b>" + data.rolled;
|
|
results.appendChild(thresholdsRolledtag)
|
|
let h2tag = document.createElement("h2");
|
|
h2tag.textContent = data.success ? "You Succeeded!" : "You Failed!";
|
|
results.appendChild(h2tag);
|
|
|
|
let imgSrc = data.success ? "img/ability_check_succeeded.gif" : "img/ability_check_failed.gif";
|
|
imgElement.src = imgSrc;
|
|
results.appendChild(imgElement);
|
|
}, 1500);
|
|
})
|
|
.catch((error) => {
|
|
console.error('Failed:', error);
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |