Add subtle pixel shading to combined soup bowls
This commit is contained in:
@@ -2,10 +2,17 @@ package online.astradev.cauldron;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/** Export before AstraPlus's startup pack build; never overwrite administrator resources. */
|
||||
/** Export before AstraPlus's startup pack build; upgrade only known, unmodified defaults. */
|
||||
final class SoupResources {
|
||||
// Bundled flat-colour model in 0.2.0–0.2.3, with normalized newlines and outer whitespace.
|
||||
private static final String FLAT_MODEL_SHA256 =
|
||||
"51b5c2b0561ec815e5ddaff5654ce04fffa0995fc3e5972323f385d58842cd2c";
|
||||
private SoupResources() {}
|
||||
static void install(Path root) throws IOException {
|
||||
for (String name : List.of("items/combined_soup.json",
|
||||
@@ -13,11 +20,27 @@ final class SoupResources {
|
||||
String relative = "assets/astradev_soups/" + name;
|
||||
Path target = root.resolve("astraplus/resources").resolve(relative);
|
||||
Files.createDirectories(target.getParent());
|
||||
if (Files.exists(target)) continue;
|
||||
boolean exists = Files.exists(target, LinkOption.NOFOLLOW_LINKS);
|
||||
if (exists && !(name.equals("models/item/soup_liquid.json") && isFlatDefault(target))) continue;
|
||||
try (var input = SoupResources.class.getResourceAsStream("/astra-resources/" + relative)) {
|
||||
if (input == null) throw new IOException("Missing resource " + relative);
|
||||
Files.copy(input, target);
|
||||
if (!exists) Files.copy(input, target);
|
||||
else {
|
||||
Path temp = Files.createTempFile(target.getParent(), "soup-model-", ".tmp");
|
||||
try {
|
||||
Files.copy(input, temp, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.move(temp, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally { Files.deleteIfExists(temp); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static boolean isFlatDefault(Path path) throws IOException {
|
||||
if (!Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.size(path) > 8192) return false;
|
||||
String model = Files.readString(path, UTF_8).replace("\r\n", "\n").trim();
|
||||
try {
|
||||
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256")
|
||||
.digest(model.getBytes(UTF_8))).equals(FLAT_MODEL_SHA256);
|
||||
} catch (NoSuchAlgorithmException impossible) { throw new AssertionError(impossible); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user