Wolph42's drop in Light Source Editor

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: Azhrei, dorpond, trevor, giliath, Gamerdude, jay, Mr.Ice

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Wolph42's drop in Light Source Editor

Post by wolph42 »

Inspired by Roadan's dirty token manager and Veggies light source editor, I thought of creating a drop in light source editor.
Observant people will recognize the layout to be similar to that of Veggies FW (thank you for that ;)). However this works within any campaign with any light settings.

How to install (MT build 70)
1. download file attached to this post
2. drag the file into maptool
3. drag the 'verbose' button to a token (and rename it)
OR
3. drag the other button (SetLightSource) to any token where you want to use it and delete the lib:wolph42 token.

Note:
(Edit:)- that the button does work on the Campaign panel, after you have set 'apply to selected token' (right click and edit)
- if you get a message: "You do not have permission to call the getInfo('campaign') function", then do the following:
1. right click on the SetLightSource macro
2. click edit --> options (tab) --> deselect: "Allow players to edit macro"

[spoiler=Alternatively you can just paste the code straight into your framework]

Code: Select all

<!--set light-->
<!--get lightsources from campaignproperties-->
[h:source = getInfo("campaign")]
[h:lightSource = json.get(source, "light sources")]
[h:lightTypeList = listSort(json.fields(lightSource),"A+")]

<!--remove light types not wanted-->
<!-- h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Type you want removed")) -->
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Ranges"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Suppress"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Flame"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Special"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Suppress"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Grenade"))]

<!--construct lists of light-->
[h:i = 0]
[h:inputStr = ""]

[h, foreach(lightType, lightTypeList), CODE:{
    [inputStr = listAppend(inputStr,"tab"+i+" | "+lightType+" || TAB")]
    [H, if(!i): inputStr = listAppend(inputStr, "divider |  | <html><b>The Wolph42  Light Editor</b></html>| LABEL | text=none")]
    [lights = json.get(lightSource,lightType)]
    [lightSet = lightType]
    [lightList = ""]       
    [foreach(light, lights):lightList = listappend(lightList, json.get(light, "name"))]
    [lightSetList = listSort(lightList,"N+")]
    [nlightSetList = listCount(lightSetList)]
    [h,COUNT(nlightSetList),CODE:{
        [light = listGet(lightSetList,roll.count)]
        [newStr = "Lamp"+i+"S"+roll.count+"|"+hasLightSource(lightSet, light)+"| "+light+" | CHECK"]
        [inputStr = listAppend(inputStr, newStr)]
    }]
    [H, if(!i): inputStr = listAppend(inputStr, "divider2 | ------ | ------------------------------ | LABEL")]
    [H, if(!i): inputStr = listAppend(inputStr, "removeAll | 0 | REMOVE ALL LIGHTS? | CHECK")]
    [i=i+1]
}]


<!--ask for input-->
[H: inputStr = listFormat(inputStr, "input( %list )", " ' %item ' ", ",")]
<!-- create the dialog -->
[H: status = eval(inputStr)]
[H: abort(status)]

<!--set the the lights-->
[i=0]
[h, foreach(lightType, lightTypeList), CODE:{
    [lights = json.get(lightSource,lightType)]
    [lightSet = lightType]
    [lightList = ""]       
    [foreach(light, lights):lightList = listappend(lightList, json.get(light, "name"))]
    [lightSetList = listSort(lightList,"N+")]
    [nlightSetList = listCount(lightSetList)]
    [h,COUNT(nlightSetList),CODE:{
        [light = listGet(lightSetList,roll.count)]
        [setLight(lightSet,light,eval("Lamp"+i+"S"+roll.count))]
    }]
    [h:i=i+1]
}]

<!-- if removeAll was checked, clear all lights -->
[H, if(removeAll): clearLights()]
[/spoiler]

[spoiler=excluding light types]If you want to exclude certain light types:
In the top of the code there is the comment:
<!-- h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Type you want removed")) -->

Change this into
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Type you want removed"))]
And replace "Type you want removed" with the type you want removed.[/spoiler]

Any suggestions are welcome.

Screenshot:
Wolph42 Light Editor.jpg
Wolph42 Light Editor.jpg (95.05 KiB) Viewed 5224 times
Attachments
Wolph42 Light Editor.rptok
(81.48 KiB) Downloaded 269 times
Last edited by wolph42 on Wed Jul 07, 2010 6:11 am, edited 3 times in total.

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Wolph42's drop in Light Source Editor

Post by Raoden »

I get an error when I try to drag-and-drop your token into MapTool from my MapTool Library (b63):

[spoiler]

Code: Select all

java.lang.InstantiationError: java.util.Map$Entry
   at sun.reflect.GeneratedSerializationConstructorAccessor356.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:62)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:257)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:124)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
   at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
   at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:66)
   at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:63)
   at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:54)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
   at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
   at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
   at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
   at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
   at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
   at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
   at com.thoughtworks.xstream.XStream.fromXML(XStream.java:789)
   at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:138)
   at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:123)
   at net.rptools.maptool.util.PersistenceUtil.loadToken(PersistenceUtil.java:400)
   at net.rptools.maptool.client.ui.assetpanel.ImageFileImagePanelModel.getTransferable(ImageFileImagePanelModel.java:98)
   at net.rptools.maptool.client.ui.assetpanel.AssetPanel$3.getTransferable(AssetPanel.java:261)
   at net.rptools.lib.swing.ImagePanel.dragGestureRecognized(ImagePanel.java:395)
   at java.awt.dnd.DragGestureRecognizer.fireDragGestureRecognized(Unknown Source)
   at sun.awt.windows.WMouseDragGestureRecognizer.mouseDragged(Unknown Source)
   at java.awt.AWTEventMulticaster.mouseDragged(Unknown Source)
   at java.awt.Component.processMouseMotionEvent(Unknown Source)
   at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:24)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
[/spoiler]
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

User avatar
Azhrei
Site Admin
Posts: 12050
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Wolph42's drop in Light Source Editor

Post by Azhrei »

Yep, that's a common problem due to a format change on tokens added in b66 (I think). It's on my list to see if I can't add some backward compatibility but I'm not sure how likely that is. :(

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Wolph42's drop in Light Source Editor

Post by wolph42 »

Indeed. Forgot to mention it's created in build 70.

Just create a macro an a token and paste the posted code above in it. Same result (without errors I hope).

Ah wait I make use of getinfo(campaign) which is from a pretty late mt build, not sure but could be b69?

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Wolph42's drop in Light Source Editor

Post by Raoden »

OK, no problem. Just good to know that it doesn't work in older builds.

I use b70 right now for my own games, just still using b63 for creating Drop-In Resources so that others can use them.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Wolph42's drop in Light Source Editor

Post by JamzTheMan »

Awesome, finally my light sources in alphabetic order! woot!

Not to mention, much easier to set via one Campaign macro. (Not sure why you said it doesn't work there? If you check the "Apply to selected token" it works. Although if you have multiple selected tokens, you get a prompt for each one.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Wolph42's drop in Light Source Editor

Post by wolph42 »

JamzTheMan wrote:Awesome, finally my light sources in alphabetic order! woot!

Not to mention, much easier to set via one Campaign macro. (Not sure why you said it doesn't work there? If you check the "Apply to selected token" it works. Although if you have multiple selected tokens, you get a prompt for each one.


indeed :oops: It's been quite a while since the last time ive set a macro on the campaign panel, so I just forgot that you have to set it to selected token....

Would it be nicer if in case of multiple select, all tokens are set at the same time? So the changes are applied to all selected tokens at once. I think thats relatively easy to make.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Wolph42's drop in Light Source Editor

Post by JamzTheMan »

wolph42 wrote:
JamzTheMan wrote:Awesome, finally my light sources in alphabetic order! woot!

Not to mention, much easier to set via one Campaign macro. (Not sure why you said it doesn't work there? If you check the "Apply to selected token" it works. Although if you have multiple selected tokens, you get a prompt for each one.


indeed :oops: It's been quite a while since the last time ive set a macro on the campaign panel, so I just forgot that you have to set it to selected token....

Would it be nicer if in case of multiple select, all tokens are set at the same time? So the changes are applied to all selected tokens at once. I think thats relatively easy to make.


Yes, that would be great. For bonus points, maybe add a checkbox at the bottom that defaults to checked, "Apply to all Selected Tokens"? That is, if someone would like it to function as it does now?

Also, one that changes "Sight" to would be great. I constantly have to change the sight on my PC's when they activate powers/spells that grant enhanced vision.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Wolph42's drop in Light Source Editor

Post by wolph42 »

AFAIK there are no script functions available to set sight. So a no go there. I'll have a look at the rest.
edit:correction, there are functions to set it. I'll delve into it.

I've also thought about the checkbox set for all selected, but I think that should be the default, as it currently works is rather confusing (with multiple selection) so if I can change it I'll do it without the checkbox.

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Wolph42's drop in Light Source Editor

Post by wolph42 »

hmm I thought that would be easy, but it doesnt work and I don't see why, maybe someone can shed some light on this.

[spoiler=heres the full code]

Code: Select all

<!--set light-->
<!--get lightsources from campaignproperties-->
[h:source = getInfo("campaign")]
[h:lightSource = json.get(source, "light sources")]
[h:lightTypeList = listSort(json.fields(lightSource),"A+")]

<!--remove light types not wanted-->
<!-- h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Type you want removed")) -->
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Ranges"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Suppress"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Flame"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Special"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Suppress"))]
[h:lightTypeList = listDelete(lightTypeList, listFind(lightTypeList, "Grenade"))]

<!--construct lists of light-->
[h:i = 0]
[h:inputStr = ""]

[h, foreach(lightType, lightTypeList), CODE:{
    [inputStr = listAppend(inputStr,"tab"+i+" | "+lightType+" || TAB")]
    [H, if(!i): inputStr = listAppend(inputStr, "divider |  | <html><b>The Wolph42  Light Editor</b></html>| LABEL | text=none")]
    [lights = json.get(lightSource,lightType)]
    [lightSet = lightType]
    [lightList = ""]       
    [foreach(light, lights):lightList = listappend(lightList, json.get(light, "name"))]
    [lightSetList = listSort(lightList,"N+")]
    [nlightSetList = listCount(lightSetList)]
    [h,COUNT(nlightSetList),CODE:{
        [light = listGet(lightSetList,roll.count)]
        [newStr = "Lamp"+i+"S"+roll.count+"|"+hasLightSource(lightSet, light)+"| "+light+" | CHECK"]
        [inputStr = listAppend(inputStr, newStr)]
    }]
    [H, if(!i): inputStr = listAppend(inputStr, "divider2 | ------ | ------------------------------ | LABEL")]
    [H, if(!i): inputStr = listAppend(inputStr, "removeAll | 0 | REMOVE ALL LIGHTS? | CHECK")]
    [i=i+1]
}]


<!--ask for input-->
[H: inputStr = listFormat(inputStr, "input( %list )", " ' %item ' ", ",")]
<!-- create the dialog -->
[H: status = eval(inputStr)]
[H: abort(status)]

<!--set the the lights-->
[h:i=0]
<!----------------------------------------------NEW--------------------------------------------->
[h: ids = getSelected()]
<!----------------------------------------------NEW--------------------------------------------->
[h, foreach(lightType, lightTypeList), CODE:{
    [lights = json.get(lightSource,lightType)]
    [lightSet = lightType]
    [lightList = ""]       
    [foreach(light, lights):lightList = listappend(lightList, json.get(light, "name"))]
    [lightSetList = listSort(lightList,"N+")]
    [nlightSetList = listCount(lightSetList)]
[h,COUNT(nlightSetList),CODE:{
        [light = listGet(lightSetList,roll.count)]
        [lightSetting = eval("Lamp"+i+"S"+roll.count)]
<!----------------------------------------------NEW--------------------------------------------->     
        [h, foreach(id, ids, ""): setLight(lightSet,light,lightSetting)]
<!----------------------------------------------NEW--------------------------------------------->
    }]
    [h:i=i+1]
}]


<!-- if removeAll was checked, clear all lights -->
[H, if(removeAll): clearLights()][/spoiler] I've marked the new spots

And here the the marked spots:

Code: Select all

[h: ids = getSelected()]

and

Code: Select all

[h,COUNT(nlightSetList),CODE:{
        [light = listGet(lightSetList,roll.count)]
        [lightSetting = eval("Lamp"+i+"S"+roll.count)]
        [h, foreach(id, ids, ""): setLight(lightSet,light,lightSetting)]
    }]

AFAIK this should work, but
1. it does not update every selected token
2. it keeps creating a new interface for every selected token
Anyone any suggestions?

User avatar
wolph42
Deity
Posts: 9718
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Wolph42's drop in Light Source Editor

Post by wolph42 »

I just came accross this once again and noticed my last post. Seem I've learned a lot in a year still. Anyway I know why it doesn't work and the only way to get it to work is by adding another CODE layer, which can't because its already at two levels, or adding an exta UDF, but that would defeat the drop-in purpose.

alas.

User avatar
Azhrei
Site Admin
Posts: 12050
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Wolph42's drop in Light Source Editor

Post by Azhrei »

wolph42 wrote:the only way to get it to work is by adding another CODE layer

Another option is to not do the work inside the loop, but merely keep track of what work needs to be done. Then when the existing loop is all done, loop around again in a separate one and do what you need to do.

The ugliest way to do that (!) would be to build a string that has the commands in it and execute it using eval later on. But that's an ugly hack. Another option would be to build a JSON object with one property per command to be executed and then use json.evaluate. This is still pretty ugly but much easier to actually implement (less hassle with quoting requirements).

Last, just keep a JSON array of objects/tokens that need to be processed later. Then a separate FOREACH that goes through the array can take care of it.



User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Wolph42's drop in Light Source Editor

Post by CoveredInFish »

Please emphase that its indeed not CODE what matters but {}.

So if people write {myVar} instead of [r:myVar] they might run into this problem as well.

Post Reply

Return to “Drop-In Macro Resources”