Skip to content

Commit 5a7d70d

Browse files
committed
Put IDs in plain text with a \0 separator, and fix up some issues with not deleting files.
1 parent f559779 commit 5a7d70d

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

src/main/java/name/ipsi/project/fwbp/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void writeIds() throws IOException {
9595
var outputFile = Path.of("src", "main", "resources", "id-list.txt");
9696
if (Files.exists(outputFile)) {
9797
var fileContents = ids.entrySet().stream()
98-
.map(e -> String.format("%s,%s", e.getKey(), e.getValue()))
98+
.map(e -> String.format("%s\0%s", e.getKey(), e.getValue()))
9999
.collect(Collectors.joining("\n"));
100100
Files.writeString(outputFile, fileContents, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
101101
} else {

src/main/java/name/ipsi/project/fwbp/books/werewolf/Werewolf20Extractor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ private void processRites() {
625625
}
626626
}
627627

628-
entries.add(new Rite(rite.name(), rite.type(), rite.level(), rite.type().rollData(), description, system));
628+
entries.add(new Rite(fixText(rite.name()), rite.type(), rite.level(), rite.type().rollData(), description, system));
629629
}
630630
}
631631

@@ -657,7 +657,7 @@ private void processFetishes() {
657657
}
658658

659659
entries.add(new Fetish(
660-
fetish.name(),
660+
fixText(fetish.name()),
661661
fetish.level(),
662662
fetish.gnosis(),
663663
description
@@ -678,14 +678,21 @@ private void processTalens() {
678678
}
679679

680680
entries.add(new Talen(
681-
talen.name(),
681+
fixText(talen.name()),
682682
talen.gnosis(),
683683
description
684684
));
685685
}
686686
}
687687

688-
private record Data(String name, int cost, int max, boolean merit) {}
688+
private record Data(String name, int cost, int max, boolean merit) {
689+
private Data(String name, int cost, int max, boolean merit) {
690+
this.name = fixText(name);
691+
this.cost = cost;
692+
this.max = max;
693+
this.merit = merit;
694+
}
695+
}
689696

690697
private void processMeritsAndFlaws() {
691698
List<String> sectionHeaders = new ArrayList<>();

src/main/java/name/ipsi/project/fwbp/foundry/core/FoundryUtils.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import java.io.IOException;
88
import java.io.InputStreamReader;
99
import java.nio.charset.StandardCharsets;
10-
import java.security.MessageDigest;
11-
import java.security.NoSuchAlgorithmException;
12-
import java.util.*;
10+
import java.util.Collections;
11+
import java.util.Map;
12+
import java.util.Random;
13+
import java.util.TreeMap;
1314
import java.util.stream.Collectors;
1415

1516
public class FoundryUtils {
@@ -26,9 +27,9 @@ public class FoundryUtils {
2627
}
2728
try (var reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
2829
for (var line = reader.readLine(); line != null; line = reader.readLine()) {
29-
var parts = line.split(",");
30+
var parts = line.split("\0");
3031
if (parts.length != 2) {
31-
throw new RuntimeException("Expected ID file line [" + line + "] to match format <id>,<hash>");
32+
throw new RuntimeException("Expected ID file line [" + line + "] to match format <key>\0<id>");
3233
}
3334
ids.put(parts[0], parts[1]);
3435
}
@@ -38,31 +39,20 @@ public class FoundryUtils {
3839
}
3940

4041
public static String generateId(String group, String name) {
41-
var toHash = String.format("%s:%s", group, name);
42-
var hash = generateHash(toHash);
43-
if (ids.containsKey(hash)) {
44-
return ids.get(hash);
42+
var key = String.format("%s:%s", group, name);
43+
if (ids.containsKey(key)) {
44+
return ids.get(key);
4545
} else {
46-
log.warn("No existing ID found for [{}] - generating new", toHash);
46+
log.warn("No existing ID found for [{}] - generating new", key);
4747
var r = new Random();
4848
var id = r.ints(16, 0, 36)
4949
.mapToObj(i -> Integer.toString(i, 36))
5050
.collect(Collectors.joining(""));
51-
ids.put(hash, id);
51+
ids.put(key, id);
5252
return id;
5353
}
5454
}
5555

56-
private static String generateHash(String toHash) {
57-
try {
58-
var hasher = MessageDigest.getInstance("SHA512");
59-
var hash = hasher.digest(toHash.getBytes(StandardCharsets.UTF_8));
60-
return Base64.getEncoder().encodeToString(hash);
61-
} catch (NoSuchAlgorithmException e) {
62-
throw new RuntimeException(e);
63-
}
64-
}
65-
6656
public static Map<String, String> getIds() {
6757
return Collections.unmodifiableMap(ids);
6858
}

src/main/java/name/ipsi/project/fwbp/foundry/core/ModuleGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ private ModulePack createPack(String label, String packName, DocumentTypes type,
133133
var packFile = outputPath.resolve(path);
134134
log.trace("Creating pack {}, {}, {} at {}", label, packName, type, packFile);
135135

136-
Files.createFile(packFile);
136+
if (!Files.exists(packFile)) {
137+
Files.createFile(packFile);
138+
}
139+
137140
foundryDocuments.forEach(doc -> {
138141
try {
139142
log.trace("Writing document to pack file");

src/main/resources/id-list.txt

-51 KB
Binary file not shown.

src/test/java/name/ipsi/project/fwbp/MainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
3939
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "module.json"), "96947f364f029a8b6eb0629bdb8d167829254ae3215775ccb34b2f2613ff56ca8dc3786193a970c41c01787d2746415ba59a572803285a5d3d53556b4fefb39a");
4040
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "w20.css"), "2debd674fb547d898a6cfc8addefa1e22cacde66938df545de2937c23715b39ecc4185818845ad2318c98dba0514e476d23377d80ba9fd450be4e0addf550cad");
4141
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "w20.js"), "01d4f461c7e84a173e206815cd9e48ceef1606c954c189f85e0d293657ac9393beb42faab59711f374733ab3b6c5bca6cebf63aed5d767c574e8e6e0d325d363");
42-
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "packs", "w20.db"), "432758b98d4b1327031629c374b421c73ef643c12137315a5759454192bdd8f09d4b1d50be7cb5b3863c67e958edb85a2d45b99ac6beaf57b4b97ec905ecdcfb");
42+
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "packs", "w20.db"), "bac277ffd66f179cf422320c84ce686a25b5960ff5771f0499f58854979ba77fee22cc73bde97a11a43df53de641f6cdf5a7485989eb5c9b03aa12fdccc05414");
4343
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "images", "adventure-cover.jpeg"), "17d71cdd62f4c930b803fbcf1fab02a3d0244eb7fa1d4359ab088381b1288f1bb191117ec60d3075528732ff9ce4888545e6b66b0d681b00b68b79a214daee1c");
4444
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "images", "black-furies-splash.jpeg"), "0c2f71fba6238336509d84672af71bee9344c477e0696ddd2f4dcf7d53193a1df4726f59f78135d653411f9e44dddbb08f54c65cb552a3ae3ce358dc1e2a4dea");
4545
expectedFiles.put(Path.of("modules", "wod-werewolf-20-core", "images", "black-spiral-dancers-splash.jpeg"), "10c193572ee8f878ce800f3e4bd6db12e3971714f9f69bda1ca15ee8edb64b9540f6638aacefdafdeef07d7027dc9c6f44d0423ca9c75caa492bcc752feaa372");

0 commit comments

Comments
 (0)