Code: Select all
Got but json.sort only accepts JSON Arrays.
Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice
Code: Select all
Got but json.sort only accepts JSON Arrays.
Code: Select all
[H: groupList = json.sort(json.fields(allMacros,"json"),"a")]
Code: Select all
@@dumpMacros
@PROPS@ autoExecute=true ; color=green ; fontColor=black ; group= ; includeLabel=false ; sortBy=8 ; index=1 ; fontSize=1.00em ; minWidth= ; playerEditable=false ; maxWidth= ; tooltip= ; applyToSelected=false ;
[h: switchToken(macro.args)]
[h: allMacros = getMacroGroups()]
[H: groupList = json.sort(json.fields(allMacros,"json"),"a")]
[H: group_0 = 0]
[H: inputStr = "group_0|All Groups,Group Select|Select Group Export|RADIO"]
[H: groupLength = json.length(groupList)]
[H, C(groupLength): inputStr = json.append(inputStr,
strformat("group_%d|0|%s|CHECK",roll.count+1,if(json.get(groupList,roll.count) == " ","Default",json.get(groupList,roll.count))))]
[H: hasInput = input(json.toList(inputStr,"##"))]
[H: groupFilter = ""]
[H, if(group_0 == 1 && groupLength > 1), code: {
[H, C(groupLength), code: {
[H: nameValue = eval("group_"+(roll.count+1))]
[H, if(nameValue): groupFilter = json.append(groupFilter,json.get(groupList,roll.count))]
}]
};{
[H, if(hasInput): groupFilter = groupList; groupFilter = ""]
}]
[h: output = ""]
[h: newLine = "%0A"]
[H, foreach(iGroup,groupFilter), code: {
[H, if(json.isEmpty(iGroup)): iGroup = " "]
[H: gMacros = json.get(allMacros,iGroup)]
[H: gMacros = json.sort(gMacros,"a","sortBy","label")]
[H, foreach(iMacro,gMacros), code: {
[h: indexes = json.get(iMacro,"index")]
[h: props = getMacroProps(indexes, "json")]
[h: macroheader = strformat("@@%s",json.get(props, "label"))]
[h: macroProps = getMacroProps(indexes)]
[h: macroProps = setStrProp(macroProps,"sortBy",json.get(iMacro,"sortBy"))]
[h: macroProps = strformat("@PROPS@ %s",deleteStrProp(macroProps, "label"))]
[h: moutput = strformat("%s%s%s%s%s%s",macroheader,newLine,macroProps,newLine,encode(json.get(props, "command")),newLine)]
[h: twoLines = strformat("%s%s",newLine,newLine)]
[h, if(!endsWith(moutput,twoLines)): moutput = strformat("%s%s",moutput,newLine)]
[h, if(json.get(props, "label") == "onCampaignLoad"): output = strformat("%s%s",moutput,output); output = strformat("%s%s",output,moutput)]
}]
}]
[R, if(hasInput), code: { [H, macro("showInFrame@Lib:cifMacroIO"): output] };{}]
Code: Select all
<!-- This Macro is pre-generated. ALTER AT YOUR OWN RISK -->
[H: alias = json.set("{}","varName","original macro name")]
[H: prefix = "authorsInitials.libraryInitials"]
[H: outputFunctions = json.append("","macroName1","macroName2")]
[H: noOutputFunctions = json.append("","macroName3","macroName4")]
[H, foreach(fn,outputFunctions): defineFunction(strformat("%s.%s",prefix,fn),strformat("%s@this",json.get(alias,fn)),0)]
[H, foreach(fn,noOutputFunctions): defineFunction(strformat("%s.%s",prefix,fn),strformat("%s@this",json.get(alias,fn)),1)]
Code: Select all
Invalid condition in IF(tTemp != "" || !isWhitespace) roll option.
Statement options (if any): H, if(tTemp != "" || !isWhitespace)
Statement Body : isWhitespace = 0
Code: Select all
@@SupernalSheet
@PROPS@ autoExecute=true ; color=blue ; fontColor=white ; group=0. Current ; includeLabel=false ; sortBy=6 ; index=91 ; fontSize=1.00em ; minWidth= ; playerEditable=true ; maxWidth= ; tooltip= ; applyToSelected=false ;
<!-- WoD Character Sheet v1.0 -->
[h: Img1 = tblImage("Icons", 1)]
[h: Img2 = tblImage("Icons", 2)]
[h: Img3 = tblImage("Icons", 3)]
[h: Img4 = tblImage("Icons", 4)]
[h: Img5 = tblImage("Icons", 5)]
[h: ImgHelmet = tblImage("Icons", 7)]
[h: ImgShield = tblImage("Icons", 8)]
[h: ImgGold = tblImage("Icons", 9)]
[h: ImgSilver = tblImage("Icons", 10)]
[h: ImgCopper = tblImage("Icons", 11)]
[h: Imghide = tblImage("Totaltens", 0)]
[H: ImgLogo = getImg("Logo", TemplateType)]
[H: SupernalFamilyLogo = getImg(TemplateType, SupernalFamilyText+"_"+SupernalFamily)]
[H: SupernalSocialGroupLogo = getImg(TemplateType, SupernalSocialGroupText+"_"+SupernalSocialGroup)]
[h: ImgDotFilled = tblImage("Icons", 9)]
[h: ImgDotUnFilled = tblImage("Icons", 10)]
<table width="100%" height="100%" cellpadding="2" align="center" border="1" bgcolor="white">
<tr height="100%">
<td colspan="6" width="100%">
<TABLE BORDER="0" width="100%">
<tr>
<td bgcolor="white" align="center" width="20%">
<img src='[r: SupernalFamilyLogo]' width="50" height="50" />
</td>
<td bgcolor="white" align="center" width="60%" colspan="4" rowspan="2">
<img src='[r: ImgLogo]' width="125" height="61" />
</td>
<td bgcolor="white" align="center" width="20%">
<img src='[r: SupernalSocialGroupLogo]' width="50" height="50" />
</td>
</tr>
<tr>
<td bgcolor="white" align="center" width="20%">
[r: SupernalFamily]
</td>
<td bgcolor="white" align="center" width="20%">
[r: SupernalSocialGroup]
</td>
</tr>
</TABLE>
</td>
</tr>
<tr>
<td valign="top" align="center" width="65%" colspan="3">
<table width="100%" cellpadding="0" >
<tr>
<td width="35%" bgcolor="black" color="white" align="right" border="0"><b>Name</b> </td>
<td width="5%" height="1" border="0"><img scr="[r: Imghide]" width="1" height="1"></td>
<td width="60%" align="Left" border="0">[r: token.name]</td>
</tr>
<tr>
<td height="1" colspan="3" border="0"><img scr="[r: Imghide]" width="1" height="1"></td>
</tr>
<tr>
<td width="35%" bgcolor="black" color="white" align="right" border="0"><b>Virtue / Vice</b> </td>
<td width="5%" height="1" border="0"><img scr="[r: Imghide]" width="1" height="1"></td>
<td width="60%" align="Left" border="0">[r: Virtue] / [r: Vice]</td>
</tr>
</table>
</td>
<td valign="top" align="center" width="35%" colspan="3">
<table width="100%" cellpadding="0">
<tr>
<td width="100%" bgcolor="black" color="white" align="center" border="0"><b><span style="color:white">
[h: target=currentToken()]
[r: macroLink("Health", "HealthChange@this", "all",target, currentToken())]</span></b>
</td>
</tr>
<tr>
<td width="100%" align="center" border="0">
[h:len= length(Health)]
[h:status = 1]
<!-- Loop through your health - if there's something there that shouldn't be (it's not e, a, l, or b), abort -->
[FOR(i,0,len-1,+1, ""),CODE:{
[h:box = substring(Health, i, i+1)]
[h,if(box!="e"&&box!="a"&&box!="l"&&box!="b"): status = 0]
}]
[h: abort(status)]
<!-- Since we know the health box is fine, print out everything by using the table
(I made the little icons, they're free to good homes, etc.). -->
[FOR(i,0,len,+1, ""),CODE:{
[h:box = substring(Health, i, i+1)]
[h,if(box=="e"):temp=4]
[h,if(box=="a"):temp=3]
[h,if(box=="l"):temp=2]
[h,if(box=="b"):temp=1]
<image src='[r: tableImage("HealthBoxes", temp)]'></image>
}]
</td>
</tr>
</table>
</td>
</tr>
<!-- Consolidated repeated HTML statements into FOR Loop - Jamz -->
<tr>
<td colspan="6">
<table width="100%" cellpadding="0">
<tr>
[h: attribList="Intelligence, Strength, Presence, Wits, Dexterity, Manipulation, Resolve, Stamina, Composure"]
[h: row=0]
[h: focus="0"]
[FOREACH(attrib, attribList, ""),CODE:{
[h, IF(row == 3 || row == 6): outPut="</tr><tr>"; outPut=""]
[r: outPut]
[h: row=row+1]
<td width="30%" bgcolor="black" color="white" align="right" border="0">
<span style="color:white; font-weight:bold">
[h: jsonData = json.append("[]", attrib, focus, "None")]
[r: macroLink(attrib, "AbilityRoll@this", "all",jsonData, currentToken())]
</span>
</td>
<td border="0" width="15%" align="center" bgcolor="#dcdcdc">
[h: Dotlen=getProperty(attrib)]
[FOR(i,0,Dotlen,+1, ""),CODE:{
<image src='[r: ImgDotFilled]' width='8' height='8' />
}]
[FOR(i,Dotlen,5,+1, ""),CODE:{
<image src='[r: ImgDotUnFilled]' width='8' height='8' />
}]
</td>
}]
</tr>
</table>
<tr>
<td colspan="6">
<table width="100%" cellpadding="0">
<tr>
[h: skillList="Academics, Athletics, Animal_Ken, Computer, Brawl, Empathy, Crafts, Drive, Expression, Investigation, Firearms, Intimidation, Medicine, Larceny, Persuasion, Occult, Stealth, Socialize, Politics, Survival, Streetwise, Science, Weaponry, Subterfuge"]
[h: row=0]
[h: focus="0"]
[FOREACH(skill, skillList, ""),CODE:{
[h: row2=row/3]
[h: row3=ceil(row/3)]
[h, IF(row2 == row3 && row > 0): outPut="</tr><tr>"; outPut=""]
[r: outPut]
[h: row=row+1]
<td width="30%" bgcolor="black" color="white" align="right" border="0">
<span style="color:white; font-weight:bold">
[h: jsonData = json.append("[]", skill, focus, "None")]
[r: macroLink(skill, "AbilityRoll@this", "all",jsonData, currentToken())]
</span>
</td>
<td border="0" width="69%" align="center" bgcolor="#dcdcdc">
[h: Dotlen=getProperty(skill)]
[h, IF(Dotlen < 0): ImgTemp=Imghide; ImgTemp=ImgDotFilled]
[h, IF(Dotlen < 0): ImgTemp2=Imghide; ImgTemp2=ImgDotUnFilled]
[h, IF(Dotlen < 0): Dotlen=0]
[FOR(i,0,Dotlen,+1, ""),CODE:{
<image src='[r: ImgTemp]' width='8' height='8' />
}]
[FOR(i,Dotlen,5,+1, ""),CODE:{
<image src='[r: ImgTemp2]' width='8' height='8' />
}]
</td>
<td border="0" width="1%" align="center" bgcolor="#dcdcdc"><span style="color:black">
</td>
}]
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="center" width="80%" colspan="5">
<table width="100%" cellpadding="0">
<tr>
<td border="0" width="40%" align="center" bgcolor="black" color="white"><span style="color:white"><b>
[r: macroLink("Weapon", "UpdateWeapons@this", "none","", currentToken())]</b></span>
</td>
<td border="0" width="30%" align="center" bgcolor="black" color="white"><b>Attack Roll</b>
</td>
<td border="0" width="30%" align="center" bgcolor="black" color="white"><b>Attack Skill</b>
</td>
</tr>
[h,if(json.isEmpty(Weapons)): weaponList = ""; weaponList = json.fields(Weapons)]
[foreach(wpn, weaponList, ""), code: {
[h: wpnDetails = json.get(Weapons, wpn)]
[h: wpnName = wpn]
[h: wpnAbil = json.get(wpnDetails, "Ability")]
[h: wpnSkill = json.get(wpnDetails, "Skill")]
[h: wpnDmg = json.get(wpnDetails, "Damage")]
[h: wpnrng = json.get(wpnDetails, "Range")]
[h: focbonus=0]
[h: wpnRBval = getProperty(wpnAbil)]
[h: wpnSKval = getProperty(wpnSkill)]
[h:wpnRollBonus = wpnRBval + wpnSKval + wpnDmg]
<tr>
<td border="0" height="3" colspan="6"><img scr="[r: Imghide]" width="1" height="1">
</td>
</tr>
<tr>
<td border="0" width="40%" align="center">
<span style="color:black">
[h:jsonData = json.append("[]", wpnName, wpnRollBonus)]
[r: macroLink(wpnName, "WeaponAttack@this", "all",jsonData, currentToken())]
</span>
</td>
<td border="0" width="30%" align="center"> [r: wpnRollBonus]</td>
<td border="0" width="30%" align="center"> [r: wpnSkill]</td>
</tr>
[if(wpnrng != "---" && wpnrng != ""), code: {
<tr>
<td border="0" height="3" colspan="3"><img scr="[r: Imghide]" width="1" height="1">
</td>
</tr>
<tr>
<td border="0" width="100%" align="center" colspan="3">
<span style="font-style:italic">[r: wpnrng] Range</span>
</td>
</tr>
};
{}]
<tr>
<td border="0" height="3" colspan="3"><img scr="[r: Imghide]" width="1" height="1">
</td>
</tr>
<tr>
<td border="0" height="1" colspan="3" bgcolor="black"><img scr="[r: Imghide]" width="1" height="1">
</td>
</tr>
<tr>
<td border="0" height="3" colspan="3"><img scr="[r: Imghide]" width="1" height="1">
</td>
</tr>
}]
</table>
</td>
<td valign="top" align="center" width="20%" colspan="1">
<table width="100%" cellpadding="0">
<tr>
<td border="0" align="center" bgcolor="black" color="white">
<span style="color:white"><b>[r: macroLink("Willpower", "ChangeWill@Lib:Test", "none", "", currentToken())]</b>
</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="#dcdcdc">[r: Willpower]</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="black" color="white"><b>Speed</b></td>
</tr>
<tr>
<td border="0" align="center" bgcolor="#dcdcdc">[r: Speed]</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="black" color="white"><b>Initiative</b></td>
</tr>
<tr>
<td border="0" align="center" bgcolor="#dcdcdc">[r: InitMod]</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="black" color="white">
<span style="color:white"><b>Defense</b>
</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="#dcdcdc">[r: Defense]</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="black" color="white">
<span style="color:white">
<b>[r: macroLink("Armor", "EquipArmor@Lib:Test", "none", "", currentToken())]</b>
</span>
</td>
</tr>
<tr>
<td border="0" align="center" bgcolor="#dcdcdc">[r: Armor]</td>
</tr>
<tr>
<td border="0" valign="top" align="center">
<span style="color:black">
<img src="[r: ImgHelmet]" width="20" height="20" border="0">
[r: macroLink(ArmorType, "UpdateArmor@Lib:Test", "none", "", currentToken())]
</span>
</td>
</tr>
</table>
</td>
</tr>
[h,if(json.isEmpty(SpellBook)): spellList = ""; spellList = json.fields(SpellBook)]
[if(Mana > 0), CODE: {
<tr>
<td colspan="6">
<table width="100%" cellpadding="0">
<tr>
<td border="0" align="center" bgcolor="black" color="white" width="100%" colspan="6">
<span style="color:white">
<b>[r: macroLink(SupernalPowersText, "UpdateSpells@Lib:Test", "none", "", currentToken())]</b></span>
</td>
</tr>
<tr>
<td border="0" td align="center" width="100%">
[foreach(spell, spellList, ", "), code: {
[h: spellDetails = json.get(SpellBook, spell)]
[h: spellName = spell]
[h: spellSchool = json.get(spellDetails, "School")]
[h: spellType = json.get(spellDetails, "Type")]
[h: spellManaCost = json.get(spellDetails, "ManaCost")]
[h: spellCastTime = json.get(spellDetails, "CastTime")]
[h: spellTN = json.get(spellDetails, "TN")]
[h: spellTest = json.get(spellDetails, "Test")]
[h: spellDesc = json.get(spellDetails, "Desc")]
<span style="color:black">
[h:jsonData = json.append("[]", spellName, spellSchool, spellType, spellManaCost, spellCastTime, spellTN, spellTest, spellDesc)]
[r: macroLink(spellName, "DisplaySpells@this", "none",jsonData, currentToken())]
</span>
}]
</td>
</tr>
<tr>
<td border="0" align="bottom" width="10%">
<b>[r:SupernalTraitText]:</b> [r:SupernalTrait]
</td>
<td border="0" align="right" width="90%" colspan="5">
<b><a href='[r:macroLinkText("ManaChange@Lib:Test","all","", currentToken())]'>
[r:SupernalEnergyText]</a>:</b> [r: SupernalEnergy] / <b>Per Turn: </b> [r:SupernalEnergyPerTurn]
<a href='[r:macroLinkText("adjustProperty@Lib:Test","all","prop=SupernalEnergy; value=1", currentToken())]'>
<img src="[r: Img4]" width="35" height="35" border="0">
</a>
<a href='[r:macroLinkText("adjustProperty@Lib:Test","all","prop=SupernalEnergy; value=-1", currentToken())]'>
<img src="[r: Img5]" width="35" height="35" border="0">
</a>
</td>
</tr>
</table>
</td>
</tr>
};{}]
<tr>
<td colspan="6">
<table width="100%" cellpadding="2">
[h, IF(json.isEmpty(ClassTalent)): ctList = ""; ctList = json.fields(ClassTalent)]
<tr>
<td border="0" colspan='2' align='center' bgcolor="black">
<span color='white'>
<b>[r:macroLink("Other Abilities","UpdateClassTalents@this", "none", "", currentToken())]</b>
</span>
</td>
</tr>
<tr>
<td border="0" colspan='2'>
[r,foreach(entry, ctList,", "),CODE:
{
[h:ctDetail = json.get(ClassTalent,entry)]
[h:ctDesc = json.get(ctDetail, "ctText")]
<span style="color:black">
[h:jsonData = json.append("[]", ctDesc, entry)]
[r: macroLink(entry, "ClassTalentDisplay@this", "none",jsonData, currentToken())]
}]
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="6">
<table width="100%" cellpadding="0">
<tr>
<td border="0" border="0" colspan='5' align='center' bgcolor="black">
<span color='white'>
<b>[r:macroLink("Equipment","UpdateEquipment@this", "self", "", currentToken())]</b>
</span>
</td>
</tr>
<tr>
<td border="0" colspan="5" align="center">[r: Equipment]</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="6">
<table width="100%" cellpadding="0">
<tr>
<td border="0" width="25%" align="center">
<a href='[r:macroLinkText("InitRoll@Lib:Test","all","", currentToken())]'>
<img src="[r: Img2]" width="50" height="50" border="0">
</a>
</td>
<td border="0" width="25%" align="center">
<a href='[r:macroLinkText("SupernalUpdate@Lib:Test","gm-self","", currentToken())]'>
<img src="[r: Img3]" width="50" height="50" border="0">
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
Code: Select all
[H: importedText = json.get(macro.args, "textfield")]
[H: id = json.get(macro.args, "id")]
[H: output = json.append("",strformat("<b>Token: <font color=blue>%s</font></b>",getName(id)))]
[H: maxLines = 500]
[H: eol = "%0A"]
[H: '<!-- List safe encoding -->']
[H: importedText = encode(importedText)]
[H: '<!-- put each line in to json array -->']
[H: tLines = json.fromList(importedText,eol)]
[H: numLines = json.length(tLines)]
[H: tPutLines = ""]
[H: tProps = "{}"]
[H: setLine = -1]
[H: tLine = ""]
[H, if(numLines > maxLines), code: {
[H: '<!-- Find next line cutoff -->']
[H: tLine = json.get(tLines,maxLines)]
[H, if(startsWith(tLine,"%40%40")): wConditon = 0; wCondition = 1]
[H, while(wCondition), code: {
[H: maxLines = maxLines +1]
[H, if(maxLines < numLines): tLine = json.get(tLines,maxLines); wCondition = 0]
[H, if(startsWith(tLine,"%40%40")): wCondition = 0]
}]
[H: '<!-- Put lines in array to be copied to macros and then delete -->']
[H, for(lineNum,0,maxLines), code: {
[H: tLine = json.get(tLines,0)]
[H: tPutLines = json.append(tPutLines,tLine)]
[H: tLines = json.remove(tLines,0)]
}]
};{
[H: tPutLines = tLines]
[H: tLines = ""]
}]
[H: tMacro = ""]
[H: hasLabel = 0]
[H: tLabel = ""]
[H: isWhitespace = 0]
[H: '<!-- Create, Rewrite macros -->']
[H, foreach(tLine,tPutLines), code: {
[H: isLabel = 0]
[H: isProps = 0]
[H: '<!-- Check for label line, starts with @@ -->']
[H, if(startsWith(tLine,"%40%40")): isLabel = 1]
[H, if(isLabel && !hasLabel), code: {
[H: tLabel = substring(l.decode(tLine), 2))]
[H: hasLabel = 1]
};{}]
[H, if(startsWith(tLine, "%40PROPS%40")): isProps = 1]
[H, if(isProps): tProps = json.fromStrProp(substring(l.decode(tLine), 7)))]
[H, if(isLabel && !json.isEmpty(tMacro)), code: {
[H: '<!-- Save macro -->']
[H: output = json.append(output,
strformat("<b>Macro: <font color=red>%s</font> - <i>%d lines</i></b>",tLabel,json.length(tMacro))
)]
[H: command = json.toList(tMacro,eol)]
[H: command = l.decode(command)]
[H: tProps = json.set(tProps,"playerEditable","false")]
[H, macro("createOrEditMacro@Lib:cifMacroIO"): json.set(tProps, "command", command, "label", tLabel, "id", id)]
[H: tLabel = substring(l.decode(tLine), 2))]
[H: tMacro = ""]
[H: tProps = "{}"]
};{}]
[H: tTemp = trim(l.decode(tLine))]
[H, if(!json.isEmpty(tTemp) || !isWhitespace): isWhitespace = 0]
[H, if(startsWith(tTemp,"<!--") && endsWith(tTemp,"-->")): isCommentLine = 1; isCommentLine = 0]
[H: '<!-- Hide Comment lines -->']
[H, if(isCommentLine), code: {
[H: tRegEx = encode("<!--") + ".*?" + encode("-->")]
[H: rText = replace(tTemp,"'","")]
[H: rText = encode(strformat("[H: '%s']",rText))]
[H: tLine = replace(tLine,tRegEx,rText)]
};{}]
[H, if(!isLabel && !isProps && hasLabel && !isWhitespace): tMacro = json.append(tMacro,tLine)]
[H: '<!-- Only allow 1 line of whitespace -->']
[H, if(json.isEmpty(tTemp)): isWhitespace = 1]
}]
[H: '<!-- Create, rewrite last macro -->']
[H, if(hasLabel && !json.isEmpty(tMacro)), code: {
[H: output = json.append(output,
strformat("<b>Macro: <font color=red>%s</font> - <i>%d lines</i></b>",tLabel,json.length(tMacro))
)]
[H: command = json.toList(tMacro,eol)]
[H: command = l.decode(command)]
[H, macro("createOrEditMacro@Lib:cifMacroIO"): json.set(tProps, "command", command, "label", tLabel, "id", id)]
}]
[H: '<!-- Output -->']
[R: json.toList(output,"<br>")]
[H: '<!-- If there are more lines to process, do again -->']
[H, if(!json.isEmpty(tLines)), code: {
[H: tLines = json.toList(tLines,eol)]
[H: tLines = l.decode(tLines)]
[H: macro.args = json.set(macro.args,"textfield",tLines)]
[H: tLink = macroLinkText("processImport@Lib:cifMacroIO","all",macro.args)]
[H: execLink(tLink,1)]
};{
[dialog("Import"):{<b>DONE!</b>}]
}]
Code: Select all
[h: eol = "%0A" ]
[h: formData = macro.args ]
[h: id = json.get( formData, "id" )]
[h: importedText = json.get( formData, "textfield" )]
[ if( json.type( importedText ) == "ARRAY" ), code: {
[h: mBlocks = importedText ]
}; {
[h: importedText = encode( importedText )]
[h: delim = strformat( "%s%s", eol, encode( "@@" ) )]
[h: mBlocks = json.fromList( importedText, delim )]
}]
[h: mBlock = json.get( mBlocks, 0 )]
[h: wsTest = trim( l.decode( mBlock ) )]
[r, token( id ), if( wsTest != "" ): output = constructMacro( mBlock )]
[h: mBlocks = json.remove( mBlocks, 0 )]
[ if( json.isEmpty( mBlocks ) ), code: {
[ dialog( "Import" ): {
<html>
<table cellspacing='2' cellpadding='0' style='background-color:#595751'><tr><td>
<table width='250px' cellspacing='0' cellpadding='2' style='background-color:#FAF9F5;'><tr>
<td style='font-size: 1.4em' align='center'><b>Done!</b></td>
</tr></table>
</td></tr></table>
</html>
}]
}; {
[h: tLink = macroLinkText( "processImport@this", "all", json.set( formData, "textfield", mBlocks ) )]
[h: execLink( tLink, 1 )]
}]
Code: Select all
[h: id = currentToken()]
[h: eol = "%0A" ]
[h: mText = arg(0)]
[h: mProps = '{}' ]
[h: lineCount = 0 ]
[h: tLines = json.fromList( mText, eol )]
[h: rLabel = l.decode( json.get( tLines, 0 ) )]
[h, if( startsWith( rLabel, "@@" ) ): rLabel = substring( rLabel, 2 )]
[h: mProps = json.set( mProps, "label", rLabel )]
[h: tLines = json.remove( tLines, 0 )]
[h: lineCount = lineCount +1 ]
[h: rProps = l.decode( json.get( tLines, 0 ) )]
[ if( startsWith( rProps, "@PROPS@" ) ), code: {
[h: rProps = json.fromStrProp( trim( substring( rProps, 7 ) ) )]
[h: mProps = json.merge( rProps, mProps )]
[h: tLines = json.remove( tLines, 0 )]
[h: lineCount = lineCount +1 ]
}; {}]
[h: command = '[]' ]
[h: whitespaceFlag = 0 ]
[ foreach( tLine, tLines, "" ), code: {
[h: wsTest = trim( l.decode( tLine ) )]
[h, if( wsTest != "" || whitespaceFlag == 0 ): command = json.append( command, tLine )]
[h, if( wsTest == "" ): whitespaceFlag = 1 ; whitespaceFlag = 0 ]
}]
[h: lineCount = lineCount + json.length( command )]
[h: command = json.toList( command, eol )]
[h: command = l.decode( command )]
[h, token( id ): createOrEditMacro( json.set( mProps, "command", command, "id", id ) )]
[r: macro.return = strformat( "<b>Macro: <font color=red>%s</font> - <i>%d lines</i></b>", rLabel, lineCount )]
Code: Select all
[H: defineFunction("l.decode","l.decode@this",1)]
[H: defineFunction("getMacroGroups","getMacroGroups@this",1)]
[H: defineFunction("constructMacro","constructMacro@this",1)]
Well, I'm going to include it in v2.0 of my Token Manager (formerly PropEditor) tool, which will hopefully be ready to post soon. But I thought you might like to at least see the idea of macro-by-macro importing in the meantime.aliasmask wrote:You should post your own token based on the whichever version you used and add a letter. Also, put in the token notes how if varies from the previous version.
I dont' know what the max amount of lines is (1000?) but do keep in mind that macros can certainly extend beyond 500 lines. I've checked a couple of mine and noticed that the longest (of the ones I checked) currently counts 443 lines....I re-wrote the processImport macro. I figured, as long as it was getting broken into blocks of 500 lines anyway (which was the cause of much of its complicated code), we might as well just break it into one macro at a time and process each of them in turn.
(in case you're wondering the HP system of my framework is on the same scale as D&D.Attacks with both weapons, this attack is done with Mono Axe Rolling against WS 99 (+60 modifiers). Roll: 30 - Target is hit in the head and takes 17300 Rending damage.
Code: Select all
[h:finalDamTotal =bestDamageTotal + rfBonusDmg + mightyShot + damMod]
[r:finalDamTotal]
Code: Select all
[if(listFind(wpnSpec, "Tearing") != -1): finalDmg = max(getDamage(wpnUsed,modifiedChar),getDamage(wpnUsed,modifiedChar)); finalDmg = getDamage(wpnUsed,modifiedChar)]
Code: Select all
[finalDmg = finalDmg + SB + miscModDam + 2*hasTalent("Crushing Blow")]
Code: Select all
<!--getdamage-->
[h:assert(argCount() == 2, "getDamage() requires exactly 2 arguments", 0)]
[h:wpnUsed = arg(0)]
[h:govChar = arg(1)]
[h:damDiceRolls = "[]"]
<!--righteous fury-->
[h:rf = 0]
[h:rfBonusDmg = 0]
[h:initialDamTotal = 0]
[h:tearingDamTotal = 0]
[h:tearingDamDiceRolls = "[]"]
[h:bestDamageTotal = 0]
<!--Flamer jams on rolling a nine-->
[h:nineRolled = 0]
[h:wpnDetails = json.get(Weapons,wpnUsed)]
[h:numDamDice = json.get(wpnDetails,"WpnDamDice")]
[h:wpnCategory = json.get(wpnDetails,"Category")]
[h:diceType = "d"+json.get(wpnDetails, "WpnDamDiceType")]
<!--the Luminen weapons have "WB" as damMod-->
[h:damMod = json.get(wpnDetails,"WpnDamMod")]
[h,if(isNumber(damMod)):damMod = damMod; damMod = eval(damMod))]
[h:wpnSpec = json.get(wpnDetails,"Special")]
<!--mightyshot gives +2 damage to ranged attacks>
[h, if(wpnCategory == "Ranged"):mightyShot = 2*hasTalent("Mighty Shot"); mightyShot = 0]
[h,count(numDamDice): damDiceRolls = json.append(damDiceRolls, eval(diceType))]
[h,foreach(element,damDiceRolls),CODE:
{
[if(element == 9): nineRolled = 1]
[initialDamTotal = initialDamTotal + element]
}]
[h,if(listFind(wpnSpec,"Tearing")!= -1),CODE:
{
[count(numDamDice): tearingDamDiceRolls = json.append(tearingDamDicerolls,eval(diceType))]
[h,foreach(element,tearingDamDiceRolls): tearingDamTotal = tearingDamTotal + element]
}]
[h,if(initialDamTotal > tearingDamTotal),CODE:
{
[finalRollSet = damDiceRolls]
[bestDamageTotal = initialDamTotal]
};
{
[finalRollSet = tearingDamDiceRolls]
[bestDamageTotal = tearingDamTotal]
}]
[h,foreach(element,finalRollSet),CODE:
{
[if(element == 10): rf = 1]
}]
<!--Check Righteous Fury-->
[h,if(rf),CODE:
{
[rfTens = 1d10-1]
[rfOnes = 1d10-1]
[h:rfResult = if(rfTens+rfOnes == 0, 100, (rfTens*10+rfOnes))]
[if(rfResult <= govChar),CODE:
{
[rfBonusDmg = 1d10e]
}]
}]
[h:finalDamTotal =bestDamageTotal + rfBonusDmg + mightyShot + damMod]
[r:finalDamTotal]
[h:result = rf]
[h:result = Listappend(rf,nineRolled)]
[h:macro.return=result]
Code: Select all
[H: '<!--getdamage-->']
[h:assert(argCount() == 2, "getDamage() requires exactly 2 arguments", 0)]
[h:wpnUsed = arg(0)]
[h:govChar = arg(1)]
[h:damDiceRolls = "[]"]
[H: '<!--righteous fury-->']
[h:rf = 0]
[h:rfBonusDmg = 0]
[h:initialDamTotal = 0]
[h:tearingDamTotal = 0]
[h:tearingDamDiceRolls = "[]"]
[h:bestDamageTotal = 0]
[H: '<!--Flamer jams on rolling a nine-->']
[h:nineRolled = 0]
[h:wpnDetails = json.get(Weapons,wpnUsed)]
[h:numDamDice = json.get(wpnDetails,"WpnDamDice")]
[h:wpnCategory = json.get(wpnDetails,"Category")]
[h:diceType = "d"+json.get(wpnDetails, "WpnDamDiceType")]
[H: '<!--the Luminen weapons have "WB" as damMod-->']
[h:damMod = json.get(wpnDetails,"WpnDamMod")]
[h,if(isNumber(damMod)):damMod = damMod; damMod = eval(damMod))]
[h:wpnSpec = json.get(wpnDetails,"Special")]
<!--mightyshot gives +2 damage to ranged attacks>
[h, if(wpnCategory == "Ranged"):mightyShot = 2*hasTalent("Mighty Shot"); mightyShot = 0]
[h,count(numDamDice): damDiceRolls = json.append(damDiceRolls, eval(diceType))]
[h,foreach(element,damDiceRolls),CODE:
{
[if(element == 9): nineRolled = 1]
[initialDamTotal = initialDamTotal + element]
}]
[h,if(listFind(wpnSpec,"Tearing")!= -1),CODE:
{
[count(numDamDice): tearingDamDiceRolls = json.append(tearingDamDicerolls,eval(diceType))]
[h,foreach(element,tearingDamDiceRolls): tearingDamTotal = tearingDamTotal + element]
}]
[h,if(initialDamTotal > tearingDamTotal),CODE:
{
[finalRollSet = damDiceRolls]
[bestDamageTotal = initialDamTotal]
};
{
[finalRollSet = tearingDamDiceRolls]
[bestDamageTotal = tearingDamTotal]
}]
[h,foreach(element,finalRollSet),CODE:
{
[if(element == 10): rf = 1]
}]
[H: '<!--Check Righteous Fury-->']
[h,if(rf),CODE:
{
[rfTens = 1d10-1]
[rfOnes = 1d10-1]
[h:rfResult = if(rfTens+rfOnes == 0, 100, (rfTens*10+rfOnes))]
[if(rfResult <= govChar),CODE:
{
[rfBonusDmg = 1d10e]
}]
}]
[h:finalDamTotal =bestDamageTotal + rfBonusDmg + mightyShot + damMod]
[r:finalDamTotal]
[h:result = rf]
[h:result = Listappend(rf,nineRolled)]
[h:macro.return=result]
Code: Select all
[h:finalDamTotal = eval("bestDamageTotal + rfBonusDmg + mightyShot + damMod")]
[r:finalDamTotal]