asset details (WIP)
This commit is contained in:
+2
@@ -1,5 +1,6 @@
|
||||
package p.packer.repositories;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -77,6 +78,7 @@ final class PackerRuntimeAssetMaterializerTest {
|
||||
OutputFormatCatalog.TILES_INDEXED_V1,
|
||||
OutputCodecCatalog.NONE,
|
||||
metadata,
|
||||
Map.<String, JsonNode>of(),
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
+67
@@ -1,6 +1,7 @@
|
||||
package p.packer.services;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.packer.events.PackerEvent;
|
||||
@@ -106,6 +107,7 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertTrue(Files.isRegularFile(projectRoot.resolve("assets/ui/new-atlas/asset.json")));
|
||||
final String manifestJson = Files.readString(projectRoot.resolve("assets/ui/new-atlas/asset.json"));
|
||||
assertTrue(manifestJson.contains("\"asset_uuid\""));
|
||||
assertTrue(manifestJson.contains("\"pipeline\""));
|
||||
|
||||
final var snapshot = service.listAssets(new ListAssetsRequest(project(projectRoot)));
|
||||
assertEquals(1, snapshot.assets().size());
|
||||
@@ -216,6 +218,33 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertEquals("mono", manifest.path("output").path("codec_configuration").path("palette").asText());
|
||||
assertEquals("16x16", manifest.path("output").path("metadata").path("tile_size").asText());
|
||||
assertEquals("1", manifest.path("output").path("metadata").path("channels").asText());
|
||||
assertTrue(manifest.path("output").path("pipeline").isMissingNode() || manifest.path("output").path("pipeline").isObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssetContractPreservesPipelineMetadataUnderOutput() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("update-contract-pipeline"));
|
||||
final Path manifestPath = projectRoot.resolve("assets/ui/atlas/asset.json");
|
||||
final ObjectNode manifest = (ObjectNode) MAPPER.readTree(manifestPath.toFile());
|
||||
final ObjectNode pipelineNode = ((ObjectNode) manifest.path("output")).putObject("pipeline");
|
||||
pipelineNode.putObject("samples").putObject("1").put("offset", 0).put("length", 64);
|
||||
pipelineNode.put("normalized", true);
|
||||
MAPPER.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
final var result = service.updateAssetContract(new UpdateAssetContractRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
false,
|
||||
OutputCodecCatalog.NONE,
|
||||
Map.of("NONE:packMode", "tight"),
|
||||
Map.of("tile_size", "16x16")));
|
||||
|
||||
assertTrue(result.success());
|
||||
|
||||
final var updatedManifest = MAPPER.readTree(manifestPath.toFile());
|
||||
assertTrue(updatedManifest.path("output").path("pipeline").path("normalized").asBoolean());
|
||||
assertEquals(64, updatedManifest.path("output").path("pipeline").path("samples").path("1").path("length").asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -345,6 +374,44 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertEquals(1, loader.loadCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyPaletteOverhaulingWritesPipelinePalettesInOrder() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("apply-palette-overhauling"));
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
final var response = service.applyPaletteOverhauling(new ApplyPaletteOverhaulingRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of(
|
||||
Map.of(
|
||||
"originalArgb8888", List.of(0xFFFF0000, 0xFF00FF00),
|
||||
"convertedRgb565", List.of(0xF800, 0x07E0)),
|
||||
Map.of(
|
||||
"originalArgb8888", List.of(0xFF0000FF),
|
||||
"convertedRgb565", List.of(0x001F)))));
|
||||
|
||||
assertTrue(response.success());
|
||||
|
||||
final var manifest = MAPPER.readTree(projectRoot.resolve("assets/ui/atlas/asset.json").toFile());
|
||||
assertEquals(2, manifest.path("output").path("pipeline").path("palettes").size());
|
||||
assertEquals(0xFFFF0000, manifest.path("output").path("pipeline").path("palettes").get(0).path("originalArgb8888").get(0).asInt());
|
||||
assertEquals(0x001F, manifest.path("output").path("pipeline").path("palettes").get(1).path("convertedRgb565").get(0).asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyPaletteOverhaulingFailsWhenSelectionIsEmpty() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("apply-palette-overhauling-empty"));
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
final var response = service.applyPaletteOverhauling(new ApplyPaletteOverhaulingRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of()));
|
||||
|
||||
assertFalse(response.success());
|
||||
assertTrue(response.errorMessage().contains("At least one palette"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deepSyncPreservesContractDrivenBankInvalidationAfterPatchUpdate() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("deep-sync-bank-composition"));
|
||||
|
||||
+57
@@ -10,6 +10,7 @@ import p.packer.testing.PackerFixtureLocator;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -31,9 +32,65 @@ final class PackerAssetDeclarationParserTest {
|
||||
assertEquals(AssetFamilyCatalog.TILE_BANK, result.declaration().assetFamily());
|
||||
assertEquals("TILES/indexed_v1", result.declaration().outputFormat().displayName());
|
||||
assertEquals(OutputCodecCatalog.NONE, result.declaration().outputCodec());
|
||||
assertEquals(Map.of(), result.declaration().outputPipelineMetadata());
|
||||
assertTrue(result.declaration().preloadEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesPipelineMetadataAsDedicatedOutputObject() throws Exception {
|
||||
final Path manifest = tempDir.resolve("asset.json");
|
||||
Files.writeString(manifest, """
|
||||
{
|
||||
"schema_version": 1,
|
||||
"asset_uuid": "uuid-pipeline",
|
||||
"name": "pipeline_asset",
|
||||
"type": "sound_bank",
|
||||
"output": {
|
||||
"format": "SOUND/v1",
|
||||
"codec": "NONE",
|
||||
"pipeline": {
|
||||
"samples": {
|
||||
"1": { "offset": 0, "length": 128 }
|
||||
},
|
||||
"normalized": true
|
||||
}
|
||||
},
|
||||
"preload": { "enabled": true }
|
||||
}
|
||||
""");
|
||||
|
||||
final var result = parser.parse(manifest);
|
||||
|
||||
assertTrue(result.valid());
|
||||
assertEquals(2, result.declaration().outputPipelineMetadata().size());
|
||||
assertTrue(result.declaration().outputPipelineMetadata().get("normalized").asBoolean());
|
||||
assertEquals(128, result.declaration().outputPipelineMetadata().get("samples").path("1").path("length").asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsNonObjectPipelineMetadata() throws Exception {
|
||||
final Path manifest = tempDir.resolve("asset.json");
|
||||
Files.writeString(manifest, """
|
||||
{
|
||||
"schema_version": 1,
|
||||
"asset_uuid": "uuid-pipeline",
|
||||
"name": "pipeline_asset",
|
||||
"type": "tile_bank",
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "NONE",
|
||||
"pipeline": []
|
||||
},
|
||||
"preload": { "enabled": true }
|
||||
}
|
||||
""");
|
||||
|
||||
final var result = parser.parse(manifest);
|
||||
|
||||
assertFalse(result.valid());
|
||||
assertTrue(result.diagnostics().stream().anyMatch(diagnostic -> diagnostic.message().contains("output.pipeline")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsMalformedJsonWithStructuralDiagnostic() {
|
||||
final var result = parser.parse(PackerFixtureLocator.fixtureRoot("workspaces/invalid-malformed/assets/bad/asset.json"));
|
||||
|
||||
+25
@@ -49,10 +49,35 @@ final class PackerAssetDetailsServiceTest {
|
||||
assertEquals(List.of(), result.details().codecConfigurationFieldsByCodec().get(OutputCodecCatalog.NONE));
|
||||
assertNotNull(result.details().bankComposition());
|
||||
assertTrue(result.details().bankComposition().selectedFiles().isEmpty());
|
||||
assertTrue(result.details().pipelinePalettes().isEmpty());
|
||||
assertTrue(result.diagnostics().stream().noneMatch(diagnostic -> diagnostic.blocking()));
|
||||
assertTrue(result.diagnostics().stream().anyMatch(diagnostic -> diagnostic.message().contains("Output metadata for tile bank cannot be empty")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposesPipelinePalettesFromOutputPipelineMetadata() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("managed-pipeline-palettes"));
|
||||
final Path manifestPath = projectRoot.resolve("assets/ui/atlas/asset.json");
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final ObjectNode manifest = (ObjectNode) mapper.readTree(manifestPath.toFile());
|
||||
final ObjectNode pipeline = ((ObjectNode) manifest.path("output")).putObject("pipeline");
|
||||
final var palettes = pipeline.putArray("palettes");
|
||||
palettes.addObject()
|
||||
.putArray("originalArgb8888").add(0xFFFF0000).add(0xFF00FF00);
|
||||
((ObjectNode) palettes.get(0))
|
||||
.putArray("convertedRgb565").add(0xF800).add(0x07E0);
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
|
||||
final PackerAssetDetailsService service = service();
|
||||
final var result = service.getAssetDetails(new GetAssetDetailsRequest(project(projectRoot), AssetReference.forAssetId(1)));
|
||||
|
||||
assertEquals(1, result.details().pipelinePalettes().size());
|
||||
assertEquals(
|
||||
List.of(0xFFFF0000, 0xFF00FF00),
|
||||
result.details().pipelinePalettes().getFirst().get("originalArgb8888"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void projectsBankCompositionAvailableAndSelectedFiles() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("managed-bank-composition"));
|
||||
|
||||
Reference in New Issue
Block a user