dev/glyph-bank-alignment (#3)
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 60.67% (15274/25176)
* Branch Coverage: 53.64% (5782/10779)
* Lines of Code: 25176
* Cyclomatic Complexity: 9960
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 11, passed: 545
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 60.67% (15274/25176)
* Branch Coverage: 53.64% (5782/10779)
* Lines of Code: 25176
* Cyclomatic Complexity: 9960
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 11, passed: 545
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #3 Co-authored-by: bQUARKz <bquarkz@gmail.com> Co-committed-by: bQUARKz <bquarkz@gmail.com>
This commit was merged in pull request #3.
This commit is contained in:
+30
-29
@@ -37,7 +37,7 @@ import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class FileSystemPackerWorkspaceService implements PackerWorkspaceService {
|
||||
private static final int TILE_BANK_COLOR_KEY_RGB565 = 0xF81F;
|
||||
private static final int GLYPH_BANK_COLOR_KEY_RGB565 = 0xF81F;
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
private final PackerWorkspaceFoundation workspaceFoundation;
|
||||
@@ -816,7 +816,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
if (declaration == null) {
|
||||
return List.of();
|
||||
}
|
||||
if (declaration.assetFamily() == AssetFamilyCatalog.TILE_BANK) {
|
||||
if (declaration.assetFamily() == AssetFamilyCatalog.GLYPH_BANK) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of(new PackerDiagnostic(
|
||||
@@ -878,7 +878,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
"size", packedAsset.payload().length,
|
||||
"decoded_size", packedAsset.decodedSize(),
|
||||
"codec", packedAsset.codec(),
|
||||
"metadata", packedAsset.metadata())));
|
||||
"metadata", packedAsset.runtimeMetadata())));
|
||||
if (packedAsset.preloadEnabled()) {
|
||||
final int slot = nextPreloadSlotByBankType.getOrDefault(packedAsset.bankType(), 0);
|
||||
nextPreloadSlotByBankType.put(packedAsset.bankType(), slot + 1);
|
||||
@@ -888,7 +888,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
assetTableMetadata.add(new LinkedHashMap<>(Map.of(
|
||||
"asset_id", packedAsset.assetId(),
|
||||
"metadata", packedAsset.metadata())));
|
||||
"metadata", packedAsset.toolingMetadata())));
|
||||
}
|
||||
|
||||
final byte[] headerBytes = canonicalJsonBytes(Map.of(
|
||||
@@ -909,10 +909,10 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
|
||||
private PackedAsset packRuntimeAsset(PackerRuntimeAsset runtimeAsset) {
|
||||
final PackerAssetDeclaration declaration = runtimeAsset.parsedDeclaration().declaration();
|
||||
if (declaration == null || declaration.assetFamily() != AssetFamilyCatalog.TILE_BANK) {
|
||||
if (declaration == null || declaration.assetFamily() != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
throw new IllegalStateException("Unsupported pack output family for current implementation.");
|
||||
}
|
||||
return packTileBank(runtimeAsset, declaration);
|
||||
return packGlyphBank(runtimeAsset, declaration);
|
||||
}
|
||||
|
||||
private boolean isEffectivelyIncludedInPackSet(PackerRuntimeAsset runtimeAsset) {
|
||||
@@ -923,7 +923,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return declaration == null || !declaration.artifacts().isEmpty();
|
||||
}
|
||||
|
||||
private PackedAsset packTileBank(PackerRuntimeAsset runtimeAsset, PackerAssetDeclaration declaration) {
|
||||
private PackedAsset packGlyphBank(PackerRuntimeAsset runtimeAsset, PackerAssetDeclaration declaration) {
|
||||
final int tileSize = parseTileSize(declaration.outputMetadata().get("tile_size"));
|
||||
final int width = 256;
|
||||
final int height = 256;
|
||||
@@ -955,35 +955,38 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
});
|
||||
|
||||
final byte[] packedPixels = packNibbles(sheetPixels);
|
||||
final byte[] paletteBytes = emitTileBankPalettes(declaration);
|
||||
final byte[] paletteBytes = emitGlyphBankPalettes(declaration);
|
||||
final byte[] payload = new byte[packedPixels.length + paletteBytes.length];
|
||||
System.arraycopy(packedPixels, 0, payload, 0, packedPixels.length);
|
||||
System.arraycopy(paletteBytes, 0, payload, packedPixels.length, paletteBytes.length);
|
||||
|
||||
final LinkedHashMap<String, Object> metadata = new LinkedHashMap<>();
|
||||
metadata.put("tile_size", tileSize);
|
||||
metadata.put("width", width);
|
||||
metadata.put("height", height);
|
||||
metadata.put("palette_count", 64);
|
||||
metadata.put("palette_authored", countAuthoredTileBankPalettes(declaration));
|
||||
metadata.put("codec", Map.of());
|
||||
metadata.put("pipeline", normalizeTileBankRuntimePipelineMetadata(declaration));
|
||||
final LinkedHashMap<String, Object> runtimeMetadata = new LinkedHashMap<>();
|
||||
runtimeMetadata.put("tile_size", tileSize);
|
||||
runtimeMetadata.put("width", width);
|
||||
runtimeMetadata.put("height", height);
|
||||
runtimeMetadata.put("palette_count", 64);
|
||||
runtimeMetadata.put("palette_authored", countAuthoredGlyphBankPalettes(declaration));
|
||||
runtimeMetadata.put("codec", Map.of());
|
||||
declaration.outputMetadata().forEach((key, value) -> {
|
||||
if (!"tile_size".equals(key)) {
|
||||
metadata.putIfAbsent(key, value);
|
||||
runtimeMetadata.putIfAbsent(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
final LinkedHashMap<String, Object> toolingMetadata = new LinkedHashMap<>(runtimeMetadata);
|
||||
toolingMetadata.put("pipeline", normalizeToolingPipelineMetadata(declaration));
|
||||
|
||||
final PackerRegistryEntry registryEntry = runtimeAsset.registryEntry()
|
||||
.orElseThrow(() -> new IllegalStateException("Packed runtime asset must be registered"));
|
||||
return new PackedAsset(
|
||||
registryEntry.assetId(),
|
||||
declaration.name(),
|
||||
"TILES",
|
||||
"GLYPH",
|
||||
"NONE",
|
||||
payload,
|
||||
width * height + 2048,
|
||||
metadata,
|
||||
runtimeMetadata,
|
||||
toolingMetadata,
|
||||
declaration.preloadEnabled());
|
||||
}
|
||||
|
||||
@@ -1006,7 +1009,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return packed;
|
||||
}
|
||||
|
||||
private byte[] emitTileBankPalettes(PackerAssetDeclaration declaration) {
|
||||
private byte[] emitGlyphBankPalettes(PackerAssetDeclaration declaration) {
|
||||
final byte[] bytes = new byte[64 * 16 * 2];
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
if (!(palettesNode instanceof com.fasterxml.jackson.databind.node.ArrayNode palettesArray)) {
|
||||
@@ -1023,8 +1026,8 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
continue;
|
||||
}
|
||||
final int paletteBaseOffset = (paletteIndex * 16) * 2;
|
||||
bytes[paletteBaseOffset] = (byte) (TILE_BANK_COLOR_KEY_RGB565 & 0xFF);
|
||||
bytes[paletteBaseOffset + 1] = (byte) ((TILE_BANK_COLOR_KEY_RGB565 >>> 8) & 0xFF);
|
||||
bytes[paletteBaseOffset] = (byte) (GLYPH_BANK_COLOR_KEY_RGB565 & 0xFF);
|
||||
bytes[paletteBaseOffset + 1] = (byte) ((GLYPH_BANK_COLOR_KEY_RGB565 >>> 8) & 0xFF);
|
||||
final JsonNode convertedNode = paletteNode.path("convertedRgb565");
|
||||
if (!convertedNode.isArray()) {
|
||||
continue;
|
||||
@@ -1039,16 +1042,13 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private int countAuthoredTileBankPalettes(PackerAssetDeclaration declaration) {
|
||||
private int countAuthoredGlyphBankPalettes(PackerAssetDeclaration declaration) {
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
return palettesNode instanceof ArrayNode palettesArray ? palettesArray.size() : 0;
|
||||
}
|
||||
|
||||
private Map<String, Object> normalizeTileBankRuntimePipelineMetadata(PackerAssetDeclaration declaration) {
|
||||
final LinkedHashMap<String, Object> pipeline = new LinkedHashMap<>(
|
||||
PackerReadMessageMapper.normalizeMetadata(declaration.outputPipelineMetadata()));
|
||||
pipeline.remove("palettes");
|
||||
return pipeline;
|
||||
private Map<String, Object> normalizeToolingPipelineMetadata(PackerAssetDeclaration declaration) {
|
||||
return new LinkedHashMap<>(PackerReadMessageMapper.normalizeMetadata(declaration.outputPipelineMetadata()));
|
||||
}
|
||||
|
||||
private byte[] buildPrelude(int headerLength) {
|
||||
@@ -1111,7 +1111,8 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
String codec,
|
||||
byte[] payload,
|
||||
int decodedSize,
|
||||
Map<String, Object> metadata,
|
||||
Map<String, Object> runtimeMetadata,
|
||||
Map<String, Object> toolingMetadata,
|
||||
boolean preloadEnabled) {
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ public final class PackerAssetDeclarationParser {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'type' must be one of: tile_bank, palette_bank, sound_bank.",
|
||||
"Field 'type' must be one of: glyph_bank, palette_bank, sound_bank.",
|
||||
manifestPath,
|
||||
true));
|
||||
return null;
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ final class PackerOutputContractCatalog {
|
||||
codecs.addAll(outputFormat.availableCodecs());
|
||||
} else {
|
||||
final String normalizedFormat = outputFormat.manifestValue().trim().toUpperCase(Locale.ROOT);
|
||||
if (normalizedFormat.startsWith("TILES/")
|
||||
if (normalizedFormat.startsWith("GLYPH/")
|
||||
|| normalizedFormat.startsWith("PALETTE/")
|
||||
|| normalizedFormat.startsWith("SOUND/")
|
||||
|| normalizedFormat.startsWith("AUDIO/")) {
|
||||
@@ -54,7 +54,7 @@ final class PackerOutputContractCatalog {
|
||||
|
||||
private static List<PackerCodecConfigurationField> metadataFieldsFor(OutputFormatCatalog outputFormat) {
|
||||
return switch (outputFormat) {
|
||||
case TILES_INDEXED_V1 -> List.of(new PackerCodecConfigurationField(
|
||||
case GLYPH_INDEXED_V1 -> List.of(new PackerCodecConfigurationField(
|
||||
"tile_size",
|
||||
"TileSize",
|
||||
PackerCodecConfigurationFieldType.ENUM,
|
||||
|
||||
Reference in New Issue
Block a user