total ac (still no attributes)

This commit is contained in:
Mark
2016-01-17 20:51:52 +01:00
parent dce517bd53
commit efb2f1ffd7
3 changed files with 28 additions and 16 deletions
File diff suppressed because one or more lines are too long
@@ -44,10 +44,10 @@
</select>
</div>
<div class="col-08 vert-middle pad-r-sm">
<input type="number" name="attr_bonus" value="0" step="1">
<input type="number" name="attr_ac_bonus" value="0" step="1">
</div>
<div class="col-08 vert-middle pad-r-sm">
<input type="number" name="attr_total_ac" disabled>
<input type="number" name="attr_ac_total" class="pseudo-disabled" step="0.01">
</div>
<div class="col-14 center vert-middle">
<input type="checkbox" name="attr_stealth_pen" value="@{armor_stealth_pen}">
@@ -67,7 +67,7 @@
<div class="shaped-row center pad-t-md pad-b-md">
<div class="col-10 center pad-r-md">
<input type="number" name="attr_ac_armor_calc" value="(@{repeating_armor_0_worn} + @{repeating_armor_1_worn} + @{repeating_armor_2_worn} + @{repeating_armor_3_worn} + @{repeating_armor_4_worn} + (@{global_ac_bonus}))" disabled>
<input type="number" name="attr_ac_armor_calc" class="pseudo-disabled" step="0.01">
<div class="small-label">{{'AC_ARMORED' | translate}}</div>
</div>
+24 -12
View File
@@ -24,17 +24,20 @@ var sumRepeating = function (options) {
getSectionIDs(repeatingItem, function (ids) {
var collectionArray = [];
var finalSetAttrs = {};
finalSetAttrs[options.totalField] = 0;
for (var i = 0; i < ids.length; i++) {
collectionArray.push(repeatingItem+'_' + ids[i] + '_' + options.toggle);
if(options.qty) {
collectionArray.push(repeatingItem + '_' + ids[i] + '_' + options.qty);
}
collectionArray.push(repeatingItem+'_' + ids[i] + '_' + options.weight);
collectionArray.push(repeatingItem+'_' + ids[i] + '_' + options.fieldToAdd);
if(options.bonus) {
collectionArray.push(repeatingItem + '_' + ids[i] + '_' + options.bonus);
}
}
getAttrs(collectionArray, function (v) {
var sum = 0;
for (var j = 0; j < ids.length; j++) {
var toggle = v[repeatingItem+'_' + ids[j] + '_' + options.toggle];
if(toggle === 'undefined' || toggle === 'on') {
@@ -42,18 +45,19 @@ var sumRepeating = function (options) {
if(options.qty) {
qty = parseInt(v[repeatingItem+'_' + ids[j] + '_' + options.qty], 10) || 1;
}
var weight = parseFloat(v[repeatingItem+'_' + ids[j] + '_' + options.weight]) || 0;
var itemWeight = qty * weight;
var fieldToAdd = parseFloat(v[repeatingItem+'_' + ids[j] + '_' + options.fieldToAdd]) || 0;
if(options.bonus) {
fieldToAdd += parseFloat(v[repeatingItem+'_' + ids[j] + '_' + options.bonus]) || 0;
}
var itemTotal = qty * fieldToAdd;
if(options.itemWeight) {
finalSetAttrs[repeatingItem+'_' + ids[j] + '_' + options.itemWeight] = itemWeight;
if(options.itemTotal) {
finalSetAttrs[repeatingItem+'_' + ids[j] + '_' + options.itemTotal] = itemTotal;
}
sum += itemWeight;
finalSetAttrs[options.totalField] += itemTotal;
}
}
finalSetAttrs[options.totalField] = sum;
setAttrs(finalSetAttrs);
});
});
@@ -64,8 +68,8 @@ on('change:repeating_inventory', function () {
collection: 'inventory',
toggle: 'carried',
qty: 'qty',
weight: 'weight',
itemWeight: 'weight_total',
fieldToAdd: 'weight',
itemTotal: 'weight_total',
totalField: 'weight_inventory'
});
});
@@ -74,7 +78,15 @@ on('change:repeating_armor', function () {
sumRepeating({
collection: 'armor',
toggle: 'worn',
weight: 'weight',
fieldToAdd: 'weight',
totalField: 'weight_armor'
});
sumRepeating({
collection: 'armor',
toggle: 'worn',
fieldToAdd: 'ac_base',
bonus: 'ac_bonus',
itemTotal: 'ac_total',
totalField: 'ac_armor_calc'
});
});