Skip to content

Commit a8b219e

Browse files
committed
zima 0.8.1
1 parent 2476f33 commit a8b219e

File tree

11 files changed

+450
-282
lines changed

11 files changed

+450
-282
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'pl.asie.zima'
9-
version '0.8.0'
9+
version '0.8.1'
1010

1111
repositories {
1212
mavenCentral()

docs/changelog/0.8.1.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Improvements:
2+
3+
* [#11] Warning before overwriting an already saved file.
4+
* Coarse dither-enabled conversion is now multithreaded! Expect much faster performance.
5+
* Super ClassicZoo profile added; for now it's just the Super ZZT profile with an increased board size limit.
6+
* As ZZT 3.2 can't generate a Zima board above the 20000-byte limit, a ClassicZoo option is not necessary for now.
7+
* WeaveZZT's other.maxstats setting is now respected.
8+
* WeaveZZT's theme.blinking setting is now respected.
9+
* WeaveZZT's pal.* settings are now respected.
10+
11+
Bugs fixed:
12+
13+
* Fixed performance regression from zima 0.6.0 in MegaZeux conversion mode.

docs/changelog/versions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
0.6.0
1010
0.7.0
1111
0.8.0
12+
0.8.1

src/main/java/pl/asie/libzzt/ElementLibraryWeaveZZT.java

Lines changed: 0 additions & 152 deletions
This file was deleted.

src/main/java/pl/asie/libzzt/Platform.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class Platform {
5353

5454
public static final Platform ZZT;
5555
public static final Platform SUPER_ZZT;
56+
public static final Platform SUPER_CLASSICZOO;
5657
public static final Platform WEAVE_ZZT_25;
5758
public static final Platform MEGAZEUX;
5859

@@ -75,10 +76,12 @@ public boolean isDoubleWide(TextVisualData visual) {
7576
static {
7677
ZZT = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(20000 + 2).maxStatCount(150).library(ElementLibraryZZT.INSTANCE).build();
7778
SUPER_ZZT = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(20000 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).build();
79+
SUPER_CLASSICZOO = Platform.builder().usesBoard(true).boardWidth(96).boardHeight(80).maxBoardSize(65500 + 2).maxStatCount(128).library(ElementLibrarySuperZZT.INSTANCE).doubleWide(true).build();
7880
MEGAZEUX = Platform.builder().usesBoard(false).boardWidth(65535).boardHeight(65535).defaultBoardWidth(80).defaultBoardHeight(25).supportsBlinking(false).library(ElementLibraryNull.INSTANCE).build();
7981

8082
try {
81-
WEAVE_ZZT_25 = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(65500 + 2).maxStatCount(254).library(ElementLibraryWeaveZZT.create(ElementLibraryZZT.INSTANCE, null)).build();
83+
WeaveZZTPlatformData platformData = WeaveZZTPlatformData.parse(ElementLibraryZZT.INSTANCE, null);
84+
WEAVE_ZZT_25 = Platform.builder().usesBoard(true).boardWidth(60).boardHeight(25).maxBoardSize(65500 + 2).maxStatCount(150).library(platformData.getLibrary()).build();
8285
} catch (IOException e) {
8386
throw new RuntimeException(e);
8487
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/**
2+
* Copyright (c) 2020, 2021, 2022 Adrian Siekierka
3+
*
4+
* This file is part of zima.
5+
*
6+
* zima is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* zima is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with zima. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package pl.asie.libzzt;
20+
21+
import com.google.common.collect.BiMap;
22+
import com.google.common.collect.HashBiMap;
23+
import lombok.AllArgsConstructor;
24+
import lombok.Getter;
25+
import pl.asie.zima.Constants;
26+
27+
import java.io.BufferedReader;
28+
import java.io.IOException;
29+
import java.io.InputStream;
30+
import java.io.InputStreamReader;
31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.List;
34+
import java.util.Locale;
35+
import java.util.Map;
36+
import java.util.stream.Collectors;
37+
38+
@Getter
39+
@AllArgsConstructor
40+
public class WeaveZZTPlatformData {
41+
private static final BiMap<String, String> INTERNAL_TO_WEAVE = HashBiMap.create(Map.ofEntries(
42+
Map.entry("BOARD_EDGE", "EDGE"),
43+
Map.entry("MESSAGE_TIMER", "DARKNESS"),
44+
Map.entry("BLINK_RAY_EW", "BLINKEW"),
45+
Map.entry("BLINK_RAY_NS", "BLINKNS"),
46+
Map.entry("UNKNOWN_46", "CUSTOMTEXT"),
47+
Map.entry("TEXT_BLUE", "BLUETEXT"),
48+
Map.entry("TEXT_GREEN", "GREENTEXT"),
49+
Map.entry("TEXT_CYAN", "CYANTEXT"),
50+
Map.entry("TEXT_RED", "REDTEXT"),
51+
Map.entry("TEXT_PURPLE", "PURPLETEXT"),
52+
Map.entry("TEXT_YELLOW", "YELLOWTEXT"),
53+
Map.entry("TEXT_WHITE", "WHITETEXT")
54+
));
55+
56+
private static final Map<String, Integer> COLOR_NUMBERS = Map.ofEntries(
57+
Map.entry("BLACK", 0),
58+
Map.entry("DKBLUE", 1),
59+
Map.entry("DKGREEN", 2),
60+
Map.entry("DKCYAN", 3),
61+
Map.entry("DKRED", 4),
62+
Map.entry("DKPURPLE", 5),
63+
Map.entry("BROWN", 6),
64+
Map.entry("GRAY", 7),
65+
Map.entry("GREY", 7),
66+
Map.entry("DKGRAY", 8),
67+
Map.entry("DKGREY", 8),
68+
Map.entry("BLUE", 9),
69+
Map.entry("GREEN", 10),
70+
Map.entry("CYAN", 11),
71+
Map.entry("RED", 12),
72+
Map.entry("PURPLE", 13),
73+
Map.entry("YELLOW", 14),
74+
Map.entry("WHITE", 15)
75+
);
76+
77+
private final int[] palette;
78+
private final int maxStatCount;
79+
private final boolean blinkingDisabled;
80+
private final ElementLibrary library;
81+
82+
public static WeaveZZTPlatformData parse(ElementLibrary base, InputStream is) throws IOException {
83+
List<Element> elements = new ArrayList<>(base.getElements());
84+
List<String> names = elements.stream().map(base::getInternalName).collect(Collectors.toList());
85+
List<String> weaveNames = names.stream().map(e -> INTERNAL_TO_WEAVE.getOrDefault(e, e)).collect(Collectors.toList());
86+
int[] palette = Arrays.copyOf(Constants.EGA_PALETTE, 16);
87+
boolean blinkingDisabled = false;
88+
boolean paletteModified = false;
89+
int maxStatCount = 150;
90+
91+
// Weave ZZT default patches
92+
{
93+
int customTextIdx = weaveNames.indexOf("CUSTOMTEXT");
94+
if (customTextIdx >= 0) {
95+
elements.set(customTextIdx, elements.get(customTextIdx).withTextColor(0));
96+
}
97+
}
98+
99+
// File patches
100+
if (is != null) try (InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr)) {
101+
String line;
102+
while ((line = reader.readLine()) != null) {
103+
String s = line.strip();
104+
if (s.length() > 1 && s.charAt(0) != '#') {
105+
String[] keyValue = s.split("=", 2);
106+
if (keyValue.length == 2) {
107+
String keyFull = keyValue[0].replaceAll("[^.A-Za-z]", "");
108+
String value = keyValue[1].replaceAll("[^-.A-Za-z0-9]", "");
109+
Integer valueNum = COLOR_NUMBERS.get(value.toUpperCase(Locale.ROOT));
110+
if (valueNum == null) {
111+
try {
112+
valueNum = Integer.parseInt(value);
113+
} catch (NumberFormatException e) {
114+
// pass
115+
}
116+
}
117+
if ("other.maxstats".equalsIgnoreCase(keyFull)) {
118+
if (valueNum != null) {
119+
maxStatCount = valueNum;
120+
}
121+
continue;
122+
} else if ("theme.blinking".equalsIgnoreCase(keyFull)) {
123+
if (valueNum != null) {
124+
blinkingDisabled = valueNum != 0;
125+
}
126+
}
127+
String[] key = keyFull.split("\\.");
128+
if (key.length == 2) {
129+
if ("pal".equalsIgnoreCase(key[0])) {
130+
Integer palIdx = COLOR_NUMBERS.get(key[1].toUpperCase(Locale.ROOT));
131+
if (palIdx == null) {
132+
try {
133+
palIdx = Integer.parseInt(key[1]);
134+
} catch (NumberFormatException e) {
135+
// pass
136+
}
137+
}
138+
String[] palValues = keyValue[1].replaceAll("[^,A-Za-z0-9]", "").split(",");
139+
if (palValues.length == 3 && palIdx != null) {
140+
try {
141+
int red = (Integer.parseInt(palValues[0]) * 255 / 63) & 0xFF;
142+
int green = (Integer.parseInt(palValues[1]) * 255 / 63) & 0xFF;
143+
int blue = (Integer.parseInt(palValues[2]) * 255 / 63) & 0xFF;
144+
System.out.println("Modifying color " + palIdx + " => " + red + ", " + green + ", " + blue);
145+
palette[palIdx] = (red << 16) | (green << 8) | blue;
146+
paletteModified = true;
147+
} catch (NumberFormatException e) {
148+
// pass
149+
}
150+
}
151+
}
152+
int elementIdx = weaveNames.indexOf(key[0].toUpperCase(Locale.ROOT));
153+
if (elementIdx >= 0 && valueNum != null) {
154+
System.out.println("Modifying " + names.get(elementIdx) + " -> " + key[1]);
155+
Element element = elements.get(elementIdx);
156+
if ("CHAR".equalsIgnoreCase(key[1])) {
157+
element = element.withCharacter(valueNum & 0xFF);
158+
} else if ("FG".equalsIgnoreCase(key[1])) {
159+
if (element.isText()) {
160+
element = element.withTextColor((element.getTextColor() & 0xF0) | (valueNum & 0x0F));
161+
} else {
162+
element = element.withColor((element.getColor() & 0xF0) | (valueNum & 0x0F));
163+
}
164+
} else if ("BG".equalsIgnoreCase(key[1])) {
165+
if (element.isText()) {
166+
element = element.withTextColor((element.getTextColor() & 0x0F) | ((valueNum & 0x0F) << 4));
167+
} else {
168+
element = element.withColor((element.getColor() & 0x0F) | ((valueNum & 0x0F) << 4));
169+
}
170+
} else if ("DESTRUCTIBLE".equalsIgnoreCase(key[1])) {
171+
element = element.withDestructible(value.equalsIgnoreCase("TRUE"));
172+
} else if ("PUSHABLE".equalsIgnoreCase(key[1])) {
173+
element = element.withPushable(value.equalsIgnoreCase("TRUE"));
174+
} else if ("PLACEABLEONTOP".equalsIgnoreCase(key[1])) {
175+
element = element.withPlaceableOnTop(value.equalsIgnoreCase("TRUE"));
176+
} else if ("WALKABLE".equalsIgnoreCase(key[1])) {
177+
element = element.withWalkable(value.equalsIgnoreCase("TRUE"));
178+
} else if ("CYCLE".equalsIgnoreCase(key[1])) {
179+
element = element.withCycle(valueNum);
180+
} else if ("SCOREVALUE".equalsIgnoreCase(key[1])) {
181+
element = element.withScoreValue(valueNum);
182+
}
183+
// Missing: PARAM1, PARAM2, PARAM3
184+
elements.set(elementIdx, element);
185+
}
186+
}
187+
}
188+
}
189+
}
190+
}
191+
192+
return new WeaveZZTPlatformData(paletteModified ? palette : null, maxStatCount, blinkingDisabled, new ElementLibrary(names, elements));
193+
}
194+
}

0 commit comments

Comments
 (0)