Created
May 28, 2016 18:11
-
-
Save SCPRedMage/739114cec4d66c1208d9fff1e8a6213a to your computer and use it in GitHub Desktop.
Sheet Worker to compile attacks and spells into template macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateAttackMacro() | |
{ | |
var baseMacro = "/w \"@{character_name}\" &{template:pf_generic} @{toggle_accessible_flag} @{toggle_rounded_flag}{{color=@{rolltemplate_color}}} {{header_image=@{header_image-pf_attack-melee}}} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{subtitle}} {{name=Attacks}}"; | |
getSectionIDs("repeating_weapon", function(idarray) { | |
getAttrs(["_reporder_repeating_weapon"], function(repValues) { | |
getAttrs(_.map(idarray,function(id) { return "repeating_weapon_"+id+"_attack-type"; }), function(values) { | |
var repList = repValues._reporder_repeating_weapon.split(","); | |
repList = _.map(repList,function(ID) { return ID.toLowerCase(); }); | |
var orderedList = _.union(repList,idarray); | |
var attackIDList = _.object(_.map(orderedList,function(id) { | |
return [id,values["repeating_weapon_"+id+"_attack-type"]]; | |
})); | |
console.log(attackIDList); | |
var melee = ""; | |
var ranged = ""; | |
var cmb = ""; | |
var misc = ""; | |
_.each(orderedList, function(ID) { | |
var value = attackIDList[ID]; | |
if (value === "@{attk-melee}") | |
melee = melee + " [@{repeating_weapon_"+ID+"_name}](~@{character_name}|repeating_weapon_"+ID+"_attack-roll)"; | |
else if (value === "@{attk-ranged}") | |
ranged = ranged + " [@{repeating_weapon_"+ID+"_name}](~@{character_name}|repeating_weapon_"+ID+"_attack-roll)"; | |
else if (value === "@{CMB}") | |
cmb = cmb + " [@{repeating_weapon_"+ID+"_name}](~@{character_name}|repeating_weapon_"+ID+"_attack-roll)"; | |
else | |
misc = misc + " [@{repeating_weapon_"+ID+"_name}](~@{character_name}|repeating_weapon_"+ID+"_attack-roll)"; | |
}); | |
if (melee) | |
melee = " {{**Melee**}} {{" + melee.trim() + "}}"; | |
if (ranged) | |
ranged = " {{**Ranged**}} {{" + ranged.trim() + "}}"; | |
if (cmb) | |
cmb = " {{**Combat Maneuvers**}} {{" + cmb.trim() + "}}"; | |
if (misc) | |
misc = " {{**Misc**}} {{" + misc.trim() + "}}"; | |
var attrs = {}; | |
attrs["attacks-macro"] = baseMacro + melee + ranged + cmb + misc; | |
setAttrs(attrs); | |
}); | |
}); | |
}); | |
} | |
function updateSpellbookMacros() | |
{ | |
var class0BaseMacro = "/w \"@{character_name}\" &{template:pf_generic} @{toggle_accessible_flag} @{toggle_rounded_flag}{{color=@{rolltemplate_color}}} {{header_image=@{header_image-pf_block}}} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{subtitle}} {{name=@{spellclass-0-name} Spells}}"; | |
var class1BaseMacro = "/w \"@{character_name}\" &{template:pf_generic} @{toggle_accessible_flag} @{toggle_rounded_flag}{{color=@{rolltemplate_color}}} {{header_image=@{header_image-pf_block}}} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{subtitle}} {{name=@{spellclass-1-name} Spells}}"; | |
var class2BaseMacro = "/w \"@{character_name}\" &{template:pf_generic} @{toggle_accessible_flag} @{toggle_rounded_flag}{{color=@{rolltemplate_color}}} {{header_image=@{header_image-pf_block}}} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{subtitle}} {{name=@{spellclass-2-name} Spells}}"; | |
getSectionIDs("repeating_spells", function(idarray) { | |
getAttrs(["_reporder_repeating_spells"], function(repValues) { | |
var spellAttrs = _.map(idarray,function(id) { return "repeating_spells_"+id+"_spell_level"; }).concat(_.map(idarray,function(id) { return "repeating_spells_"+id+"_spellclass_number"; })); | |
getAttrs(spellAttrs, function(values) { | |
var orderedList; | |
if (!_.isUndefined(repValues._reporder_repeating_spells)) | |
{ | |
repList = repValues._reporder_repeating_spells.split(","); | |
repList = _.map(repList,function(ID) { return ID.toLowerCase(); }); | |
orderedList = _.union(repList,idarray); | |
} | |
else | |
orderedList = idarray; | |
var spellIDList = _.object(_.map(orderedList,function(id) { | |
return [id,{ level: values["repeating_spells_"+id+"_spell_level"], spellClass: values["repeating_spells_"+id+"_spellclass_number"] }]; | |
})); | |
var spellsArray = [["","","","","","","","","",""],["","","","","","","","","",""],["","","","","","","","","",""]]; | |
_.each(orderedList, function(ID) { | |
var spellClass; | |
if (_.isUndefined(spellIDList[ID].spellClass)) | |
spellClass = 0; | |
else | |
spellClass = parseInt(spellIDList[ID].spellClass); | |
var level; | |
if (_.isUndefined(spellIDList[ID].level)) | |
level = 0; | |
else | |
level = parseInt(spellIDList[ID].level); | |
spellsArray[spellClass][level] += " [@{repeating_spells_"+ID+"_name}](~@{character_name}|repeating_spells_"+ID+"_roll)"; | |
}); | |
_.each(spellsArray, function(lvls, spellClass) { | |
_.each(lvls, function(text,lvl) { | |
if (text !== "") | |
{ | |
spellsArray[spellClass][lvl] = " {{Level " + lvl + "}} {{" + text.trim() + "}}"; | |
} | |
}); | |
}); | |
console.log(spellsArray); | |
var attrs = {}; | |
attrs["spellclass-0-book"] = class0BaseMacro + spellsArray[0][0] + spellsArray[0][1] + spellsArray[0][2] + spellsArray[0][3] + spellsArray[0][4] + spellsArray[0][5] + spellsArray[0][6] + spellsArray[0][7] + spellsArray[0][8] + spellsArray[0][9]; | |
attrs["spellclass-1-book"] = class1BaseMacro + spellsArray[1][0] + spellsArray[1][1] + spellsArray[1][2] + spellsArray[1][3] + spellsArray[1][4] + spellsArray[1][5] + spellsArray[1][6] + spellsArray[1][7] + spellsArray[1][8] + spellsArray[1][9]; | |
attrs["spellclass-2-book"] = class2BaseMacro + spellsArray[2][0] + spellsArray[2][1] + spellsArray[2][2] + spellsArray[2][3] + spellsArray[2][4] + spellsArray[2][5] + spellsArray[2][6] + spellsArray[2][7] + spellsArray[2][8] + spellsArray[2][9]; | |
setAttrs(attrs); | |
}); | |
}); | |
}); | |
} | |
on("remove:repeating_weapon change:repeating_weapon change:_reporder_repeating_weapon", function() { | |
updateAttackMacro(); | |
}); | |
on("remove:repeating_spells change:repeating_spells change:_reporder_repeating_spells", function() { | |
updateSpellbookMacros(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment