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

View File

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

View File

@ -2,10 +2,8 @@
<script> <script>
<name>MapValidator</name> <name>MapValidator</name>
<code><![CDATA[import java.io.BufferedWriter; <code><![CDATA[import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Iterator; import java.util.Iterator;
import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.io.RecursiveFileIterator; 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 { try {
map = mapManager.openMapFile(mapFile, false); map = mapManager.openMapFile(mapFile, false);
} catch (IOException ex) { } catch (IOException ex) {
print("Cannot load map '" + mapFile + "': " + ex.getMessage()); print("Cannot load map '"+mapFile+"': "+ex.getMessage());
return; return;
} }
if (map == null) { if (map == null) {
@ -95,14 +93,15 @@ try {
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1); baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
} }
Path mapDefaultFolder = globalSettings.getMapsDirectory(); String mapDefaultFolder = globalSettings.getMapsDirectory().getPath();
Path rootDirectory = mapDefaultFolder.resolve(baseDirectory); String rootDirectory = mapDefaultFolder + baseDirectory;
Iterator it = new RecursiveFileIterator(rootDirectory); Iterator it = new RecursiveFileIterator(new File(rootDirectory));
while (it.hasNext()) { while (it.hasNext()) {
Path path = it.next(); File file = it.next();
String name = path.getFileName().toString(); String name = file.getName();
if (Files.isRegularFile(path, new LinkOption[0]) String path = file.getPath();
&& path.toString().startsWith(rootDirectory.toString()) if (file.isFile()
&& path.startsWith(rootDirectory)
&& !name.equalsIgnoreCase("README") && !name.equalsIgnoreCase("README")
&& !name.endsWith(".animation") && !name.endsWith(".animation")
&& !name.endsWith(".msg") && !name.endsWith(".msg")
@ -119,10 +118,10 @@ try {
&& !name.equals("ChangeLog") && !name.equals("ChangeLog")
&& !name.equals("COPYING") && !name.equals("COPYING")
&& !name.equals("TODO") && !name.equals("TODO")
&& !path.toString().contains("/.git/") && !path.contains("/.git/")
&& !path.toString().contains("/Info/") && !path.contains("/Info/")
&& !path.toString().contains("/editor/scripts/")) { && !path.contains("/editor/scripts/")) {
checkMap(path, path.toString().substring(mapDefaultFolder.toString().length())); checkMap(file, file.getPath().substring(mapDefaultFolder.length()));
} }
} }
@ -158,3 +157,4 @@ try {
<value /> <value />
</parameter> </parameter>
</script> </script>

View File

@ -1,36 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<script> <script>
<name>WorldMaker</name> <name>WorldMaker</name>
<code><![CDATA[import java.io.IOException; <code><![CDATA[import cfeditor.IGUIConstants;
import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.File;
import java.nio.MappedByteBuffer; import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel; 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) { File getSimpleFilename(File mapFile) {
String mapFilename = mapFile.toString(); String mapFilename = mapFile.getPath();
int i = mapFilename.lastIndexOf(File.separator); int i = mapFilename.lastIndexOf(File.separator);
if (i > 0) { if (i > 0) {
mapFilename = mapFilename.substring(i + 1); mapFilename = mapFilename.substring(i + 1);
} }
return Paths.get(mapFilename, new String[0]); return new File(mapFilename);
} }
Path getPngImageFilename(Path mapFile) { File getPngImageFilename(File mapFile) {
return locationDir.resolve(PictureDirectory + getSimpleFilename(mapFile) + ".png"); return new File(locationDir, PictureDirectory + getSimpleFilename(mapFile) + ".png");
} }
boolean updateMap(Path mapFile, Path pictureFile) { boolean updateMap(File mapFile, File pictureFile) {
if (!Files.exists(mapFile, new LinkOption[0])) { if (!mapFile.exists()) {
return false; 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; return false;
} }
print("converting " + mapFile + " to " + pictureFile + "."); print("converting " + mapFile + " to " + pictureFile + ".");
@ -41,7 +38,7 @@ boolean updateMap(Path mapFile, Path pictureFile) {
} }
try { try {
try { try {
ImageIO.write(rendererFactory.newSimpleMapRenderer(map.getMapModel()).getFullImage(), "png", pictureFile.toFile()); ImageIO.write(rendererFactory.newSimpleMapRenderer(map.getMapModel()).getFullImage(), "png", pictureFile);
} catch (IOException ex) { } catch (IOException ex) {
print("cannot write " + pictureFile + ": " + ex.getMessage()); print("cannot write " + pictureFile + ": " + ex.getMessage());
return false; return false;
@ -71,7 +68,7 @@ void checkDaList() {
if (Location == null || Location.length() == 0) { if (Location == null || Location.length() == 0) {
locationDir = globalSettings.getMapsDirectory(); locationDir = globalSettings.getMapsDirectory();
} else { } else {
locationDir = Paths.get(Location); locationDir = new File(Location);
} }
print("World map will be " + DestWidth + "x" + DestHeight + " in size"); print("World map will be " + DestWidth + "x" + DestHeight + " in size");
@ -79,7 +76,7 @@ void checkDaList() {
if (!PictureDirectory.endsWith(File.separator)) { if (!PictureDirectory.endsWith(File.separator)) {
PictureDirectory = PictureDirectory + File.separator; PictureDirectory = PictureDirectory + File.separator;
} }
Files.createDirectories(locationDir.resolve(PictureDirectory), new FileAttribute[0]); new File(locationDir, PictureDirectory).mkdirs();
final long bytesPerPixel = 3L; final long bytesPerPixel = 3L;
@ -87,10 +84,10 @@ void checkDaList() {
boolean firstRun = false; boolean firstRun = false;
byte[] header = ("P6\n" + DestWidth + " " + DestHeight + "\n255\n").getBytes("ISO-8859-1"); byte[] header = ("P6\n" + DestWidth + " " + DestHeight + "\n255\n").getBytes("ISO-8859-1");
long headerSize = header.length; long headerSize = header.length;
Path destinationFilePpm = locationDir.resolve(PictureDirectory + WorldPicture + ".ppm"); File destinationFilePpm = new File(locationDir, PictureDirectory + WorldPicture + ".ppm");
Path destinationFilePng = locationDir.resolve(PictureDirectory + WorldPicture + ".png"); File destinationFilePng = new File(locationDir, PictureDirectory + WorldPicture + ".png");
File tempFile = new File("/tmp/tmp.ppm"); File tempFile = new File("/tmp/tmp.ppm");
if (Files.exists(destinationFilePpm, new LinkOption[0])) { if (destinationFilePpm.exists()) {
runCommand("cp '" + destinationFilePpm + "' '" + tempFile + "'"); runCommand("cp '" + destinationFilePpm + "' '" + tempFile + "'");
} else { } else {
print("generating empty picture"); print("generating empty picture");
@ -113,10 +110,10 @@ void checkDaList() {
for (int y = 0; y < NumY.intValue(); y++) { for (int y = 0; y < NumY.intValue(); y++) {
currentX = StartX.intValue() + x; currentX = StartX.intValue() + x;
currentY = StartY.intValue() + y; currentY = StartY.intValue() + y;
currentMap = locationDir.resolve(MapFilename + "_" + currentX + "_" + currentY); currentMap = new File(locationDir, MapFilename + "_" + currentX + "_" + currentY);
currentPicture = getPngImageFilename(currentMap); currentPicture = getPngImageFilename(currentMap);
didUpdate = updateMap(currentMap, currentPicture); 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 + "'"); runCommand("pngtopnm '" + currentPicture + "' | pnmscale -xysize " + TileWidth + " " + TileHeight + " > '" + tempImageFile + "'");
FileInputStream fis = new FileInputStream(tempImageFile); FileInputStream fis = new FileInputStream(tempImageFile);
fis.skip(toSkip); fis.skip(toSkip);
@ -138,7 +135,7 @@ void checkDaList() {
runCommand("mv /tmp/tmp.png '" + destinationFilePng + "'"); runCommand("mv /tmp/tmp.png '" + destinationFilePng + "'");
} }
Path locationDir; File locationDir;
checkDaList(); checkDaList();
print("Done!");]]></code> print("Done!");]]></code>
<mode> <mode>
@ -219,3 +216,4 @@ print("Done!");]]></code>
<value>worldmap</value> <value>worldmap</value>
</parameter> </parameter>
</script> </script>