From: <aki...@us...> - 2006-12-12 03:39:23
|
Revision: 1012 http://svn.sourceforge.net/gridarta/?rev=1012&view=rev Author: akirschbaum Date: 2006-12-10 07:15:27 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Whitespace changes; remove debugging print statements. Modified Paths: -------------- trunk/crossfire/resource/conf/scripts.xml Modified: trunk/crossfire/resource/conf/scripts.xml =================================================================== --- trunk/crossfire/resource/conf/scripts.xml 2006-12-10 14:23:47 UTC (rev 1011) +++ trunk/crossfire/resource/conf/scripts.xml 2006-12-10 15:15:27 UTC (rev 1012) @@ -2,101 +2,114 @@ <scripts> <script> <name>WorldMaker</name> - <code><![CDATA[//input your beanshell Code -import java.io.*; + <code><![CDATA[import java.io.*; import cfeditor.IGUIConstants; + /* * Functions declaration */ -String getSimpleFilename(String mapFilename){ - int i = mapFilename.lastIndexOf(File.separator); - if (i>0) - mapFilename=mapFilename.substring(i+1); - return mapFilename; +String getSimpleFilename(String mapFilename) { + int i = mapFilename.lastIndexOf(File.separator); + if (i > 0) { + mapFilename = mapFilename.substring(i + 1); + } + return mapFilename; } -String getPngImageFilename(String mapFilename){ - return Location+PictureDirectory+getSimpleFilename(mapFilename)+".png"; +String getPngImageFilename(String mapFilename) { + return Location + PictureDirectory + getSimpleFilename(mapFilename) + ".png"; } -boolean updateMap(String mapFile, String pictureFile){ - File image = new File(pictureFile); - File map = new File(mapFile); - if (!map.exists()) - return false; - if ( (image.exists()) && (image.lastModified() >= map.lastModified())) - return false; - print ("converting "+mapFile+" to "+pictureFile+"."); - mapControl = mainControl.openFile(map,false); - print ("map control is "+mapControl); - mainControl.createImageWanted(mapControl, pictureFile); - mainControl.closeLevel(mapControl,true); - return true; + +boolean updateMap(String mapFile, String pictureFile) { + File image = new File(pictureFile); + File map = new File(mapFile); + if (!map.exists()) { + return false; + } + if (image.exists() && image.lastModified() >= map.lastModified()) { + return false; + } + print("converting " + mapFile + " to " + pictureFile + "."); + mapControl = mainControl.openFile(map, false); + mainControl.createImageWanted(mapControl, pictureFile); + mainControl.closeLevel(mapControl, true); + return true; } -boolean fileExists(String name){return new File(name).exists();} -boolean runCommand(String cmd){ - f = File.createTempFile("WMaker",".sh"); - FileWriter out = new FileWriter(f); - out.write(cmd); - out.close(); - print ("running "+cmd); - Process p = Runtime.getRuntime().exec("sh "+f.getAbsolutePath()); - p.waitFor(); - f.delete(); - return (p.exitValue()==0); + +boolean fileExists(String name) { + return new File(name).exists(); } + +boolean runCommand(String cmd) { + f = File.createTempFile("WMaker", ".sh"); + FileWriter out = new FileWriter(f); + out.write(cmd); + out.close(); + print("running " + cmd); + Process p = Runtime.getRuntime().exec("sh " + f.getAbsolutePath()); + p.waitFor(); + f.delete(); + return p.exitValue() == 0; +} + /* * Running code */ -void checkDaList(){ - DestWidth=TileWidth.intValue()*NumX.intValue(); - DestHeight=TileHeight.intValue()*NumY.intValue(); - if ( (Location==null) || (Location.length()<1)){ - Location=mainControl.getMapDefaultFolder(); - print ("autodetected location "+Location); - } - print ("World map will be "+DestWidth+"x"+DestHeight+" in size"); - if (!Location.endsWith(File.separator)) - Location=Location+File.separator; - HashSet mapList = new HashSet(); - boolean firstRun = false; - if (fileExists(Location+PictureDirectory+WorldPicture+".ppm")){ - runCommand("cp "+Location+PictureDirectory+WorldPicture+".ppm /tmp/tmp.ppm"); - } else{ - runCommand("ppmmake \\#000 "+DestWidth+" "+DestHeight+" > /tmp/tmp.ppm"); - firstRun=true; - print ("Creating images for the first time."); - } - for (int x = 0;x< NumX.intValue();x++){ - for (int y = 0;y< NumY.intValue();y++){ - currentX = StartX.intValue()+x; - currentY = StartY.intValue()+y; - currentMap = Location+MapFilename+"_"+currentX+"_"+currentY; - currentPicture = getPngImageFilename(currentMap); - didUpdate = updateMap(currentMap,currentPicture); - if ( (didUpdate || firstRun) && fileExists(currentPicture)){ - print ("converting ...."); - runCommand("pngtopnm "+currentPicture+" | pnmscale -xysize "+TileWidth+" "+TileHeight+" > /tmp/ppm.tmp"); - sx = x * TileWidth.intValue(); - sy = y * TileHeight.intValue(); - runCommand("pnmpaste /tmp/ppm.tmp "+sx+" "+sy+" /tmp/tmp.ppm > /tmp/tmp.ppm1"); - runCommand("rm -f /tmp/tmp.ppm"); - runCommand("mv /tmp/tmp.ppm1 /tmp/tmp.ppm"); - } - } - } - runCommand("mv /tmp/tmp.ppm "+Location+PictureDirectory+WorldPicture+".ppm"); - print ("converting to png if possible.\n"); - runCommand("pnmtopng "+Location+PictureDirectory+WorldPicture+".ppm > /tmp/tmp.png"); - runCommand("mv /tmp/tmp.png "+Location+PictureDirectory+WorldPicture+".png"); +void checkDaList() { + DestWidth = TileWidth.intValue() * NumX.intValue(); + DestHeight = TileHeight.intValue() * NumY.intValue(); + + if (Location == null || Location.length() < 1) { + Location=mainControl.getMapDefaultFolder(); + print("autodetected location " + Location); + } + + print("World map will be " + DestWidth + "x" + DestHeight + " in size"); + if (!Location.endsWith(File.separator)) { + Location = Location + File.separator; + } + + HashSet mapList = new HashSet(); + boolean firstRun = false; + if (fileExists(Location + PictureDirectory + WorldPicture + ".ppm")) { + runCommand("cp " + Location + PictureDirectory + WorldPicture + ".ppm /tmp/tmp.ppm"); + } else { + runCommand("ppmmake \\#000 " + DestWidth + " " + DestHeight + " > /tmp/tmp.ppm"); + firstRun = true; + print("Creating images for the first time."); + } + + for (int x = 0; x < NumX.intValue(); x++) { + for (int y = 0;y < NumY.intValue(); y++) { + currentX = StartX.intValue() + x; + currentY = StartY.intValue() + y; + currentMap = Location + MapFilename + "_" + currentX + "_" + currentY; + currentPicture = getPngImageFilename(currentMap); + didUpdate = updateMap(currentMap, currentPicture); + if ((didUpdate || firstRun) && fileExists(currentPicture)) { + runCommand("pngtopnm " + currentPicture + " | pnmscale -xysize " + TileWidth + " " + TileHeight + " > /tmp/ppm.tmp"); + sx = x * TileWidth.intValue(); + sy = y * TileHeight.intValue(); + runCommand("pnmpaste /tmp/ppm.tmp " + sx + " " + sy + " /tmp/tmp.ppm > /tmp/tmp.ppm1"); + runCommand("rm -f /tmp/tmp.ppm"); + runCommand("mv /tmp/tmp.ppm1 /tmp/tmp.ppm"); + } + } + } + runCommand("mv /tmp/tmp.ppm " + Location + PictureDirectory + WorldPicture + ".ppm"); + print("converting to png if possible.\n"); + runCommand("pnmtopng " + Location + PictureDirectory + WorldPicture + ".ppm > /tmp/tmp.png"); + runCommand("mv /tmp/tmp.png " + Location + PictureDirectory + WorldPicture + ".png"); } + // Max run is mandatory because we are not yet able to kill batch scripts int maxRun = 20; -while ( (maxRun>0) && (!scriptThread.isInterrupted())){ - checkDaList(); - Thread.sleep(CheckDelay.intValue()); - maxRun--; +while (maxRun > 0 && !scriptThread.isInterrupted()) { + checkDaList(); + Thread.sleep(CheckDelay.intValue()); + maxRun--; } -print ("Done!");]]></code> +print("Done!");]]></code> <mode> <autoboot>false</autoboot> <bash>true</bash> @@ -184,4 +197,3 @@ </parameter> </script> </scripts> - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |