UPDATE
version 2 is described in another post due to (code) length limitations.
The Lib token can be downloaded with the macros (the code was getting too long to post, sorry) LEGACY - v1
I just threw this together over the past couple of hours, so it's basic and pretty hack, but feel free to improve / modify it if you think it's useful (I'd bet good money zEal has one of these in his "Macro Toolkit" already, but I'll never learn if I don't try )
If you use it, leave "Apply to Selected Tokens" unchecked: the input includes a list of tokens to work on (starts with selected, then tries impersonated, and finally the location of the macro).
BatchEditMacrosV1
Code: Select all
/self <!-----===== Batch Edit Macro Properties v1 =====----->
[H: jaw.tokenConditions = json.set("", "selected", 1 )]
[H, IF( isGM()==0 ): jaw.tokenConditions = json.set( jaw.tokenConditions, "owned", 1 )]
[H: targetLocations = getTokens( ",", jaw.tokenConditions )]
[H, IF( targetLocations=="" ): targetLocations = currentToken() ] <!-- getImpersonated() fails ungracefully (what about hasImpersonated?). This will return the impersonated token if there is one -->
[H, IF( targetLocations=="" ): targetLocations = getMacroLocation() ] <!-- Final option -->
<!-- assemble lists for input -->
[H: macroLocation.list = "" ] <!-- macro property retrieval doesnt seem to work with "Global" or "Campaign", but geMacroLocation should still allow this to be used in these locations -->
[H, FOREACH( loc, targetLocations ): macroLocation.list = listAppend( macroLocation.list, getName( loc ) +" "+ getImage( getName( loc ) ) )]
[H: macroProps.db = json.set("",
"applyToSelected", "Apply To Selected",
"autoExecute", "Auto Execute",
"color", "Button Color",
"command", "Command (Contents)",
"fontColor", "Font Color",
"fontSize", "Font Size",
"includeLabel", "Include Label",
"group", "Group",
"sortBy", "Sorting Prefix",
"label", "Label (Name)",
"maxWidth", "Max. Width",
"minWidth", "Min. Width",
"playerEditable", "Allow Players to Edit Macro",
"tooltip", "ToolTip"
)]
[H: macroPropNames = json.fields( macroProps.db ) ]
[H: macroProps.list = "" ]
[H, FOREACH( field, macroPropNames ): macroProps.list = listAppend( macroProps.list, json.get( macroProps.db, field ) )]
<!-- User Input -->
[H: inputLine = "%s | %s | %s | %s | %s" ]
[H: go = input(
strformat( inputLine, "macroLocation", macroLocation.list, "Macro Location", "LIST", "icon=true iconsize=60" ),
strformat( inputLine, "propName", macroProps.list, "Macro Property to edit", "LIST", "" ),
"value.old | | Old Value | TEXT | width=20",
"value.new | | New Value | TEXT | width=20"
)]
[H: abort(go)]
[H: propName = listGet( macroPropNames, propName )]
[H: macroLocation = listGet( targetLocations, macroLocation )]
[H: updateMacros.list = "" ]
[H: loc = macroLocation ]
<!-- H, FOREACH( loc , targetLocations ), code: -->
[H: macros.list = getMacros( "json", loc ) ]
[H, FOREACH( macro, macros.list ), code:{
[ macroIndex.list = getMacroIndexes( macro, "json", loc )] <!-- what about macros with duplicate names? -->
[FOREACH( macroIndex, macroIndex.list ), code:{
[ macroProps = getMacroProps( macroIndex, "json", loc )]
[if( value.old==""): editProp = 1 ; editProp = if( json.get( macroProps, propName ) == value.old, 1, 0 )]
[if( editProp ): macroProps.new = json.set( macroProps, propName, value.new ) ; macroProps.new = macroProps ]
[if( editProp ): updateMacros.list = listAppend( updateMacros.list, macro )]
[if( editProp ): setMacroProps( macroIndex, macroProps.new, "json", loc )]
}]
}]
<!--
}] -->
<!-- Output -->
<strong>Macros Updated:</strong> {if( updateMacros.list=="" , "NONE" , updateMacros.list )}
<br><strong>@</strong> { getName( macroLocation ) }
EDIT: Group filter removed, as it was unreliable - see v2 for more advanced filtering features
The "Group" filter doesn't seem to be 100% reliable, but it's past my bedtime, so I might look at this later (the Group Property is matched reliably, but the Group filter uses Wiki: getMacroGroup(), which sometimes does not return all indices of macros in that group)...
Enjoy.