lots of updates
add ecnounter alpha pull out astral travel to own file zine prep fix multi-row table headers
This commit is contained in:
@@ -8,11 +8,17 @@
|
||||
* https://www.itsericwoodward.com/licenses/mit
|
||||
****************************************************************************/
|
||||
|
||||
// TODO: Add quick buttons to roll specific dice and add them to the box, along with [X] to clear
|
||||
// adding a dice looks for a matching die in the pattern and increments how many there are, or appends (if no match)
|
||||
// so clicking "d6" 3x gives you "3d6" in box
|
||||
|
||||
// Die Roller script
|
||||
const addRollerForm = () => {
|
||||
const rollerForm = document.getElementById('js-rollerForm'),
|
||||
rollerInput = document.getElementById('js-rollerInput'),
|
||||
rollerOutput = document.getElementById('js-rollerOutput');
|
||||
rollerOutput = document.getElementById('js-rollerOutput'),
|
||||
isExpressionRE =
|
||||
/(?:(?:^|[-+_*/])(?:\s*-?\d*d?\d+(\.\d+)?(?:[+-]\s*\d*d?\d+)?\s*))+$/i;
|
||||
|
||||
// double-click [x] to clear list
|
||||
rollerForm.addEventListener('reset', (e) => {
|
||||
@@ -26,18 +32,24 @@ const addRollerForm = () => {
|
||||
|
||||
const newEl = document.createElement('li'),
|
||||
// support multiple sets of dice
|
||||
rolls = rollerInput.value.split(/,\s+/);
|
||||
rolls = rollerInput.value.split(/,\s*/);
|
||||
|
||||
newEl.innerText = rolls
|
||||
.map((roll) => {
|
||||
const result = dice.roll(roll),
|
||||
stringifiedResult = dice.stringify(result);
|
||||
console.log(
|
||||
{ roll, result, stringifiedResult },
|
||||
isExpressionRE.test(roll)
|
||||
);
|
||||
return `${stringifiedResult.replaceAll(
|
||||
'!!!mods listing not yet complete!!!',
|
||||
''
|
||||
)}${
|
||||
// only show total if there's multiple dice thrown in a set
|
||||
stringifiedResult.includes(',') ? ` = ${+result}` : ''
|
||||
stringifiedResult.includes(',') || isExpressionRE.test(roll)
|
||||
? ` = ${+result}`
|
||||
: ''
|
||||
}`;
|
||||
})
|
||||
.join(', ');
|
||||
@@ -75,7 +87,7 @@ const RoomTypes = {
|
||||
const roomForm = document.getElementById('js-roomForm'),
|
||||
roomOutput = document.getElementById('js-roomOutput');
|
||||
|
||||
roomForm.addEventListener('submit', (e) => {
|
||||
roomForm?.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const newEl = document.createElement('li'),
|
||||
@@ -87,7 +99,7 @@ const RoomTypes = {
|
||||
newEl.innerText = `${roomType}${
|
||||
hasTreasure ? ' (Treasure)' : ''
|
||||
} {${roomVal},${treasureVal}}`;
|
||||
roomOutput.prepend(newEl);
|
||||
roomOutput?.prepend(newEl);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -104,7 +116,7 @@ const shuffleContainer = (parent) => {
|
||||
},
|
||||
addComplicationForm = () => {
|
||||
const complicationForm = document.getElementById('js-complicationForm');
|
||||
complicationForm.addEventListener('submit', (e) => {
|
||||
complicationForm?.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
shuffleContainer('js-complicationList');
|
||||
});
|
||||
@@ -113,7 +125,7 @@ const shuffleContainer = (parent) => {
|
||||
const complicationForm = document.getElementById(
|
||||
'js-astralComplicationForm'
|
||||
);
|
||||
complicationForm.addEventListener('submit', (e) => {
|
||||
complicationForm?.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
shuffleContainer('js-astralComplicationList');
|
||||
});
|
||||
|
Reference in New Issue
Block a user