diff --git a/build.gradle b/build.gradle index e2d8f90..78804d4 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group 'pl.asie.zima' -version '0.8.1' +version '0.8.2' repositories { mavenCentral() diff --git a/docs/changelog/0.8.2.txt b/docs/changelog/0.8.2.txt new file mode 100644 index 0000000..6a33042 --- /dev/null +++ b/docs/changelog/0.8.2.txt @@ -0,0 +1,7 @@ +Improvements: + +* MegaZeux image conversion is now up to ~6% faster. + +Bugs fixed: + +* Fixed outputting Super ClassicZoo and WeaveZZT board files. \ No newline at end of file diff --git a/docs/changelog/versions.txt b/docs/changelog/versions.txt index 1deb953..829171e 100644 --- a/docs/changelog/versions.txt +++ b/docs/changelog/versions.txt @@ -10,3 +10,4 @@ 0.7.0 0.8.0 0.8.1 +0.8.2 \ No newline at end of file diff --git a/src/main/java/pl/asie/libzzt/Board.java b/src/main/java/pl/asie/libzzt/Board.java index 083d638..d3022e7 100644 --- a/src/main/java/pl/asie/libzzt/Board.java +++ b/src/main/java/pl/asie/libzzt/Board.java @@ -146,7 +146,7 @@ public void readZ(ZInputStream inStream) throws IOException { } try (ByteArrayInputStream byteStream = new ByteArrayInputStream(data); ZInputStream stream = new ZInputStream(byteStream)) { - this.name = stream.readPString(platform == Platform.SUPER_ZZT ? 60 : 50); + this.name = stream.readPString(platform.getZztWorldFormat().isSuperZZTLike() ? 60 : 50); int ix = 1; int iy = 1; @@ -171,23 +171,23 @@ public void readZ(ZInputStream inStream) throws IOException { } while (iy <= this.height); this.maxShots = stream.readPByte(); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { this.dark = stream.readPBoolean(); } for (int i = 0; i < 4; i++) this.neighborBoards[i] = stream.readPByte(); this.reenterWhenZapped = stream.readPBoolean(); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { this.message = stream.readPString(58); } this.startPlayerX = stream.readPByte(); this.startPlayerY = stream.readPByte(); - if (platform == Platform.SUPER_ZZT) { + if (platform.getZztWorldFormat().isSuperZZTLike()) { stream.readPShort(); // DrawXOffset - TOOD stream.readPShort(); // DrawYOffset - TOOD } this.timeLimitSec = stream.readPShort(); - int skipCount = platform == Platform.SUPER_ZZT ? 14 : 16; + int skipCount = platform.getZztWorldFormat().isSuperZZTLike() ? 14 : 16; if (stream.skip(skipCount) != skipCount) { throw new IOException(); } @@ -207,7 +207,7 @@ public void readZ(ZInputStream inStream) throws IOException { public void writeZ(ZOutputStream outStream) throws IOException { try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ZOutputStream stream = new ZOutputStream(byteStream)) { - stream.writePString(this.name, platform == Platform.SUPER_ZZT ? 60 : 50); + stream.writePString(this.name, platform.getZztWorldFormat().isSuperZZTLike() ? 60 : 50); // fancy RLE logic int ix = 1; @@ -235,23 +235,23 @@ public void writeZ(ZOutputStream outStream) throws IOException { } while (iy <= this.height); stream.writePByte(this.maxShots); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { stream.writePBoolean(this.dark); } for (int i = 0; i < 4; i++) stream.writePByte(this.neighborBoards[i]); stream.writePBoolean(this.reenterWhenZapped); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { stream.writePString(this.message, 58); } stream.writePByte(this.startPlayerX); stream.writePByte(this.startPlayerY); - if (platform == Platform.SUPER_ZZT) { + if (platform.getZztWorldFormat().isSuperZZTLike()) { stream.writePShort(0); // DrawXOffset - TODO stream.writePShort(0); // DrawYOffset - TODO } stream.writePShort(this.timeLimitSec); - stream.pad(platform == Platform.SUPER_ZZT ? 14 : 16); + stream.pad(platform.getZztWorldFormat().isSuperZZTLike() ? 14 : 16); stream.writePShort(stats.size() - 1); diff --git a/src/main/java/pl/asie/libzzt/Platform.java b/src/main/java/pl/asie/libzzt/Platform.java index ae28e30..d99abb3 100644 --- a/src/main/java/pl/asie/libzzt/Platform.java +++ b/src/main/java/pl/asie/libzzt/Platform.java @@ -49,6 +49,8 @@ public final class Platform { private final boolean maxStatCountIsActual = false; @Builder.Default private final boolean supportsBlinking = true; + @Builder.Default + private final ZztWorldSerializationFormat zztWorldFormat = null; private final ElementLibrary library; public static final Platform ZZT; @@ -74,14 +76,14 @@ public boolean isDoubleWide(TextVisualData visual) { } static { - ZZT = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(20000 + 2).maxStatCount(150).library(ElementLibraryZZT.INSTANCE).build(); - SUPER_ZZT = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(20000 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).build(); - SUPER_CLASSICZOO = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(65500 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).build(); + ZZT = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(20000 + 2).maxStatCount(150).library(ElementLibraryZZT.INSTANCE).zztWorldFormat(ZztWorldSerializationFormat.ZZT).build(); + SUPER_ZZT = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(20000 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).zztWorldFormat(ZztWorldSerializationFormat.SUPER_ZZT).build(); + SUPER_CLASSICZOO = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(65500 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).zztWorldFormat(ZztWorldSerializationFormat.SUPER_ZZT).build(); MEGAZEUX = Platform.builder().usesBoard(false).boardWidth(65535).boardHeight(65535).defaultBoardWidth(80).defaultBoardHeight(25).supportsBlinking(false).library(ElementLibraryNull.INSTANCE).build(); try { WeaveZZTPlatformData platformData = WeaveZZTPlatformData.parse(ElementLibraryZZT.INSTANCE, null); - WEAVE_ZZT_25 = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(65500 + 2).maxStatCount(150).library(platformData.getLibrary()).build(); + WEAVE_ZZT_25 = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(65500 + 2).maxStatCount(150).library(platformData.getLibrary()).zztWorldFormat(ZztWorldSerializationFormat.ZZT).build(); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/pl/asie/libzzt/Stat.java b/src/main/java/pl/asie/libzzt/Stat.java index 8a2ec8e..332bfc8 100644 --- a/src/main/java/pl/asie/libzzt/Stat.java +++ b/src/main/java/pl/asie/libzzt/Stat.java @@ -114,7 +114,7 @@ public void readZ(ZInputStream stream, Platform platform) throws IOException { } this.dataPos = stream.readPShort(); int dataLen = stream.readPShort(); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { if (stream.skip(8) != 8) { throw new IOException("Could not skip unk!"); } @@ -130,7 +130,7 @@ public void readZ(ZInputStream stream, Platform platform) throws IOException { } public int lengthZ(Platform platform) { - int len = (platform == Platform.ZZT ? 33 : 25); + int len = (platform.getZztWorldFormat().isZZTLike() ? 33 : 25); if (boundStatId == 0 && data != null) { byte[] dataBytes = data.getBytes(StandardCharsets.ISO_8859_1); len += dataBytes.length; @@ -155,7 +155,7 @@ public void writeZ(ZOutputStream stream, Platform platform) throws IOException { stream.pad(4); // data^ stream.writePShort(this.dataPos); stream.writePShort(boundStatId > 0 ? (-boundStatId) : ((dataBytes != null) ? dataBytes.length : 0)); - if (platform == Platform.ZZT) { + if (platform.getZztWorldFormat().isZZTLike()) { stream.pad(8); // unk } if (boundStatId == 0 && dataBytes != null) { diff --git a/src/main/java/pl/asie/libzzt/World.java b/src/main/java/pl/asie/libzzt/World.java index c02a503..c8c9d68 100644 --- a/src/main/java/pl/asie/libzzt/World.java +++ b/src/main/java/pl/asie/libzzt/World.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +// TODO: Super ZZT world (de)serialization @Data public class World { private static final int VERSION = -1; diff --git a/src/main/java/pl/asie/libzzt/ZztWorldSerializationFormat.java b/src/main/java/pl/asie/libzzt/ZztWorldSerializationFormat.java new file mode 100644 index 0000000..b4c4969 --- /dev/null +++ b/src/main/java/pl/asie/libzzt/ZztWorldSerializationFormat.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2020, 2021, 2022 Adrian Siekierka + * + * This file is part of zima. + * + * zima is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * zima is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with zima. If not, see . + */ +package pl.asie.libzzt; + +public enum ZztWorldSerializationFormat { + ZZT, + SUPER_ZZT; + + public boolean isZZTLike() { + return this == ZZT; + } + + public boolean isSuperZZTLike() { + return this == SUPER_ZZT; + } +}