All things being equal, you'd just create another function that does .repeating('melee'). You could also refactor the above like this, if all the other names are the same: on('sheet:opened change:repeating_ranged_type remove:repeating_ranged_type', function (e) {
updatewoundmod ('ranged');
});
on('sheet:opened change:repeating_melee_type remove:repeating_melee_type', function (e) {
updatewoundmod ('melee');
});
function updatewoundmod(repeatingName, callback){
callback = callback || noop; // assuming noop is defined somewhere, otherwise _.noop
TAS.repeating(repeatingName)
.fields('type','wound_modifier')
.each(function(r){
switch(r.type){
case "Small Piercing (pi-)":
r.wound_modifier = "0.5";
break;
case "Large Piercing (pi+)":
case "Cutting (cut)":
r.wound_modifier = "1.5";
break;
case "Huge Piercing (pi++)":
case "Impaling (imp)":
r.wound_modifier = "2";
break;
case "Burning (burn)":
case "Corrosion (cor)":
case "Fatigue (fat)":
case "Toxic (tox)":
case "Piercing (pi)":
case "Crushing (cr)":
r.wound_modifier = "1";
break;
}
})
.execute();
};
Though I have some recollection that there is an issue with having repeating row fields with the same name as other repeating row fields in another repeating section. It's best to preface repeating row fields with their repeating section name like: <input type="number" name="attr_ranged_wound_modifier" value="0" readonly="readonly"/> In which case you could do: on('sheet:opened change:repeating_ranged_rangedtype remove:repeating_ranged_rangedtype', function (e) {
updatewoundmod ('ranged');
});
on('sheet:opened change:repeating_melee_melee_type remove:repeating_melee_melee_type', function (e) {
updatewoundmod ('melee');
});
function updatewoundmod(repeatingName, callback){
callback = callback || noop; // assuming noop is defined somewhere, otherwise _.noop
TAS.repeating(repeatingName)
.fields(
repeatingName+'_type',
repeatingName+'wound_modifier'
)
.each(function(r){
switch(r[repeatingName+'_type']){
case "Small Piercing (pi-)":
r[repeatingName+'_wound_modifier'] = "0.5";
break;
case "Large Piercing (pi+)":
case "Cutting (cut)":
r[repeatingName+'_wound_modifier'] = "1.5";
break;
case "Huge Piercing (pi++)":
case "Impaling (imp)":
r[repeatingName+'_wound_modifier'] = "2";
break;
case "Burning (burn)":
case "Corrosion (cor)":
case "Fatigue (fat)":
case "Toxic (tox)":
case "Piercing (pi)":
case "Crushing (cr)":
r[repeatingName+'_wound_modifier'] = "1";
break;
}
})
.execute();
};
It's been awhile since I touched sheet workers though, so I might be misremembering.