2021-03-21 00:07:57 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
let generate = function(seed) {
|
|
|
|
let size = document.querySelector('input[name="size"]').value
|
|
|
|
let wastelands = document.querySelector('input[name="wastelands"]').value
|
|
|
|
let mountains = document.querySelector('input[name="mountains"]').value
|
|
|
|
let ruins = document.querySelector('input[name="ruins"]').value
|
|
|
|
|
|
|
|
let map = document.querySelector('.map')
|
|
|
|
// Generate new random seed
|
2021-03-25 10:43:58 +01:00
|
|
|
let newMapParams = '?seed=' + seed +
|
2021-03-21 00:07:57 +01:00
|
|
|
'&s=' + size +
|
|
|
|
'&w=' + wastelands +
|
|
|
|
'&m=' + mountains +
|
|
|
|
'&r=' + ruins
|
2021-03-25 10:43:58 +01:00
|
|
|
document.querySelector('.map').setAttribute('src', '/map.svg' + newMapParams);
|
|
|
|
document.querySelector('#print-button').setAttribute('data-target', '/print' + newMapParams);
|
|
|
|
document.querySelector('#map-button').setAttribute('data-target', '/map.svg' + newMapParams);
|
|
|
|
document.querySelector('#map-link').setAttribute('data-target', '/map.svg' + newMapParams);
|
2021-03-21 00:07:57 +01:00
|
|
|
};
|
|
|
|
|
2021-03-23 15:18:23 +01:00
|
|
|
let actionButtons = document.querySelectorAll('button[class="action"]');
|
|
|
|
Array.prototype.forEach.call(actionButtons, function(action, i) {
|
|
|
|
action.addEventListener('click', function(e) {
|
|
|
|
document.location.href = e.target.getAttribute('data-target');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-21 00:07:57 +01:00
|
|
|
let buttons = document.querySelectorAll('input[type="button"]')
|
|
|
|
Array.prototype.forEach.call(buttons, function(button, i) {
|
|
|
|
button.addEventListener('click', function(e) {
|
|
|
|
// Reset to default buttons
|
|
|
|
if (e.target.hasAttribute('data-default')) {
|
|
|
|
let defaultValue = e.target.getAttribute('data-default');
|
|
|
|
let name = e.target.getAttribute('name').substr(8);
|
|
|
|
let targetInput = document.querySelector('input[type="text"][name="'+name+'"]')
|
|
|
|
targetInput.value = defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Roll the dice
|
|
|
|
if (e.target.getAttribute('name') === 'random-seed') {
|
|
|
|
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
let seed = '';
|
|
|
|
for (let i=0; i<10; i++) {
|
|
|
|
let index = Math.floor(Math.random() * 25)
|
|
|
|
seed += chars[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
let seedElement = document.querySelector('input[name="seed"]');
|
|
|
|
seedElement.value = seed;
|
|
|
|
generate(seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh
|
|
|
|
if (e.target.getAttribute('name') === 'refresh') {
|
|
|
|
let seed = document.querySelector('input[name="seed"]').value;
|
|
|
|
generate(seed);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|