Revert parts of 449fc26e37 which didn't belong into that commit

master
Andreas Kirschbaum 2021-08-31 22:43:01 +02:00
parent 6582a9e85c
commit b50d5a356e
4 changed files with 229 additions and 244 deletions

View File

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>LegacySpellConverter</name>
<code><![CDATA[import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>LegacySpellConverter</name>
<code><![CDATA[import java.io.File;
import java.util.Iterator;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.io.RecursiveFileIterator;
import net.sf.gridarta.model.mapmodel.MapSquare;
import net.sf.gridarta.gameobject.ArchetypeParser;
import net.sf.gridarta.gameobject.ArchetypeSet;
import net.sf.gridarta.gameobject.GameObject;
import net.sf.gridarta.io.RecursiveFileIterator;
import net.sf.gridarta.map.MapSquare;
int countMapFiles = 0;
int countSpellObjects = 0;
@ -246,21 +245,21 @@ void convertGameObject(GameObject gameObject) {
case 62: // FIREWALL
case 109: // WAND
case 111: // SCROLL
/* String spellAttribute = type == 62 ? "dam" : "sp";
String spellAttribute = type == 62 ? "dam" : "sp";
if (!gameObject.iterator().hasNext()) {
int spellId = gameObject.getAttributeInt(spellAttribute);
if (spellId < 0 || spellId >= spellMapping.length || spellMapping[spellId] == null) {
print("invalid spell number " + spellId + " in object " + gameObject.getBestName() + " at " + gameObject.getMapX() + "/" + gameObject.getMapY());
} else {
Archetype spellArchetype = archetypeSet.getOrCreateArchetype(spellMapping[spellId]);
GameObject spell = gameObjectFactory.createGameObject(spellArchetype);
GameObject spell = archetypeSet.getOrCreateArchetype(spellMapping[spellId]).createArch();
spell.postParseGameObject(0);
gameObject.addLast(spell);
countSpellObjects++;
}
}
gameObject.removeAttribute(spellAttribute);*/
gameObject.removeAttribute(spellAttribute);
if (gameObject.getArchetype().getAttributeString("randomitems").length() > 0) {
gameObject.setAttributeString("randomitems", "none");
} else {
@ -270,20 +269,19 @@ void convertGameObject(GameObject gameObject) {
}
}
void convertMap(Path mapFile, String mapPath) {
print(mapPath.toString());
void convertMap(File mapFile, String mapPath) {
print(mapPath);
try {
mapControl = mapManager.openMapFile(mapFile, false);
} catch (IOException ex) {
print("Cannot load map '" + mapFile + "': " + ex.getMessage());
mapControl = mapManager.openMapFile(mapFile, false);
if (mapControl == null) {
print("Cannot load map file");
return;
}
try {
mapControl.getMapModel().beginTransaction("spell conversion");
try {
Iterator it1 = mapControl.getMapModel().iterator();
Iterator it1 = mapControl.getAllSquares().iterator();
while (it1.hasNext()) {
MapSquare mapSquare = it1.next();
Iterator it2 = mapSquare.iterator();
@ -296,7 +294,7 @@ void convertMap(Path mapFile, String mapPath) {
mapControl.getMapModel().endTransaction();
}
if (mapControl.getMapModel().isModified()) {
if (mapControl.isModified()) {
countMapFiles++;
mapControl.save();
}
@ -313,43 +311,30 @@ if (baseDirectory.endsWith("/")) {
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
}
Path mapDefaultFolder = globalSettings.getMapsDirectory();
Path rootDirectory = mapDefaultFolder.resolve(baseDirectory);
Iterator it = new RecursiveFileIterator(rootDirectory);
String mapDefaultFolder = globalSettings.getMapsDirectory().getPath();
String rootDirectory = mapDefaultFolder + baseDirectory;
Iterator it = new RecursiveFileIterator(new File(rootDirectory));
while (it.hasNext()) {
Path path = it.next();
String name = path.getFileName().toString();
if (Files.isRegularFile(path, new LinkOption[0])
&& path.toString().startsWith(rootDirectory.toString())
&& !name.equalsIgnoreCase("README")
&& !name.endsWith(".msg")
&& !name.endsWith(".py")
&& !name.endsWith(".png")
&& !name.endsWith(".ppm")
&& !name.endsWith(".quests")
&& !name.endsWith(".animation")
&& !name.equals("pshop_copier")
&& !name.equals("pshops_changelog")
&& !name.equals(".emergency")
&& !name.equals("ChangeLog")
&& !name.equals("COPYING")
&& !path.toString().contains("/.git/")
&& !path.toString().contains("/Info/")
&& !path.toString().contains("/editor/scripts/")) {
convertMap(path, path.toString().substring(mapDefaultFolder.toString().length()));
File file = it.next();
if (file.isFile()
&& file.getPath().startsWith(rootDirectory)
&& !file.getName().equalsIgnoreCase("README")
&& !file.getName().endsWith(".msg")) {
convertMap(file, file.getPath().substring(mapDefaultFolder.length()));
}
}
print("Done. Created " + countSpellObjects + " spell objects in " + countMapFiles + " map files.");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>false</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
</script>
print("Done. Created " + countSpellObjects + " spell objects in " + countMapFiles + " map files.");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>false</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
</script>

View File

@ -1,16 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>MapNormalizer</name>
<code><![CDATA[import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>MapNormalizer</name>
<code><![CDATA[import java.io.File;
import java.util.Iterator;
import net.sf.gridarta.gui.dialog.shrinkmapsize.ShrinkMapSizeUtils;
import net.sf.gridarta.map.mapmodel.MapModel;
import net.sf.gridarta.map.mapmodel.MapSquare;
import net.sf.gridarta.model.archetype.AttributeListUtils;
import net.sf.gridarta.model.direction.Direction;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.io.AttributeListUtils;
import net.sf.gridarta.model.io.RecursiveFileIterator;
void normalizeGameObject(GameObject gameObject) {
@ -22,13 +20,13 @@ void normalizeGameObject(GameObject gameObject) {
gameObject.setObjectText(AttributeListUtils.diffArchTextValues(gameObject.getArchetype(), gameObject.getObjectText()));
}
void normalizeMap(Path mapFile, String mapPath) {
void normalizeMap(File mapFile, String mapPath) {
print(mapPath);
try {
map = mapManager.openMapFile(mapFile, false);
} catch (IOException ex) {
print("Cannot load map '" + mapFile + "': " + ex.getMessage());
print("Cannot load map '"+mapFile+"': "+ex.getMessage());
return;
}
@ -50,7 +48,7 @@ void normalizeMap(Path mapFile, String mapPath) {
ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
}
Iterator it = mapModel.iterator();
Iterator it = mapModel.iterator ();
while (it.hasNext()) {
Iterator it2 = it.next().iterator();
while (it2.hasNext()) {
@ -61,7 +59,9 @@ void normalizeMap(Path mapFile, String mapPath) {
mapModel.endTransaction();
}
map.save();
if (map.getMapModel().isModified()) {
map.save();
}
} finally {
mapManager.release(map);
}
@ -75,14 +75,15 @@ if (baseDirectory.endsWith("/")) {
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
}
Path mapDefaultFolder = globalSettings.getMapsDirectory();
Path rootDirectory = mapDefaultFolder.resolve(baseDirectory);
Iterator it = new RecursiveFileIterator(rootDirectory);
String mapDefaultFolder = globalSettings.getMapsDirectory().getPath();
String rootDirectory = mapDefaultFolder + baseDirectory;
Iterator it = new RecursiveFileIterator(new File(rootDirectory));
while (it.hasNext()) {
Path path = it.next();
String name = path.getFileName().toString();
if (Files.isRegularFile(path, new LinkOption[0])
&& path.toString().startsWith(rootDirectory.toString())
File file = it.next();
String name = file.getName();
String path = file.getPath();
if (file.isFile()
&& path.startsWith(rootDirectory)
&& !name.equalsIgnoreCase("README")
&& !name.endsWith(".msg")
&& !name.endsWith(".py")
@ -95,23 +96,24 @@ while (it.hasNext()) {
&& !name.equals(".emergency")
&& !name.equals("ChangeLog")
&& !name.equals("COPYING")
&& !path.toString().contains("/.git/")
&& !path.toString().contains("/Info/")
&& !path.toString().contains("/editor/scripts/")) {
normalizeMap(path, path.toString().substring(mapDefaultFolder.toString().length()));
&& !path.contains("/.git/")
&& !path.contains("/Info/")
&& !path.contains("/editor/scripts/")) {
normalizeMap(file, file.getPath().substring(mapDefaultFolder.length()));
}
}
print("Done.");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
</script>
print("Done.");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
</script>

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>MapValidator</name>
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>MapValidator</name>
<code><![CDATA[import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Iterator;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.io.RecursiveFileIterator;
@ -20,11 +18,11 @@ void log(String message) {
}
}
void checkMap(Path mapFile, String mapPath) {
void checkMap(File mapFile, String mapPath) {
try {
map = mapManager.openMapFile(mapFile, false);
} catch (IOException ex) {
print("Cannot load map '" + mapFile + "': " + ex.getMessage());
print("Cannot load map '"+mapFile+"': "+ex.getMessage());
return;
}
if (map == null) {
@ -95,14 +93,15 @@ try {
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
}
Path mapDefaultFolder = globalSettings.getMapsDirectory();
Path rootDirectory = mapDefaultFolder.resolve(baseDirectory);
Iterator it = new RecursiveFileIterator(rootDirectory);
String mapDefaultFolder = globalSettings.getMapsDirectory().getPath();
String rootDirectory = mapDefaultFolder + baseDirectory;
Iterator it = new RecursiveFileIterator(new File(rootDirectory));
while (it.hasNext()) {
Path path = it.next();
String name = path.getFileName().toString();
if (Files.isRegularFile(path, new LinkOption[0])
&& path.toString().startsWith(rootDirectory.toString())
File file = it.next();
String name = file.getName();
String path = file.getPath();
if (file.isFile()
&& path.startsWith(rootDirectory)
&& !name.equalsIgnoreCase("README")
&& !name.endsWith(".animation")
&& !name.endsWith(".msg")
@ -119,10 +118,10 @@ try {
&& !name.equals("ChangeLog")
&& !name.equals("COPYING")
&& !name.equals("TODO")
&& !path.toString().contains("/.git/")
&& !path.toString().contains("/Info/")
&& !path.toString().contains("/editor/scripts/")) {
checkMap(path, path.toString().substring(mapDefaultFolder.toString().length()));
&& !path.contains("/.git/")
&& !path.contains("/Info/")
&& !path.contains("/editor/scripts/")) {
checkMap(file, file.getPath().substring(mapDefaultFolder.length()));
}
}
@ -131,30 +130,31 @@ try {
if (logFile != null) {
logFile.close();
}
}]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
<parameter>
<name>errorLimit</name>
<description>Maximum number of errors to show for each map; 0=show all errors</description>
<type>java.lang.Integer</type>
<value>20</value>
<minimum>0</minimum>
<maximum>2147483647</maximum>
</parameter>
<parameter>
<name>logFilename</name>
<description>Copy errors to this file; empty=no copy to file</description>
<type>java.lang.String</type>
<value />
</parameter>
</script>
}]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>baseDirectory</name>
<description>Base Directory</description>
<type>MapPathParameter</type>
<value>/</value>
</parameter>
<parameter>
<name>errorLimit</name>
<description>Maximum number of errors to show for each map; 0=show all errors</description>
<type>java.lang.Integer</type>
<value>20</value>
<minimum>0</minimum>
<maximum>2147483647</maximum>
</parameter>
<parameter>
<name>logFilename</name>
<description>Copy errors to this file; empty=no copy to file</description>
<type>java.lang.String</type>
<value />
</parameter>
</script>

View File

@ -1,36 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>WorldMaker</name>
<code><![CDATA[import java.io.IOException;
<?xml version="1.0" encoding="UTF-8"?>
<script>
<name>WorldMaker</name>
<code><![CDATA[import cfeditor.IGUIConstants;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.RandomAccessFile;
import java.io.FileOutputStream;
import java.io.File;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
Path getSimpleFilename(Path mapFile) {
String mapFilename = mapFile.toString();
File getSimpleFilename(File mapFile) {
String mapFilename = mapFile.getPath();
int i = mapFilename.lastIndexOf(File.separator);
if (i > 0) {
mapFilename = mapFilename.substring(i + 1);
}
return Paths.get(mapFilename, new String[0]);
return new File(mapFilename);
}
Path getPngImageFilename(Path mapFile) {
return locationDir.resolve(PictureDirectory + getSimpleFilename(mapFile) + ".png");
File getPngImageFilename(File mapFile) {
return new File(locationDir, PictureDirectory + getSimpleFilename(mapFile) + ".png");
}
boolean updateMap(Path mapFile, Path pictureFile) {
if (!Files.exists(mapFile, new LinkOption[0])) {
boolean updateMap(File mapFile, File pictureFile) {
if (!mapFile.exists()) {
return false;
}
if (Files.exists(pictureFile, new LinkOption[0]) && Files.getLastModifiedTime(pictureFile, new LinkOption[0]).toMillis() >= Files.getLastModifiedTime(mapFile, new LinkOption[0]).toMillis()) {
if (pictureFile.exists() && pictureFile.lastModified() >= mapFile.lastModified()) {
return false;
}
print("converting " + mapFile + " to " + pictureFile + ".");
@ -41,7 +38,7 @@ boolean updateMap(Path mapFile, Path pictureFile) {
}
try {
try {
ImageIO.write(rendererFactory.newSimpleMapRenderer(map.getMapModel()).getFullImage(), "png", pictureFile.toFile());
ImageIO.write(rendererFactory.newSimpleMapRenderer(map.getMapModel()).getFullImage(), "png", pictureFile);
} catch (IOException ex) {
print("cannot write " + pictureFile + ": " + ex.getMessage());
return false;
@ -71,7 +68,7 @@ void checkDaList() {
if (Location == null || Location.length() == 0) {
locationDir = globalSettings.getMapsDirectory();
} else {
locationDir = Paths.get(Location);
locationDir = new File(Location);
}
print("World map will be " + DestWidth + "x" + DestHeight + " in size");
@ -79,7 +76,7 @@ void checkDaList() {
if (!PictureDirectory.endsWith(File.separator)) {
PictureDirectory = PictureDirectory + File.separator;
}
Files.createDirectories(locationDir.resolve(PictureDirectory), new FileAttribute[0]);
new File(locationDir, PictureDirectory).mkdirs();
final long bytesPerPixel = 3L;
@ -87,10 +84,10 @@ void checkDaList() {
boolean firstRun = false;
byte[] header = ("P6\n" + DestWidth + " " + DestHeight + "\n255\n").getBytes("ISO-8859-1");
long headerSize = header.length;
Path destinationFilePpm = locationDir.resolve(PictureDirectory + WorldPicture + ".ppm");
Path destinationFilePng = locationDir.resolve(PictureDirectory + WorldPicture + ".png");
File destinationFilePpm = new File(locationDir, PictureDirectory + WorldPicture + ".ppm");
File destinationFilePng = new File(locationDir, PictureDirectory + WorldPicture + ".png");
File tempFile = new File("/tmp/tmp.ppm");
if (Files.exists(destinationFilePpm, new LinkOption[0])) {
if (destinationFilePpm.exists()) {
runCommand("cp '" + destinationFilePpm + "' '" + tempFile + "'");
} else {
print("generating empty picture");
@ -113,10 +110,10 @@ void checkDaList() {
for (int y = 0; y < NumY.intValue(); y++) {
currentX = StartX.intValue() + x;
currentY = StartY.intValue() + y;
currentMap = locationDir.resolve(MapFilename + "_" + currentX + "_" + currentY);
currentMap = new File(locationDir, MapFilename + "_" + currentX + "_" + currentY);
currentPicture = getPngImageFilename(currentMap);
didUpdate = updateMap(currentMap, currentPicture);
if ((didUpdate || firstRun) && Files.exists(currentPicture, new LinkOption[0])) {
if ((didUpdate || firstRun) && currentPicture.exists()) {
runCommand("pngtopnm '" + currentPicture + "' | pnmscale -xysize " + TileWidth + " " + TileHeight + " > '" + tempImageFile + "'");
FileInputStream fis = new FileInputStream(tempImageFile);
fis.skip(toSkip);
@ -138,84 +135,85 @@ void checkDaList() {
runCommand("mv /tmp/tmp.png '" + destinationFilePng + "'");
}
Path locationDir;
File locationDir;
checkDaList();
print("Done!");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>Location</name>
<description>Specify the map directory to use by this script. Leave empty for maps directory</description>
<type>java.lang.String</type>
<value />
</parameter>
<parameter>
<name>MapFilename</name>
<description>This map file name will be appended to the 'Location' parameter and '_mapx_mapy' will be added at the end</description>
<type>java.lang.String</type>
<value>world/world</value>
</parameter>
<parameter>
<name>TileWidth</name>
<description>The width in pixel of each generate map image</description>
<type>java.lang.Integer</type>
<value>50</value>
<minimum>0</minimum>
<maximum>2000</maximum>
</parameter>
<parameter>
<name>TileHeight</name>
<description>The height in pixel of each generated map image</description>
<type>java.lang.Integer</type>
<value>50</value>
<minimum>0</minimum>
<maximum>2000</maximum>
</parameter>
<parameter>
<name>NumX</name>
<description>The number of maps along X axis to analyze</description>
<type>java.lang.Integer</type>
<value>30</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>NumY</name>
<description>The number of maps along Y axis to analyze</description>
<type>java.lang.Integer</type>
<value>30</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>StartX</name>
<description>The first coordinate along X axis to analyze</description>
<type>java.lang.Integer</type>
<value>100</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>StartY</name>
<description>The first coordinate along Y axis to analyze</description>
<type>java.lang.Integer</type>
<value>100</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>PictureDirectory</name>
<description>The subdirectory where to put pictures</description>
<type>java.lang.String</type>
<value>images</value>
</parameter>
<parameter>
<name>WorldPicture</name>
<description>The picture which will store the world map</description>
<type>java.lang.String</type>
<value>worldmap</value>
</parameter>
</script>
print("Done!");]]></code>
<mode>
<autoboot>false</autoboot>
<bash>true</bash>
<filter>false</filter>
</mode>
<parameter>
<name>Location</name>
<description>Specify the map directory to use by this script. Leave empty for maps directory</description>
<type>java.lang.String</type>
<value />
</parameter>
<parameter>
<name>MapFilename</name>
<description>This map file name will be appended to the 'Location' parameter and '_mapx_mapy' will be added at the end</description>
<type>java.lang.String</type>
<value>world/world</value>
</parameter>
<parameter>
<name>TileWidth</name>
<description>The width in pixel of each generate map image</description>
<type>java.lang.Integer</type>
<value>50</value>
<minimum>0</minimum>
<maximum>2000</maximum>
</parameter>
<parameter>
<name>TileHeight</name>
<description>The height in pixel of each generated map image</description>
<type>java.lang.Integer</type>
<value>50</value>
<minimum>0</minimum>
<maximum>2000</maximum>
</parameter>
<parameter>
<name>NumX</name>
<description>The number of maps along X axis to analyze</description>
<type>java.lang.Integer</type>
<value>30</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>NumY</name>
<description>The number of maps along Y axis to analyze</description>
<type>java.lang.Integer</type>
<value>30</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>StartX</name>
<description>The first coordinate along X axis to analyze</description>
<type>java.lang.Integer</type>
<value>100</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>StartY</name>
<description>The first coordinate along Y axis to analyze</description>
<type>java.lang.Integer</type>
<value>100</value>
<minimum>0</minimum>
<maximum>50000</maximum>
</parameter>
<parameter>
<name>PictureDirectory</name>
<description>The subdirectory where to put pictures</description>
<type>java.lang.String</type>
<value>images</value>
</parameter>
<parameter>
<name>WorldPicture</name>
<description>The picture which will store the world map</description>
<type>java.lang.String</type>
<value>worldmap</value>
</parameter>
</script>