Tiled Parser and Scene & Palette Management in Studio
This commit is contained in:
+2
-2
@@ -81,7 +81,7 @@ final class PackerRuntimeAssetMaterializerTest {
|
||||
|
||||
final PackerAssetDeclaration declaration = declaration(
|
||||
Map.of("tile_size", "16x16"),
|
||||
List.of(new PackerAssetArtifactSelection("selected.png", 0)),
|
||||
List.of(new PackerAssetArtifactSelection(null, "selected.png", 0, null)),
|
||||
palettePipeline());
|
||||
final var materialized = materializer.materialize(
|
||||
assetRoot,
|
||||
@@ -106,7 +106,7 @@ final class PackerRuntimeAssetMaterializerTest {
|
||||
|
||||
final PackerAssetDeclaration declaration = declaration(
|
||||
Map.of("tile_size", "16x16"),
|
||||
List.of(new PackerAssetArtifactSelection("selected.png", 0)),
|
||||
List.of(new PackerAssetArtifactSelection(null, "selected.png", 0, null)),
|
||||
palettePipeline());
|
||||
final var materialized = materializer.materialize(
|
||||
assetRoot,
|
||||
|
||||
+189
-4
@@ -533,8 +533,11 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
final var supportFile = MAPPER.readTree(assetRoot.resolve("scene-bank.studio.json").toFile());
|
||||
assertEquals(16, supportFile.path("map_width").asInt());
|
||||
assertEquals(16, supportFile.path("map_height").asInt());
|
||||
assertEquals(1, supportFile.path("layer_count").asInt());
|
||||
assertEquals(4, supportFile.path("layer_count").asInt());
|
||||
assertEquals(false, supportFile.path("layers").get(0).path("enabled").asBoolean());
|
||||
assertEquals("Layer 1", supportFile.path("layers").get(0).path("name").asText());
|
||||
assertEquals(16, supportFile.path("layers").get(0).path("width").asInt());
|
||||
assertEquals(16, supportFile.path("layers").get(0).path("height").asInt());
|
||||
assertEquals("layer-1.tmx", supportFile.path("layers").get(0).path("tilemap").asText());
|
||||
}
|
||||
|
||||
@@ -722,6 +725,31 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertFalse(registry.path("assets").get(0).path("included_in_build").asBoolean(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssetBuildParticipationBlocksSceneBankWithoutEnabledLayers() throws Exception {
|
||||
final Path projectRoot = tempDir.resolve("update-build-participation-scene");
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
final CreateAssetResult createResult = service.createAsset(new CreateAssetRequest(
|
||||
project(projectRoot),
|
||||
"scenes/overworld",
|
||||
"overworld",
|
||||
AssetFamilyCatalog.SCENE_BANK,
|
||||
OutputFormatCatalog.SCENE_TILED_V1,
|
||||
OutputCodecCatalog.NONE,
|
||||
false));
|
||||
|
||||
assertEquals(PackerOperationStatus.SUCCESS, createResult.status());
|
||||
|
||||
final var result = service.updateAssetBuildParticipation(new UpdateAssetBuildParticipationRequest(
|
||||
project(projectRoot),
|
||||
createResult.assetReference(),
|
||||
true));
|
||||
|
||||
assertEquals(PackerOperationStatus.FAILED, result.status());
|
||||
assertTrue(result.summary().contains("enable at least one layer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssetContractDropsPersistedBankCompositionWhenContractFingerprintChanges() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("update-contract-drops-bank"));
|
||||
@@ -760,8 +788,8 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
void applyBankCompositionWritesArtifactsAndRefreshesSnapshotWithoutWholeProjectReload() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("apply-bank-composition"));
|
||||
final Path assetRoot = projectRoot.resolve("assets/ui/atlas");
|
||||
Files.writeString(assetRoot.resolve("confirm.png"), "fixture");
|
||||
Files.writeString(assetRoot.resolve("cancel.png"), "fixture");
|
||||
writeTilePng(assetRoot.resolve("confirm.png"), 16);
|
||||
writeTilePng(assetRoot.resolve("cancel.png"), 16);
|
||||
final CountingLoader loader = countingLoader();
|
||||
final FileSystemPackerWorkspaceService service = service(ignored -> { }, loader);
|
||||
|
||||
@@ -779,10 +807,14 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
|
||||
final var manifest = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
assertTrue(manifest.path("inputs").isMissingNode());
|
||||
assertTrue(manifest.path("artifacts").get(0).hasNonNull("artifact_id"));
|
||||
assertEquals("cancel.png", manifest.path("artifacts").get(0).path("file").asText());
|
||||
assertEquals(0, manifest.path("artifacts").get(0).path("index").asInt());
|
||||
assertTrue(manifest.path("artifacts").get(0).hasNonNull("fingerprint"));
|
||||
assertTrue(manifest.path("artifacts").get(1).hasNonNull("artifact_id"));
|
||||
assertEquals("confirm.png", manifest.path("artifacts").get(1).path("file").asText());
|
||||
assertEquals(1, manifest.path("artifacts").get(1).path("index").asInt());
|
||||
assertTrue(manifest.path("artifacts").get(1).hasNonNull("fingerprint"));
|
||||
|
||||
final var detailsResult = service.getAssetDetails(new GetAssetDetailsRequest(
|
||||
project(projectRoot),
|
||||
@@ -793,9 +825,154 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertEquals(
|
||||
List.of("cancel.png", "confirm.png"),
|
||||
detailsResult.details().bankComposition().selectedFiles().stream().map(file -> file.path()).toList());
|
||||
assertNotNull(detailsResult.details().bankComposition().selectedFiles().getFirst().metadata().get("artifactId"));
|
||||
assertEquals(1, loader.loadCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAssetDetailsBackfillsLegacyArtifactIdsAndFingerprints() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("legacy-artifact-identity"));
|
||||
final Path assetRoot = projectRoot.resolve("assets/ui/atlas");
|
||||
writeTilePng(assetRoot.resolve("confirm.png"), 16);
|
||||
final ObjectNode manifest = (ObjectNode) MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
final var artifacts = manifest.putArray("artifacts");
|
||||
artifacts.addObject()
|
||||
.put("file", "confirm.png")
|
||||
.put("index", 0);
|
||||
MAPPER.writerWithDefaultPrettyPrinter().writeValue(assetRoot.resolve("asset.json").toFile(), manifest);
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
final var detailsResult = service.getAssetDetails(new GetAssetDetailsRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1)));
|
||||
|
||||
final var migrated = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
final var migratedArtifact = migrated.path("artifacts").get(0);
|
||||
assertTrue(migratedArtifact.hasNonNull("artifact_id"));
|
||||
assertTrue(migratedArtifact.hasNonNull("fingerprint"));
|
||||
final var selectedFile = detailsResult.details().bankComposition().selectedFiles().getFirst();
|
||||
assertEquals(migratedArtifact.path("artifact_id").asText(), selectedFile.metadata().get("artifactId"));
|
||||
assertEquals(migratedArtifact.path("fingerprint").asText(), selectedFile.metadata().get("selectedFingerprint"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void packValidationBlocksGlyphMaterialPaletteWhenSchemaVersionIsNewer() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("glyph-material-stale-palette"));
|
||||
final Path assetRoot = projectRoot.resolve("assets/ui/atlas");
|
||||
writeTilePng(assetRoot.resolve("confirm.png"), 16);
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
assertTrue(service.applyBankComposition(new ApplyBankCompositionRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of("confirm.png"))).success());
|
||||
assertTrue(service.applyPaletteOverhauling(new ApplyPaletteOverhaulingRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of(Map.of(
|
||||
"originalArgb8888", List.of(0xFFFF0000),
|
||||
"convertedRgb565", List.of(0xF800))))).success());
|
||||
|
||||
final var manifest = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
final var selectedArtifact = manifest.path("artifacts").get(0);
|
||||
writeGlyphMaterialJson(
|
||||
assetRoot,
|
||||
"""
|
||||
{
|
||||
"schema_version": 1,
|
||||
"schemas": [
|
||||
{
|
||||
"schema_id": "schema-1",
|
||||
"status": "ok",
|
||||
"version": 2,
|
||||
"material_indices": { "1": "#FF0000" },
|
||||
"artifact_bindings": [
|
||||
{ "artifact_id": "%s", "fingerprint": "%s" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"palettes": [
|
||||
{
|
||||
"palette_id": "palette-1",
|
||||
"schema_id": "schema-1",
|
||||
"version": 1,
|
||||
"colors": ["#FF0000"]
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(
|
||||
selectedArtifact.path("artifact_id").asText(),
|
||||
selectedArtifact.path("fingerprint").asText()));
|
||||
|
||||
final var result = service.validatePackWorkspace(new ValidatePackWorkspaceRequest(project(projectRoot)));
|
||||
|
||||
assertEquals(PackerOperationStatus.PARTIAL, result.status());
|
||||
assertFalse(result.canPack());
|
||||
assertTrue(result.assets().getFirst().diagnostics().stream()
|
||||
.anyMatch(diagnostic -> diagnostic.message().contains("is stale because version 1 is older than schema 'schema-1' version 2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void packValidationBlocksGlyphMaterialSchemaWhenArtifactFingerprintDrifts() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("glyph-material-drift"));
|
||||
final Path assetRoot = projectRoot.resolve("assets/ui/atlas");
|
||||
final Path tilePath = assetRoot.resolve("confirm.png");
|
||||
writeTilePng(tilePath, 16);
|
||||
final FileSystemPackerWorkspaceService service = service();
|
||||
|
||||
assertTrue(service.applyBankComposition(new ApplyBankCompositionRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of("confirm.png"))).success());
|
||||
assertTrue(service.applyPaletteOverhauling(new ApplyPaletteOverhaulingRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
List.of(Map.of(
|
||||
"originalArgb8888", List.of(0xFFFF0000),
|
||||
"convertedRgb565", List.of(0xF800))))).success());
|
||||
|
||||
final var manifest = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
final var selectedArtifact = manifest.path("artifacts").get(0);
|
||||
writeGlyphMaterialJson(
|
||||
assetRoot,
|
||||
"""
|
||||
{
|
||||
"schema_version": 1,
|
||||
"schemas": [
|
||||
{
|
||||
"schema_id": "schema-1",
|
||||
"status": "ok",
|
||||
"version": 1,
|
||||
"material_indices": { "1": "#FF0000" },
|
||||
"artifact_bindings": [
|
||||
{ "artifact_id": "%s", "fingerprint": "%s" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"palettes": [
|
||||
{
|
||||
"palette_id": "palette-1",
|
||||
"schema_id": "schema-1",
|
||||
"version": 1,
|
||||
"colors": ["#FF0000"]
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(
|
||||
selectedArtifact.path("artifact_id").asText(),
|
||||
selectedArtifact.path("fingerprint").asText()));
|
||||
writeSolidTilePng(tilePath, 16, 0xFF00FF00);
|
||||
|
||||
final var result = service.validatePackWorkspace(new ValidatePackWorkspaceRequest(project(projectRoot)));
|
||||
|
||||
assertEquals(PackerOperationStatus.PARTIAL, result.status());
|
||||
assertFalse(result.canPack());
|
||||
assertTrue(result.assets().getFirst().diagnostics().stream()
|
||||
.anyMatch(diagnostic -> diagnostic.message().contains("artifact '" + selectedArtifact.path("artifact_id").asText() + "' drifted")));
|
||||
assertTrue(result.assets().getFirst().diagnostics().stream()
|
||||
.anyMatch(diagnostic -> diagnostic.message().contains("palette 'palette-1' is invalid because schema 'schema-1' is inconsistent")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyPaletteOverhaulingWritesPipelinePalettesInOrder() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("apply-palette-overhauling"));
|
||||
@@ -1376,11 +1553,15 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
}
|
||||
|
||||
private void writeTilePng(Path path, int tileSize) throws Exception {
|
||||
writeSolidTilePng(path, tileSize, 0xFFFF0000);
|
||||
}
|
||||
|
||||
private void writeSolidTilePng(Path path, int tileSize, int argb) throws Exception {
|
||||
Files.createDirectories(path.getParent());
|
||||
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);
|
||||
image.setRGB(x, y, argb);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
@@ -1397,6 +1578,10 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
}
|
||||
|
||||
private void writeGlyphMaterialJson(Path assetRoot, String content) throws Exception {
|
||||
Files.writeString(assetRoot.resolve("glyph-material.json"), content);
|
||||
}
|
||||
|
||||
private static int readLeInt(byte[] bytes, int offset) {
|
||||
return (bytes[offset] & 0xFF)
|
||||
| ((bytes[offset + 1] & 0xFF) << 8)
|
||||
|
||||
+26
-1
@@ -76,6 +76,31 @@ final class PackerAssetDeclarationParserTest {
|
||||
"asset_uuid": "uuid-scene",
|
||||
"name": "overworld_scene",
|
||||
"type": "scene_bank",
|
||||
"output": {
|
||||
"format": "SCENE/tilemap_v1",
|
||||
"codec": "NONE"
|
||||
},
|
||||
"preload": { "enabled": false }
|
||||
}
|
||||
""");
|
||||
|
||||
final var result = parser.parse(manifest);
|
||||
|
||||
assertTrue(result.valid());
|
||||
assertEquals(AssetFamilyCatalog.SCENE_BANK, result.declaration().assetFamily());
|
||||
assertEquals("SCENE/tilemap_v1", result.declaration().outputFormat().displayName());
|
||||
assertEquals(OutputCodecCatalog.NONE, result.declaration().outputCodec());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesLegacySceneBankDeclarationFormatAsTilemapContract() throws Exception {
|
||||
final Path manifest = tempDir.resolve("legacy-scene-asset.json");
|
||||
Files.writeString(manifest, """
|
||||
{
|
||||
"schema_version": 1,
|
||||
"asset_uuid": "uuid-scene-legacy",
|
||||
"name": "overworld_scene",
|
||||
"type": "scene_bank",
|
||||
"output": {
|
||||
"format": "SCENE/tiled_v1",
|
||||
"codec": "NONE"
|
||||
@@ -88,7 +113,7 @@ final class PackerAssetDeclarationParserTest {
|
||||
|
||||
assertTrue(result.valid());
|
||||
assertEquals(AssetFamilyCatalog.SCENE_BANK, result.declaration().assetFamily());
|
||||
assertEquals("SCENE/tiled_v1", result.declaration().outputFormat().displayName());
|
||||
assertEquals("SCENE/tilemap_v1", result.declaration().outputFormat().displayName());
|
||||
assertEquals(OutputCodecCatalog.NONE, result.declaration().outputCodec());
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"schema_version" : 1,
|
||||
"glyph_bank_specialization" : "sprites"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"schema_version" : 1,
|
||||
"glyph_bank_specialization" : "sprites"
|
||||
}
|
||||
Reference in New Issue
Block a user