Skip to content

Commit

Permalink
zima 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Feb 9, 2022
1 parent 2476f33 commit a8b219e
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 282 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'pl.asie.zima'
version '0.8.0'
version '0.8.1'

repositories {
mavenCentral()
Expand Down
13 changes: 13 additions & 0 deletions docs/changelog/0.8.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Improvements:

* [#11] Warning before overwriting an already saved file.
* Coarse dither-enabled conversion is now multithreaded! Expect much faster performance.
* Super ClassicZoo profile added; for now it's just the Super ZZT profile with an increased board size limit.
* As ZZT 3.2 can't generate a Zima board above the 20000-byte limit, a ClassicZoo option is not necessary for now.
* WeaveZZT's other.maxstats setting is now respected.
* WeaveZZT's theme.blinking setting is now respected.
* WeaveZZT's pal.* settings are now respected.

Bugs fixed:

* Fixed performance regression from zima 0.6.0 in MegaZeux conversion mode.
1 change: 1 addition & 0 deletions docs/changelog/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
0.6.0
0.7.0
0.8.0
0.8.1
152 changes: 0 additions & 152 deletions src/main/java/pl/asie/libzzt/ElementLibraryWeaveZZT.java

This file was deleted.

5 changes: 4 additions & 1 deletion src/main/java/pl/asie/libzzt/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class Platform {

public static final Platform ZZT;
public static final Platform SUPER_ZZT;
public static final Platform SUPER_CLASSICZOO;
public static final Platform WEAVE_ZZT_25;
public static final Platform MEGAZEUX;

Expand All @@ -75,10 +76,12 @@ 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();
MEGAZEUX = Platform.builder().usesBoard(false).boardWidth(65535).boardHeight(65535).defaultBoardWidth(80).defaultBoardHeight(25).supportsBlinking(false).library(ElementLibraryNull.INSTANCE).build();

try {
WEAVE_ZZT_25 = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(65500 + 2).maxStatCount(254).library(ElementLibraryWeaveZZT.create(ElementLibraryZZT.INSTANCE, null)).build();
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();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
194 changes: 194 additions & 0 deletions src/main/java/pl/asie/libzzt/WeaveZZTPlatformData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*/
package pl.asie.libzzt;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.AllArgsConstructor;
import lombok.Getter;
import pl.asie.zima.Constants;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public class WeaveZZTPlatformData {
private static final BiMap<String, String> INTERNAL_TO_WEAVE = HashBiMap.create(Map.ofEntries(
Map.entry("BOARD_EDGE", "EDGE"),
Map.entry("MESSAGE_TIMER", "DARKNESS"),
Map.entry("BLINK_RAY_EW", "BLINKEW"),
Map.entry("BLINK_RAY_NS", "BLINKNS"),
Map.entry("UNKNOWN_46", "CUSTOMTEXT"),
Map.entry("TEXT_BLUE", "BLUETEXT"),
Map.entry("TEXT_GREEN", "GREENTEXT"),
Map.entry("TEXT_CYAN", "CYANTEXT"),
Map.entry("TEXT_RED", "REDTEXT"),
Map.entry("TEXT_PURPLE", "PURPLETEXT"),
Map.entry("TEXT_YELLOW", "YELLOWTEXT"),
Map.entry("TEXT_WHITE", "WHITETEXT")
));

private static final Map<String, Integer> COLOR_NUMBERS = Map.ofEntries(
Map.entry("BLACK", 0),
Map.entry("DKBLUE", 1),
Map.entry("DKGREEN", 2),
Map.entry("DKCYAN", 3),
Map.entry("DKRED", 4),
Map.entry("DKPURPLE", 5),
Map.entry("BROWN", 6),
Map.entry("GRAY", 7),
Map.entry("GREY", 7),
Map.entry("DKGRAY", 8),
Map.entry("DKGREY", 8),
Map.entry("BLUE", 9),
Map.entry("GREEN", 10),
Map.entry("CYAN", 11),
Map.entry("RED", 12),
Map.entry("PURPLE", 13),
Map.entry("YELLOW", 14),
Map.entry("WHITE", 15)
);

private final int[] palette;
private final int maxStatCount;
private final boolean blinkingDisabled;
private final ElementLibrary library;

public static WeaveZZTPlatformData parse(ElementLibrary base, InputStream is) throws IOException {
List<Element> elements = new ArrayList<>(base.getElements());
List<String> names = elements.stream().map(base::getInternalName).collect(Collectors.toList());
List<String> weaveNames = names.stream().map(e -> INTERNAL_TO_WEAVE.getOrDefault(e, e)).collect(Collectors.toList());
int[] palette = Arrays.copyOf(Constants.EGA_PALETTE, 16);
boolean blinkingDisabled = false;
boolean paletteModified = false;
int maxStatCount = 150;

// Weave ZZT default patches
{
int customTextIdx = weaveNames.indexOf("CUSTOMTEXT");
if (customTextIdx >= 0) {
elements.set(customTextIdx, elements.get(customTextIdx).withTextColor(0));
}
}

// File patches
if (is != null) try (InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
String s = line.strip();
if (s.length() > 1 && s.charAt(0) != '#') {
String[] keyValue = s.split("=", 2);
if (keyValue.length == 2) {
String keyFull = keyValue[0].replaceAll("[^.A-Za-z]", "");
String value = keyValue[1].replaceAll("[^-.A-Za-z0-9]", "");
Integer valueNum = COLOR_NUMBERS.get(value.toUpperCase(Locale.ROOT));
if (valueNum == null) {
try {
valueNum = Integer.parseInt(value);
} catch (NumberFormatException e) {
// pass
}
}
if ("other.maxstats".equalsIgnoreCase(keyFull)) {
if (valueNum != null) {
maxStatCount = valueNum;
}
continue;
} else if ("theme.blinking".equalsIgnoreCase(keyFull)) {
if (valueNum != null) {
blinkingDisabled = valueNum != 0;
}
}
String[] key = keyFull.split("\\.");
if (key.length == 2) {
if ("pal".equalsIgnoreCase(key[0])) {
Integer palIdx = COLOR_NUMBERS.get(key[1].toUpperCase(Locale.ROOT));
if (palIdx == null) {
try {
palIdx = Integer.parseInt(key[1]);
} catch (NumberFormatException e) {
// pass
}
}
String[] palValues = keyValue[1].replaceAll("[^,A-Za-z0-9]", "").split(",");
if (palValues.length == 3 && palIdx != null) {
try {
int red = (Integer.parseInt(palValues[0]) * 255 / 63) & 0xFF;
int green = (Integer.parseInt(palValues[1]) * 255 / 63) & 0xFF;
int blue = (Integer.parseInt(palValues[2]) * 255 / 63) & 0xFF;
System.out.println("Modifying color " + palIdx + " => " + red + ", " + green + ", " + blue);
palette[palIdx] = (red << 16) | (green << 8) | blue;
paletteModified = true;
} catch (NumberFormatException e) {
// pass
}
}
}
int elementIdx = weaveNames.indexOf(key[0].toUpperCase(Locale.ROOT));
if (elementIdx >= 0 && valueNum != null) {
System.out.println("Modifying " + names.get(elementIdx) + " -> " + key[1]);
Element element = elements.get(elementIdx);
if ("CHAR".equalsIgnoreCase(key[1])) {
element = element.withCharacter(valueNum & 0xFF);
} else if ("FG".equalsIgnoreCase(key[1])) {
if (element.isText()) {
element = element.withTextColor((element.getTextColor() & 0xF0) | (valueNum & 0x0F));
} else {
element = element.withColor((element.getColor() & 0xF0) | (valueNum & 0x0F));
}
} else if ("BG".equalsIgnoreCase(key[1])) {
if (element.isText()) {
element = element.withTextColor((element.getTextColor() & 0x0F) | ((valueNum & 0x0F) << 4));
} else {
element = element.withColor((element.getColor() & 0x0F) | ((valueNum & 0x0F) << 4));
}
} else if ("DESTRUCTIBLE".equalsIgnoreCase(key[1])) {
element = element.withDestructible(value.equalsIgnoreCase("TRUE"));
} else if ("PUSHABLE".equalsIgnoreCase(key[1])) {
element = element.withPushable(value.equalsIgnoreCase("TRUE"));
} else if ("PLACEABLEONTOP".equalsIgnoreCase(key[1])) {
element = element.withPlaceableOnTop(value.equalsIgnoreCase("TRUE"));
} else if ("WALKABLE".equalsIgnoreCase(key[1])) {
element = element.withWalkable(value.equalsIgnoreCase("TRUE"));
} else if ("CYCLE".equalsIgnoreCase(key[1])) {
element = element.withCycle(valueNum);
} else if ("SCOREVALUE".equalsIgnoreCase(key[1])) {
element = element.withScoreValue(valueNum);
}
// Missing: PARAM1, PARAM2, PARAM3
elements.set(elementIdx, element);
}
}
}
}
}
}

return new WeaveZZTPlatformData(paletteModified ? palette : null, maxStatCount, blinkingDisabled, new ElementLibrary(names, elements));
}
}
Loading

0 comments on commit a8b219e

Please sign in to comment.