added speed and accuracy modifiers again

This commit is contained in:
lelajcorson
2021-01-09 15:21:04 -08:00
parent 09e5e9318b
commit a5e25c517c
2 changed files with 182 additions and 36 deletions
+112 -10
View File
@@ -211,20 +211,35 @@
</div>
<div class = "weapons">
<!--Accuracy and Speed-->
<input type = "checkbox" class = "toggle-calc" name = "attr_calc" value = "1">
<span class = "calc_span">Autocalculate Speed and Accuracy Modifiers</span>
<div class = "acc_speed">
<div><label class = "grid_header">SPEED</label></div>
<div><input type = "number" name = "attr_speed"></div>
<div><input class = "speed_acc_total_input" type = "number" name = "attr_speed"></div>
<input type="checkbox" class="toggle-show"/>
<div>
<span>Show Speed Modifiers</span>
<div class = "speed_mods">
<fieldset class = "repeating_speedmods">
<input type = "text" class = "speed_acc_description" name = "attr_speed_mod_type" placeholder = "Description">
<input type = "number" class = "speed_acc_mod" name = "attr_speed_mod" placeholder = "Mod">
</fieldset>
</div>
</div>
<div><label class = "grid_header">ACCURACY</label></div>
<div><input type = "number" name = "attr_acc"></div>
</div>
<div class = "speed_mods_hidden">
<fieldset>
<input type = "text" name = "attr_speed_mod_type" placeholder = "Description">
<input tyep = "text" name = "attr_speed_mod" placeholder = "Mod">
</fieldset>
<div><input class = "speed_acc_total_input" type = "number" name = "attr_acc" value = "@{accmods_0}"></div>
<input type="checkbox" class="toggle-show-acc"/>
<div>
<span>Show Accuracy Modifiers</span>
<div class = "acc_mods">
<fieldset class = "repeating_accmods">
<input type = "text" class = "speed_acc_description" name = "attr_acc_mod_type" placeholder = "Description">
<input type = "number" class = "speed_acc_mod" name = "attr_acc_mod" placeholder = "Mod">
</fieldset>
</div>
</div>
</div>
<hr>
@@ -795,4 +810,91 @@
});
});
});
</script>
<script type = "text/worker">
/* ===== PARAMETERS ==========
destinations = the name of the attribute that stores the total quantity
can be a single attribute, or an array: ['total_cost', 'total_weight']
If more than one, the matching fields must be in the same order.
section = name of repeating fieldset, without the repeating_
fields = the name of the attribute field to be summed
destination and fields both can be a single attribute: 'weight'
or an array of attributes: ['weight','number','equipped']
*/
/*Author: GiGs(G-G-G on github), with help from The Aaron, inspired by a script created by Finderski.
I found the repeatingSum function at this link: https://wiki.roll20.net/RepeatingSum and copied it directly from there. The credit for it goes to the authors above
*/
const repeatingSum = (destinations, section, fields) => {
if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')];
if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')];
getSectionIDs(`repeating_${section}`, idArray => {
const attrArray = idArray.reduce((m, id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))], []);
getAttrs([...attrArray], v => {
const getValue = (section, id, field) => v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0;
const commonMultipliers = (fields.length <= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length);
const output = {};
destinations.forEach((destination, index) => {
output[destination] = idArray.reduce((total, id) => total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) => subtotal * getValue(section, id, mult), 1), 0);
});
setAttrs(output);
});
});
};
var change = true;
on('change:repeating_speedmods:speed_mod remove:repeating_speedmods', function() {
if(change === true){
repeatingSum("speed","speedmods","speed_mod");
console.log("updating...");
}
});
on('change:repeating_accmods:acc_mod remove:repeating_accmods', function() {
if(change === true){
repeatingSum("acc","accmods","acc_mod");
console.log("updating...");
}
});
on("change:calc sheet:opened", function () {
getAttrs(["calc"], function(values) {
function updateCalc(callback){
let checked = parseInt(values.calc)||0;
if(checked === 1) {
change = true;
}
else{
change = false;
}
console.log(checked);
console.log(change);
callback();
}
function updateMods(){
console.log("calling updateMods");
if(change){
repeatingSum("acc","accmods","acc_mod");
repeatingSum("speed","speedmods","speed_mod");
console.log("updating calc one...");
}
}
//updateCalc();
updateCalc(updateMods);
});
});
</script>
+70 -26
View File
@@ -4,7 +4,7 @@ input, select, textarea{
color: #000000;
}
input, label, textarea{
input, label, textarea, span{
font-family: "Playfair Display";
}
@@ -174,29 +174,6 @@ h1{
text-align: center;
}
.sheet-acc_speed{
display: flex;
flex-wrap: wrap;
align-items: center;
}
.sheet-acc_speed label{
margin-top: 10px;
display: inline;
}
.sheet-acc_speed input{
font-size: 20px;
width: 50px;
margin-right: 10px;
margin-bottom: 10px;
}
.sheet-speed_mods_hidden{
display:none;
}
.sheet-HP_header label{
margin-top: 7px;
}
@@ -240,7 +217,7 @@ h1{
grid-row: 1 / span 5;
display: grid;
grid-template-columns: 30px auto;
grid-template-rows: 40px 160px;
grid-template-rows: 30px 160px;
column-gap: 10px;
}
@@ -249,6 +226,7 @@ h1{
grid-template-columns: 182px 50px auto;
grid-template-rows: 30px;
column-gap: 15px;
height: 30px;
}
.sheet-skills_text_grid label{
@@ -294,10 +272,76 @@ h1{
width: 180px;
}
/*Weapons*/
input.sheet-toggle-show:not(:checked) ~ div div.sheet-speed_mods{
display: none;
}
input.sheet-toggle-show-acc:not(:checked) ~ div div.sheet-acc_mods{
display: none;
}
.sheet-acc_speed .sheet-toggle-show, .sheet-acc_speed .sheet-toggle-show-acc, .sheet-acc_speed .sheet-toggle-calc{
width: 15px;
height: 15px;
margin-top: 13px;
}
.sheet-toggle-calc{
margin-bottom: 4px;
}
.sheet-acc_speed .sheet-speed_mods input, .sheet-acc_speed .sheet-acc_mods input{
font-size: 15px;
}
.sheet-acc_speed .sheet-speed_mods, .sheet-acc_speed .sheet-acc_mods{
display: block;
}
.sheet-acc_speed .sheet-speed_acc_description{
width: 125px;
}
.sheet-acc_speed .sheet-speed_acc_mod{
width: 45px;
}
.sheet-acc_speed{
display: flex;
flex-wrap: wrap;
align-items: flex-start;
}
.sheet-acc_speed label{
display: inline;
line-height: 40px;
}
.sheet-acc_speed span{
line-height: 40px;
font-size: 17px;
margin-right: 15px;
margin-left: 5px;
}
.sheet-calc_span{
line-height: 35px;
font-size: 17px;
}
.sheet-acc_speed .sheet-speed_acc_total_input{
font-size: 20px;
width: 50px;
margin-right: 10px;
margin-bottom: 10px;
}
.sheet-weapons{
grid-row: 1;
grid-col: 1;
margin-top: 10px;
}
.sheet-weapons_bio{