|
|
|
@@ -8,49 +8,91 @@
|
|
|
|
|
* https://www.itsericwoodward.com/licenses/mit
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
const // Scripts for the Die Roller
|
|
|
|
|
addRollerForm = () => {
|
|
|
|
|
const rollerForm = document.getElementById('js-rollerForm'),
|
|
|
|
|
rollerInput = document.getElementById('js-rollerInput'),
|
|
|
|
|
rollerOutput = document.getElementById('js-rollerOutput');
|
|
|
|
|
// Die Roller script
|
|
|
|
|
const addRollerForm = () => {
|
|
|
|
|
const rollerForm = document.getElementById('js-rollerForm'),
|
|
|
|
|
rollerInput = document.getElementById('js-rollerInput'),
|
|
|
|
|
rollerOutput = document.getElementById('js-rollerOutput');
|
|
|
|
|
|
|
|
|
|
// double-click [x] to clear list
|
|
|
|
|
rollerForm.addEventListener('reset', (e) => {
|
|
|
|
|
if (rollerInput.value === '') rollerOutput.replaceChildren();
|
|
|
|
|
});
|
|
|
|
|
// double-click [x] to clear list
|
|
|
|
|
rollerForm.addEventListener('reset', (e) => {
|
|
|
|
|
if (rollerInput.value === '') rollerOutput.replaceChildren();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// do the roll(s) and show the (cleaned-up) result(s)
|
|
|
|
|
rollerForm.addEventListener('submit', (e) => {
|
|
|
|
|
// do the roll(s) and show the (cleaned-up) result(s)
|
|
|
|
|
rollerForm.addEventListener('submit', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!window.dice) return;
|
|
|
|
|
|
|
|
|
|
const newEl = document.createElement('li'),
|
|
|
|
|
// support multiple sets of dice
|
|
|
|
|
rolls = rollerInput.value.split(/,\s+/);
|
|
|
|
|
|
|
|
|
|
newEl.innerText = rolls
|
|
|
|
|
.map((roll) => {
|
|
|
|
|
const result = dice.roll(roll),
|
|
|
|
|
stringifiedResult = dice.stringify(result);
|
|
|
|
|
return `${stringifiedResult.replaceAll(
|
|
|
|
|
'!!!mods listing not yet complete!!!',
|
|
|
|
|
''
|
|
|
|
|
)}${
|
|
|
|
|
// only show total if there's multiple dice thrown in a set
|
|
|
|
|
stringifiedResult.includes(',') ? ` = ${+result}` : ''
|
|
|
|
|
}`;
|
|
|
|
|
})
|
|
|
|
|
.join(', ');
|
|
|
|
|
rollerOutput.prepend(newEl);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// clear on escape key
|
|
|
|
|
rollerForm.addEventListener('keydown', (event) => {
|
|
|
|
|
if (event.key === 'Escape') rollerForm.reset();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Dungeon room populator
|
|
|
|
|
const RoomTypes = {
|
|
|
|
|
EMPTY: 2,
|
|
|
|
|
MONSTER: 4,
|
|
|
|
|
SPECIAL: 5,
|
|
|
|
|
TRAP: 6,
|
|
|
|
|
},
|
|
|
|
|
getRoomType = (room = 1) => {
|
|
|
|
|
if (room <= RoomTypes.EMPTY) return 'Empty';
|
|
|
|
|
if (room <= RoomTypes.MONSTER) return 'Monster';
|
|
|
|
|
if (room <= RoomTypes.SPECIAL) return 'Special';
|
|
|
|
|
return 'Trap';
|
|
|
|
|
},
|
|
|
|
|
checkForTreasure = (room = 1, treasure = 1) => {
|
|
|
|
|
if (room <= RoomTypes.EMPTY) return treasure <= 1;
|
|
|
|
|
if (room <= RoomTypes.MONSTER) return treasure <= 3;
|
|
|
|
|
if (room <= RoomTypes.SPECIAL) return false;
|
|
|
|
|
return treasure <= 2;
|
|
|
|
|
},
|
|
|
|
|
getRandomValue = (max = 1, min = 1) =>
|
|
|
|
|
Math.round(Math.random() * (max - min)) + min,
|
|
|
|
|
addRoomForm = () => {
|
|
|
|
|
const roomForm = document.getElementById('js-roomForm'),
|
|
|
|
|
roomOutput = document.getElementById('js-roomOutput');
|
|
|
|
|
|
|
|
|
|
roomForm.addEventListener('submit', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!window.dice) return;
|
|
|
|
|
|
|
|
|
|
const newEl = document.createElement('li'),
|
|
|
|
|
// support multiple sets of dice
|
|
|
|
|
rolls = rollerInput.value.split(/,\s+/);
|
|
|
|
|
roomVal = getRandomValue(6),
|
|
|
|
|
treasureVal = getRandomValue(6),
|
|
|
|
|
roomType = getRoomType(roomVal),
|
|
|
|
|
hasTreasure = checkForTreasure(roomVal, treasureVal);
|
|
|
|
|
|
|
|
|
|
newEl.innerText = rolls
|
|
|
|
|
.map((roll) => {
|
|
|
|
|
const result = dice.roll(roll),
|
|
|
|
|
stringifiedResult = dice.stringify(result);
|
|
|
|
|
return `${stringifiedResult.replaceAll(
|
|
|
|
|
'!!!mods listing not yet complete!!!',
|
|
|
|
|
''
|
|
|
|
|
)}${
|
|
|
|
|
// only show total if there's multiple dice thrown in a set
|
|
|
|
|
stringifiedResult.includes(',') ? ` = ${+result}` : ''
|
|
|
|
|
}`;
|
|
|
|
|
})
|
|
|
|
|
.join(', ');
|
|
|
|
|
rollerOutput.prepend(newEl);
|
|
|
|
|
newEl.innerText = `${roomType}${
|
|
|
|
|
hasTreasure ? ' (Treasure)' : ''
|
|
|
|
|
} {${roomVal},${treasureVal}}`;
|
|
|
|
|
roomOutput.prepend(newEl);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// clear on escape key
|
|
|
|
|
rollerForm.addEventListener('keydown', (event) => {
|
|
|
|
|
if (event.key === 'Escape') rollerForm.reset();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// Scripts for the Complication Randomizers
|
|
|
|
|
shuffleContainer = (parent) => {
|
|
|
|
|
// Complication Randomizer scripts
|
|
|
|
|
const shuffleContainer = (parent) => {
|
|
|
|
|
const container = document.getElementById(parent),
|
|
|
|
|
children = container.children,
|
|
|
|
|
length = children.length,
|
|
|
|
@@ -79,6 +121,7 @@ const // Scripts for the Die Roller
|
|
|
|
|
|
|
|
|
|
export default (() => {
|
|
|
|
|
addRollerForm();
|
|
|
|
|
addRoomForm();
|
|
|
|
|
addComplicationForm();
|
|
|
|
|
addAstralComplicationForm();
|
|
|
|
|
})();
|
|
|
|
|