packer (WIP)
This commit is contained in:
+14
-3
@@ -981,16 +981,19 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
final ObjectNode outputNode = mutableObject(manifest, "output");
|
||||
final ObjectNode pipelineNode = mutableObject(outputNode, "pipeline");
|
||||
final ArrayNode palettesNode = pipelineNode.putArray("palettes");
|
||||
for (Map<String, Object> palette : request.selectedPalettes()) {
|
||||
for (int paletteOrder = 0; paletteOrder < request.selectedPalettes().size(); paletteOrder += 1) {
|
||||
final Map<String, Object> palette = request.selectedPalettes().get(paletteOrder);
|
||||
final List<Integer> originalArgb8888 = integerList(palette.get("originalArgb8888"));
|
||||
final List<Integer> convertedRgb565 = integerList(palette.get("convertedRgb565"));
|
||||
if (originalArgb8888.isEmpty() || convertedRgb565.isEmpty()) {
|
||||
throw new IllegalArgumentException("Each selected palette must contain originalArgb8888 and convertedRgb565 entries.");
|
||||
}
|
||||
final ObjectNode paletteNode = palettesNode.addObject();
|
||||
final ArrayNode originalNode = paletteNode.putArray("originalArgb8888");
|
||||
paletteNode.put("index", paletteIndex(palette, paletteOrder));
|
||||
final ObjectNode payloadNode = paletteNode.putObject("palette");
|
||||
final ArrayNode originalNode = payloadNode.putArray("originalArgb8888");
|
||||
originalArgb8888.forEach(originalNode::add);
|
||||
final ArrayNode convertedNode = paletteNode.putArray("convertedRgb565");
|
||||
final ArrayNode convertedNode = payloadNode.putArray("convertedRgb565");
|
||||
convertedRgb565.forEach(convertedNode::add);
|
||||
}
|
||||
if (palettesNode.isEmpty()) {
|
||||
@@ -998,6 +1001,14 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
}
|
||||
|
||||
private int paletteIndex(Map<String, Object> palette, int fallbackIndex) {
|
||||
final Object rawIndex = palette.get("index");
|
||||
if (rawIndex instanceof Number number && number.intValue() >= 0) {
|
||||
return number.intValue();
|
||||
}
|
||||
return fallbackIndex;
|
||||
}
|
||||
|
||||
private List<Integer> integerList(Object value) {
|
||||
if (!(value instanceof Iterable<?> iterable)) {
|
||||
return List.of();
|
||||
|
||||
+86
@@ -18,6 +18,7 @@ import java.util.*;
|
||||
|
||||
public final class PackerAssetDeclarationParser {
|
||||
private static final Set<Integer> SUPPORTED_SCHEMA_VERSIONS = Set.of(1);
|
||||
private static final int MAX_PIPELINE_PALETTES = 64;
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@@ -270,11 +271,96 @@ public final class PackerAssetDeclarationParser {
|
||||
true));
|
||||
return;
|
||||
}
|
||||
if ("palettes".equals(key)) {
|
||||
pipelineMetadata.put(key, validatePaletteDeclarations(valueNode, diagnostics, manifestPath));
|
||||
return;
|
||||
}
|
||||
pipelineMetadata.put(key, valueNode.deepCopy());
|
||||
});
|
||||
return Map.copyOf(pipelineMetadata);
|
||||
}
|
||||
|
||||
private JsonNode validatePaletteDeclarations(
|
||||
final JsonNode node,
|
||||
final List<PackerDiagnostic> diagnostics,
|
||||
final Path manifestPath) {
|
||||
if (!node.isArray()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline.palettes' must be an array of palette declarations.",
|
||||
manifestPath,
|
||||
true));
|
||||
return node.deepCopy();
|
||||
}
|
||||
|
||||
final Set<Integer> seenIndices = new HashSet<>();
|
||||
int paletteCount = 0;
|
||||
for (JsonNode entry : node) {
|
||||
paletteCount += 1;
|
||||
if (!entry.isObject()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Each palette declaration must be an object with non-negative integer 'index' and object 'palette'.",
|
||||
manifestPath,
|
||||
true));
|
||||
continue;
|
||||
}
|
||||
|
||||
final JsonNode indexNode = entry.path("index");
|
||||
final JsonNode paletteNode = entry.path("palette");
|
||||
if (!indexNode.isInt() || indexNode.intValue() < 0) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Each palette declaration must define a non-negative integer 'index'.",
|
||||
manifestPath,
|
||||
true));
|
||||
} else if (!seenIndices.add(indexNode.intValue())) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline.palettes' contains duplicate palette index " + indexNode.intValue() + ".",
|
||||
manifestPath,
|
||||
true));
|
||||
}
|
||||
|
||||
if (!paletteNode.isObject()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Each palette declaration must define an object 'palette' payload.",
|
||||
manifestPath,
|
||||
true));
|
||||
continue;
|
||||
}
|
||||
|
||||
final JsonNode originalNode = paletteNode.path("originalArgb8888");
|
||||
final JsonNode convertedNode = paletteNode.path("convertedRgb565");
|
||||
if (!originalNode.isArray() || !convertedNode.isArray()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Each palette payload must contain array fields 'originalArgb8888' and 'convertedRgb565'.",
|
||||
manifestPath,
|
||||
true));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (paletteCount > MAX_PIPELINE_PALETTES) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline.palettes' cannot declare more than " + MAX_PIPELINE_PALETTES + " palettes.",
|
||||
manifestPath,
|
||||
true));
|
||||
}
|
||||
|
||||
return node.deepCopy();
|
||||
}
|
||||
|
||||
private void rejectLegacyInputs(
|
||||
final JsonNode node,
|
||||
final List<PackerDiagnostic> diagnostics,
|
||||
|
||||
+9
-2
@@ -179,6 +179,7 @@ public final class PackerAssetDetailsService {
|
||||
palettes.add(normalized);
|
||||
}
|
||||
}
|
||||
palettes.sort(Comparator.comparingInt(palette -> ((Number) palette.get("index")).intValue()));
|
||||
return List.copyOf(palettes);
|
||||
}
|
||||
|
||||
@@ -186,8 +187,13 @@ public final class PackerAssetDetailsService {
|
||||
if (!(paletteNode instanceof ObjectNode paletteObject)) {
|
||||
return Map.of();
|
||||
}
|
||||
final JsonNode originalNode = paletteObject.path("originalArgb8888");
|
||||
final JsonNode convertedNode = paletteObject.path("convertedRgb565");
|
||||
final JsonNode indexNode = paletteObject.path("index");
|
||||
final JsonNode payloadNode = paletteObject.path("palette");
|
||||
if (!indexNode.isInt() || indexNode.intValue() < 0 || !(payloadNode instanceof ObjectNode payloadObject)) {
|
||||
return Map.of();
|
||||
}
|
||||
final JsonNode originalNode = payloadObject.path("originalArgb8888");
|
||||
final JsonNode convertedNode = payloadObject.path("convertedRgb565");
|
||||
if (!originalNode.isArray() || !convertedNode.isArray()) {
|
||||
return Map.of();
|
||||
}
|
||||
@@ -206,6 +212,7 @@ public final class PackerAssetDetailsService {
|
||||
convertedRgb565.add(colorNode.intValue());
|
||||
}
|
||||
return Map.of(
|
||||
"index", indexNode.intValue(),
|
||||
"originalArgb8888", List.copyOf(originalArgb8888),
|
||||
"convertedRgb565", List.copyOf(convertedRgb565));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user