implements PR-35
This commit is contained in:
+86
-2
@@ -9,6 +9,8 @@ import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
import p.packer.models.*;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@@ -68,20 +70,102 @@ final class PackerRuntimeAssetMaterializerTest {
|
||||
assertTrue(walker.lastPriorAssetCache().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeDefaultProjectionSuppressesContentBytes() throws Exception {
|
||||
final var materializer = new PackerRuntimeAssetMaterializer(new PackerAssetWalker(MAPPER));
|
||||
final Path assetRoot = Files.createDirectories(tempDir.resolve("runtime-default"));
|
||||
final Path manifestPath = assetRoot.resolve("asset.json");
|
||||
Files.writeString(manifestPath, "{}");
|
||||
writeTile(assetRoot.resolve("selected.png"), 16);
|
||||
writeTile(assetRoot.resolve("extra.png"), 16);
|
||||
|
||||
final PackerAssetDeclaration declaration = declaration(
|
||||
Map.of("tile_size", "16x16"),
|
||||
List.of(new PackerAssetArtifactSelection("selected.png", 0)),
|
||||
palettePipeline());
|
||||
final var materialized = materializer.materialize(
|
||||
assetRoot,
|
||||
manifestPath,
|
||||
Optional.of(new PackerRegistryEntry(1, "uuid", "asset", true)),
|
||||
new PackerAssetDeclarationParseResult(declaration, List.of()),
|
||||
Optional.empty());
|
||||
|
||||
assertEquals(2, materialized.runtimeAsset().walkProjection().buildCandidateFiles().size());
|
||||
assertTrue(materialized.runtimeAsset().walkProjection().buildCandidateFiles().stream()
|
||||
.allMatch(file -> file.contentBytes().isEmpty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void packingProjectionKeepsSelectedFilesAndInjectsContentBytes() throws Exception {
|
||||
final var materializer = new PackerRuntimeAssetMaterializer(new PackerAssetWalker(MAPPER));
|
||||
final Path assetRoot = Files.createDirectories(tempDir.resolve("packing"));
|
||||
final Path manifestPath = assetRoot.resolve("asset.json");
|
||||
Files.writeString(manifestPath, "{}");
|
||||
writeTile(assetRoot.resolve("selected.png"), 16);
|
||||
writeTile(assetRoot.resolve("extra.png"), 16);
|
||||
|
||||
final PackerAssetDeclaration declaration = declaration(
|
||||
Map.of("tile_size", "16x16"),
|
||||
List.of(new PackerAssetArtifactSelection("selected.png", 0)),
|
||||
palettePipeline());
|
||||
final var materialized = materializer.materialize(
|
||||
assetRoot,
|
||||
manifestPath,
|
||||
Optional.of(new PackerRegistryEntry(1, "uuid", "asset", true)),
|
||||
new PackerAssetDeclarationParseResult(declaration, List.of()),
|
||||
Optional.empty(),
|
||||
PackerRuntimeMaterializationConfig.packingBuild());
|
||||
|
||||
assertEquals(1, materialized.runtimeAsset().walkProjection().buildCandidateFiles().size());
|
||||
final var file = materialized.runtimeAsset().walkProjection().buildCandidateFiles().getFirst();
|
||||
assertEquals("selected.png", file.relativePath());
|
||||
assertTrue(file.contentBytes().isPresent());
|
||||
assertTrue(file.contentBytes().get().length > 0);
|
||||
}
|
||||
|
||||
private static PackerAssetDeclaration declaration(Map<String, String> metadata) {
|
||||
return declaration(metadata, List.of(), Map.of());
|
||||
}
|
||||
|
||||
private static PackerAssetDeclaration declaration(
|
||||
Map<String, String> metadata,
|
||||
List<PackerAssetArtifactSelection> artifacts,
|
||||
Map<String, JsonNode> pipelineMetadata) {
|
||||
return new PackerAssetDeclaration(
|
||||
1,
|
||||
"uuid",
|
||||
"asset",
|
||||
AssetFamilyCatalog.TILE_BANK,
|
||||
List.of(),
|
||||
artifacts,
|
||||
OutputFormatCatalog.TILES_INDEXED_V1,
|
||||
OutputCodecCatalog.NONE,
|
||||
metadata,
|
||||
Map.<String, JsonNode>of(),
|
||||
pipelineMetadata,
|
||||
true);
|
||||
}
|
||||
|
||||
private static Map<String, JsonNode> palettePipeline() {
|
||||
final var payload = MAPPER.createObjectNode();
|
||||
payload.putArray("originalArgb8888").add(0xFFFF0000);
|
||||
payload.putArray("convertedRgb565").add(0xF800);
|
||||
final var declaration = MAPPER.createObjectNode();
|
||||
declaration.put("index", 0);
|
||||
declaration.set("palette", payload);
|
||||
final var palettes = MAPPER.createArrayNode();
|
||||
palettes.add(declaration);
|
||||
return Map.of("palettes", palettes);
|
||||
}
|
||||
|
||||
private static void writeTile(Path path, int tileSize) throws Exception {
|
||||
final BufferedImage image = new BufferedImage(tileSize, tileSize, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < tileSize; y += 1) {
|
||||
for (int x = 0; x < tileSize; x += 1) {
|
||||
image.setRGB(x, y, 0xFFFF0000);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
}
|
||||
|
||||
private static final class TrackingWalker extends PackerAssetWalker {
|
||||
private Optional<PackerAssetCacheEntry> lastPriorAssetCache = Optional.empty();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user