Using BeanShell with jXPMap

BeanShell is an excellent scripting language for Java which has saved my butt multiple times when a customer has wanted to see a demonstration about somthing that I was not prepared for. Basically it allows you to access the Java objects running inside a JVM in the same way you access them from ordinary Java code. As the map editor is written in Java BeanShell allows you to easily manipulate the map being edited using just the same objects that the editor uses to represent the map. Obviously you need to know how to use those objects but hey you can always use the source Luke :)

BeanShell itself has an extensive documentation on its web site: http://www.beanshell.org. To get you started, you can download this script file, which contains a few simple example functions, that try to do something useful with the map. To make things easy, save the file into your home directory with name .bshrc. That way BeanShell loads and sources the file automatically when you start it. You can also save it using any name you wish, but then you have to give a command source("/path/to/the/file"); in the BeanShell console to load it.

The script includes the following example functions:

  • randomize(pixels) which randomizes the map with the given amount of pixels
  • shadow() which adds a (rather ugly) shadow to all wall polygons
  • smooth(max) which smoothens the corenrs of the wall polygons. The max parameter controls the maximum amount of pixels a vertex gets moved.