macroIO: batch import/export macros via copy & paste

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: macroIO: batch import/export macros via copy & paste

Post by wolph42 »

Well to share the pain: Here's my headache: the option parameter for the copytoken function, which I finally got right:

Code: Select all

    [jsonResult     = 
"{'useDistance':0,'x':%{c},'y':%{r},'layer':'"+eval("layer"+tokenName)+"','facing':'[r:"+eval("rotate"+tokenName)+"]', 'size':'[r:listGet(sizeList"+tokenName+", roll(1,listCount(sizeList"+tokenName+"))-1)]'}"]
 
Note the "[r:" which differ for the last three variable options. That took me hours s to debug 1. must be without, 1 must be separated form the variable and one has to be evaluated in the loop. And yes after this it also has to be crammed through a strformat. Next to that getting the eval or no eval and the strformat in the right place was... :evil:
I've literally spend hours debugging this one line of code. To make it easy tokenName is an abstract variable:

Code: Select all

[tokenName = listGet(atmList,roll.count)] 
and the 'jsonResult' is assigned to an abstract variable:

Code: Select all

[set("json"+tokenName, jsonResult)] 
Making the use of my favourite debug tool 'pause()' a... 'challenge'.

Especially stuff like +"))-1)]'}"] really gets me going

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: macroIO: batch import/export macros via copy & paste

Post by aliasmask »

This may be related and a possible cleaner solution, but I have some code like this:

Code: Select all

@@setDefaultConfig
[H: assert(isGM(),"GM Only Function: ["+getMacroName()+"]  You do not have permission.",0)]
[H: optionMenu = json.set("{}",
   "optionTab",json.set("{}","default","Options","prompt","","type","TAB","options",""),
   "editMode",json.set("{}","default","{editMode}","prompt","Turn on Edit Mode","type","CHECK","options",""),
   "reSort",json.set("{}","default","{reSort}","prompt","Re-sort buttons by color on Save","type","CHECK","options",""),
   "cleanComment",json.set("{}","default","{cleanComment}","prompt","Change line comments to statements","type","CHECK","options",""),
   "showTabGroups",json.set("{}","default","{showTabGroups}","prompt","Show TAB Groups for Multi Macro Select","type","CHECK","options",""),
   "adminTab",json.set("{}","default","Admin","prompt","","type","TAB","options",""),
   "formWidth",json.set("{}","default","{formWidth}","prompt","Set Form Width","type","TEXT","options",""),
   "formHeight",json.set("{}","default","{formHeight}","prompt","Set Form Height","type","TEXT","options",""),
   "makeConfigDefault",json.set("{}","default",0,"prompt","Make these config settings default","type","CHECK","options",""),
   "resetDefaults",json.set("{}","default",0,"prompt","Reset Default Config","type","CHECK","options",""))]
[H: am.mio.slp("mio.optionMenu",optionMenu)]      
[H: am.mio.slp("mio.options",json.set("{}","editMode",0,"reSort",0,"cleanComment",0,"showTabGroups",0,"formWidth",92,"formHeight",40))]
[H: macro.return = optionMenu] 
Notice the braces "{}" around the variable names {editMode} and the like. This will, when I run Wiki: json.evaluate() get the current values and put them in to the object. This doesn't work for the json keys, only the values (i think).

Code: Select all

@@configOptions
@PROPS@ fontColor=black;autoExecute=true;fontSize=1.00em;sortBy=;color=default;playerEditable=false;applyToSelected=false;group=;tooltip=
[H: assert(isGM(),"GM Only Function: ["+getMacroName()+"]  You do not have permission.",0)]
[H: id = arg(0)]
[H: defaultOptions = am.mio.loadOptionsLocally()]
[H: optionMenu = am.mio.glp("mio.optionMenu")]
[H, if(json.isEmpty(optionMenu)): optionMenu = am.mio.setDefaultConfig()]
[H: menuStr = ""]
[H, foreach(option,optionMenu), code: {
   [H: menuObj = json.evaluate(json.get(optionMenu,option))]
   [H: varsFromStrProp(json.toStrProp(menuObj))]
   [H, if(type == "PROPS"): default = decode(default)]   
   [H: menuStr = json.append(menuStr,strformat("%s|%s|<html><b>%s</b></html>|%s%s",option,default,prompt,type,if(!json.isEmpty(options),"|"+options,"")))]
}]
[H: hasInput = input(json.toList(menuStr,"##"))]
[H: abort(hasInput)]
[H, if(!isNumber(formWidth)): formWidth = 92]
[H, if(!isNumber(formHeight)): formHeight = 40]
[H, foreach(option,defaultOptions): defaultOptions = json.set(defaultOptions,option,eval(option))]
[H: setProperty("mio.options",defaultOptions,id)]
[H, if(makeConfigDefault): am.mio.slp("mio.options",defaultOptions)]
[H, if(resetDefaults): am.mio.setDefaultConfig()]
 
The first half of the above code can be used to build any input menu, in fact I think I'll make it a separate function. There is no real benefit to doing it this way unless you want to be able to config the config options, but it seemed like a good programming exercise.

See if this code works:

Code: Select all

[H: jsonResult = json.set("{}","useDistance",0,"x","{c}","y","{r}","layer","{'layer'+tokenName}","facing","{'rotate'+tokenName}",
   "size","{listGet('sizeList'+tokenName,roll(1,listCount('sizeList'+tokenName))-1)}")]
[H: evalResult = json.evaluate(jsonResult)]
 

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: macroIO: batch import/export macros via copy & paste

Post by wolph42 »

If it only were so simple. The tokenname and the r and c values must be avaluated in different stages. First there is a json object created for 8 objects then these objects are all used in a x-y loop to fill an area with copy token. Which is why I use both evaluate AND strformat. To make matters worse I just figured out that I need the size variable available at a later stage. However currently my brain is fried....

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: macroIO: batch import/export macros via copy & paste

Post by aliasmask »

Whoa! I was doing some testing to make it more efficient. I was saving 11000+ lines with about 230 macros. My first run took about 7 minutes. I looked at the debug and noticed the json.get of the object (about 230 objects with about 16 object inside those) was taking about 1 second to process.

So, I did the little Wiki: varsFromStrProp() trick, nothing else and it reduced the save time to 2.5 minutes. I should probably put that in the wiki.

The parsing part was pretty fast, about 18 seconds. I could probably save some time by adding a config option to not preserve button props when writing. The only time you need to preserve the button is when you write to the token with no prop string to an existing button. Generally speaking, the prop string is usually there.

edit: I've started a new thread with the new incarnation of MacroIO: RPEdit

It has a whole new interface and is completely rewritten, but it is still compatible with the MacroIO format. I have a new format that I'll implement that will accommodate Notepad++ collapsing folders. You can read about the new features and download it at the link or in my signature.

Post Reply

Return to “Drop-In Macro Resources”