asset details (WIP)
This commit is contained in:
+15
@@ -1,10 +1,12 @@
|
||||
package p.packer.models;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -18,6 +20,7 @@ public record PackerAssetDeclaration(
|
||||
OutputFormatCatalog outputFormat,
|
||||
OutputCodecCatalog outputCodec,
|
||||
Map<String, String> outputMetadata,
|
||||
Map<String, JsonNode> outputPipelineMetadata,
|
||||
boolean preloadEnabled) {
|
||||
|
||||
public PackerAssetDeclaration {
|
||||
@@ -31,8 +34,20 @@ public record PackerAssetDeclaration(
|
||||
outputFormat = Objects.requireNonNull(outputFormat, "outputFormat");
|
||||
outputCodec = Objects.requireNonNull(outputCodec, "outputCodec");
|
||||
outputMetadata = Map.copyOf(Objects.requireNonNull(outputMetadata, "outputMetadata"));
|
||||
outputPipelineMetadata = immutablePipelineMetadata(outputPipelineMetadata);
|
||||
if (StringUtils.isBlank(assetUuid) || StringUtils.isBlank(name)) {
|
||||
throw new IllegalArgumentException("declaration fields must not be blank");
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, JsonNode> immutablePipelineMetadata(Map<String, JsonNode> pipelineMetadata) {
|
||||
final Map<String, JsonNode> sanitized = new LinkedHashMap<>();
|
||||
Objects.requireNonNull(pipelineMetadata, "outputPipelineMetadata").forEach((key, value) -> {
|
||||
if (key == null || key.isBlank() || value == null) {
|
||||
return;
|
||||
}
|
||||
sanitized.put(key.trim(), value.deepCopy());
|
||||
});
|
||||
return Map.copyOf(sanitized);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -15,6 +15,7 @@ public record PackerAssetDetails(
|
||||
Map<OutputCodecCatalog, List<PackerCodecConfigurationField>> codecConfigurationFieldsByCodec,
|
||||
List<PackerCodecConfigurationField> metadataFields,
|
||||
PackerBankCompositionDetails bankComposition,
|
||||
List<Map<String, Object>> pipelinePalettes,
|
||||
List<PackerDiagnostic> diagnostics) {
|
||||
|
||||
public PackerAssetDetails {
|
||||
@@ -25,6 +26,7 @@ public record PackerAssetDetails(
|
||||
codecConfigurationFieldsByCodec = Map.copyOf(Objects.requireNonNull(codecConfigurationFieldsByCodec, "codecConfigurationFieldsByCodec"));
|
||||
metadataFields = List.copyOf(Objects.requireNonNull(metadataFields, "metadataFields"));
|
||||
bankComposition = Objects.requireNonNull(bankComposition, "bankComposition");
|
||||
pipelinePalettes = List.copyOf(Objects.requireNonNull(pipelinePalettes, "pipelinePalettes"));
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
}
|
||||
}
|
||||
|
||||
+94
-1
@@ -2,6 +2,7 @@ package p.packer.services;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import p.packer.PackerWorkspacePaths;
|
||||
import p.packer.PackerWorkspaceService;
|
||||
@@ -541,7 +542,8 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
manifest.put("type", request.assetFamily().manifestType());
|
||||
manifest.put("output", Map.of(
|
||||
"format", request.outputFormat().manifestValue(),
|
||||
"codec", request.outputCodec().manifestValue()));
|
||||
"codec", request.outputCodec().manifestValue(),
|
||||
"pipeline", Map.of()));
|
||||
manifest.put("preload", Map.of("enabled", request.preloadEnabled()));
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
}
|
||||
@@ -665,6 +667,13 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return writeCoordinator.execute(project, () -> applyBankCompositionInWriteLane(safeRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplyPaletteOverhaulingResponse applyPaletteOverhauling(final ApplyPaletteOverhaulingRequest request) {
|
||||
final ApplyPaletteOverhaulingRequest safeRequest = Objects.requireNonNull(request, "request");
|
||||
final PackerProjectContext project = safeRequest.project();
|
||||
return writeCoordinator.execute(project, () -> applyPaletteOverhaulingInWriteLane(safeRequest));
|
||||
}
|
||||
|
||||
private UpdateAssetContractResponse updateAssetContractInWriteLane(UpdateAssetContractRequest request) {
|
||||
final PackerProjectContext project = request.project();
|
||||
workspaceFoundation.initWorkspace(new InitWorkspaceRequest(project));
|
||||
@@ -772,6 +781,55 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
}
|
||||
|
||||
private ApplyPaletteOverhaulingResponse applyPaletteOverhaulingInWriteLane(ApplyPaletteOverhaulingRequest request) {
|
||||
final PackerProjectContext project = request.project();
|
||||
workspaceFoundation.initWorkspace(new InitWorkspaceRequest(project));
|
||||
final PackerRuntimeSnapshot snapshot = runtimeRegistry.getOrLoad(project).snapshot();
|
||||
final PackerDeleteAssetEvaluation evaluation = actionReadService.evaluateDelete(snapshot, project, request.assetReference());
|
||||
if (!evaluation.canDelete()) {
|
||||
return new ApplyPaletteOverhaulingResponse(
|
||||
false,
|
||||
Objects.requireNonNullElse(evaluation.reason(), "Asset palette overhauling cannot be updated."));
|
||||
}
|
||||
if (request.selectedPalettes().isEmpty()) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "At least one palette must be selected.");
|
||||
}
|
||||
|
||||
final Path assetRoot = evaluation.resolved().assetRoot();
|
||||
final Path manifestPath = assetRoot.resolve("asset.json");
|
||||
if (!Files.isRegularFile(manifestPath)) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "asset.json was not found for the requested asset root.");
|
||||
}
|
||||
|
||||
final ObjectNode manifest;
|
||||
try {
|
||||
final JsonNode rawManifest = mapper.readTree(manifestPath.toFile());
|
||||
if (!(rawManifest instanceof ObjectNode objectNode)) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "asset.json must contain a JSON object at the root.");
|
||||
}
|
||||
manifest = objectNode;
|
||||
} catch (IOException exception) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "Unable to read asset manifest: " + exception.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
patchManifestPipelinePalettes(manifest, request);
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
final var runtime = runtimeRegistry.update(project, (currentSnapshot, generation) -> runtimePatchService.afterUpdateAssetContract(
|
||||
currentSnapshot,
|
||||
generation,
|
||||
assetRoot,
|
||||
manifestPath,
|
||||
evaluation.resolved().registryEntry()));
|
||||
saveRuntimeCache(project, runtime.snapshot());
|
||||
return new ApplyPaletteOverhaulingResponse(true, null);
|
||||
} catch (IOException exception) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "Unable to update asset palette overhauling: " + exception.getMessage());
|
||||
} catch (RuntimeException exception) {
|
||||
return new ApplyPaletteOverhaulingResponse(false, "Unable to update runtime snapshot: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private OutputFormatCatalog resolveManifestOutputFormat(ObjectNode manifest) {
|
||||
final JsonNode outputNode = manifest.get("output");
|
||||
if (!(outputNode instanceof ObjectNode outputObject)) {
|
||||
@@ -832,6 +890,41 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
}
|
||||
|
||||
private void patchManifestPipelinePalettes(ObjectNode manifest, ApplyPaletteOverhaulingRequest request) {
|
||||
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()) {
|
||||
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");
|
||||
originalArgb8888.forEach(originalNode::add);
|
||||
final ArrayNode convertedNode = paletteNode.putArray("convertedRgb565");
|
||||
convertedRgb565.forEach(convertedNode::add);
|
||||
}
|
||||
if (palettesNode.isEmpty()) {
|
||||
throw new IllegalArgumentException("At least one palette must be selected.");
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> integerList(Object value) {
|
||||
if (!(value instanceof Iterable<?> iterable)) {
|
||||
return List.of();
|
||||
}
|
||||
final List<Integer> numbers = new ArrayList<>();
|
||||
for (Object item : iterable) {
|
||||
if (!(item instanceof Number number)) {
|
||||
return List.of();
|
||||
}
|
||||
numbers.add(number.intValue());
|
||||
}
|
||||
return List.copyOf(numbers);
|
||||
}
|
||||
|
||||
private String contractFingerprint(ObjectNode manifest) {
|
||||
final JsonNode outputNode = manifest.path("output");
|
||||
if (!(outputNode instanceof ObjectNode outputObject)) {
|
||||
|
||||
+47
@@ -50,6 +50,7 @@ public final class PackerAssetDeclarationParser {
|
||||
final var outputFormat = requiredOutputFormat(root.path("output"), diagnostics, manifestPath);
|
||||
final var outputCodec = requiredOutputCodec(root.path("output"), diagnostics, manifestPath);
|
||||
final var outputMetadata = optionalOutputMetadata(root.path("output"), diagnostics, manifestPath);
|
||||
final var outputPipelineMetadata = optionalOutputPipelineMetadata(root.path("output"), diagnostics, manifestPath);
|
||||
final var preloadEnabled = requiredBoolean(root.path("preload"), "enabled", diagnostics, manifestPath);
|
||||
|
||||
if (schemaVersion != null && !SUPPORTED_SCHEMA_VERSIONS.contains(schemaVersion)) {
|
||||
@@ -75,6 +76,7 @@ public final class PackerAssetDeclarationParser {
|
||||
outputFormat,
|
||||
outputCodec,
|
||||
outputMetadata,
|
||||
outputPipelineMetadata,
|
||||
preloadEnabled),
|
||||
diagnostics);
|
||||
}
|
||||
@@ -228,6 +230,51 @@ public final class PackerAssetDeclarationParser {
|
||||
return Map.copyOf(metadata);
|
||||
}
|
||||
|
||||
private Map<String, JsonNode> optionalOutputPipelineMetadata(
|
||||
final JsonNode node,
|
||||
final List<PackerDiagnostic> diagnostics,
|
||||
final Path manifestPath) {
|
||||
final JsonNode pipelineNode = node.path("pipeline");
|
||||
if (pipelineNode.isMissingNode() || pipelineNode.isNull()) {
|
||||
return Map.of();
|
||||
}
|
||||
if (!pipelineNode.isObject()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline' must be a JSON object.",
|
||||
manifestPath,
|
||||
true));
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
final Map<String, JsonNode> pipelineMetadata = new LinkedHashMap<>();
|
||||
pipelineNode.fields().forEachRemaining(entry -> {
|
||||
final String key = Objects.requireNonNullElse(entry.getKey(), "").trim();
|
||||
if (key.isBlank()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline' has an invalid empty key.",
|
||||
manifestPath,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
final JsonNode valueNode = entry.getValue();
|
||||
if (valueNode == null) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline' values must be valid JSON values.",
|
||||
manifestPath,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
pipelineMetadata.put(key, valueNode.deepCopy());
|
||||
});
|
||||
return Map.copyOf(pipelineMetadata);
|
||||
}
|
||||
|
||||
private void rejectLegacyInputs(
|
||||
final JsonNode node,
|
||||
final List<PackerDiagnostic> diagnostics,
|
||||
|
||||
+48
@@ -1,5 +1,8 @@
|
||||
package p.packer.services;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import p.packer.PackerWorkspacePaths;
|
||||
import p.packer.messages.*;
|
||||
import p.packer.messages.assets.*;
|
||||
@@ -80,6 +83,7 @@ public final class PackerAssetDetailsService {
|
||||
outputContract.codecConfigurationFieldsByCodec(),
|
||||
metadataFields(outputContract.metadataFields(), declaration.outputMetadata()),
|
||||
resolveBankCompositionDetails(snapshot, runtimeAsset, declaration),
|
||||
resolvePipelinePalettes(declaration),
|
||||
diagnostics);
|
||||
return new GetAssetDetailsResult(
|
||||
diagnostics.stream().anyMatch(PackerDiagnostic::blocking) ? PackerOperationStatus.PARTIAL : PackerOperationStatus.SUCCESS,
|
||||
@@ -119,6 +123,7 @@ public final class PackerAssetDetailsService {
|
||||
Map.of(OutputCodecCatalog.NONE, List.of()),
|
||||
List.of(),
|
||||
PackerBankCompositionDetails.EMPTY,
|
||||
List.of(),
|
||||
diagnostics);
|
||||
return new GetAssetDetailsResult(
|
||||
PackerOperationStatus.FAILED,
|
||||
@@ -160,6 +165,49 @@ public final class PackerAssetDetailsService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> resolvePipelinePalettes(PackerAssetDeclaration declaration) {
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
if (!(palettesNode instanceof ArrayNode palettesArray)) {
|
||||
return List.of();
|
||||
}
|
||||
final List<Map<String, Object>> palettes = new ArrayList<>();
|
||||
for (JsonNode paletteNode : palettesArray) {
|
||||
final Map<String, Object> normalized = palettePayloadFromNode(paletteNode);
|
||||
if (!normalized.isEmpty()) {
|
||||
palettes.add(normalized);
|
||||
}
|
||||
}
|
||||
return List.copyOf(palettes);
|
||||
}
|
||||
|
||||
private Map<String, Object> palettePayloadFromNode(JsonNode paletteNode) {
|
||||
if (!(paletteNode instanceof ObjectNode paletteObject)) {
|
||||
return Map.of();
|
||||
}
|
||||
final JsonNode originalNode = paletteObject.path("originalArgb8888");
|
||||
final JsonNode convertedNode = paletteObject.path("convertedRgb565");
|
||||
if (!originalNode.isArray() || !convertedNode.isArray()) {
|
||||
return Map.of();
|
||||
}
|
||||
final List<Integer> originalArgb8888 = new ArrayList<>();
|
||||
for (JsonNode colorNode : originalNode) {
|
||||
if (!colorNode.canConvertToInt()) {
|
||||
return Map.of();
|
||||
}
|
||||
originalArgb8888.add(colorNode.intValue());
|
||||
}
|
||||
final List<Integer> convertedRgb565 = new ArrayList<>();
|
||||
for (JsonNode colorNode : convertedNode) {
|
||||
if (!colorNode.canConvertToInt()) {
|
||||
return Map.of();
|
||||
}
|
||||
convertedRgb565.add(colorNode.intValue());
|
||||
}
|
||||
return Map.of(
|
||||
"originalArgb8888", List.copyOf(originalArgb8888),
|
||||
"convertedRgb565", List.copyOf(convertedRgb565));
|
||||
}
|
||||
|
||||
private Optional<PackerBankCompositionFile> resolveSelectedBankFile(
|
||||
Path assetRoot,
|
||||
String relativePath,
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ public final class PackerReadMessageMapper {
|
||||
toCodecConfigurationFieldsByCodecDTO(details.codecConfigurationFieldsByCodec()),
|
||||
toCodecConfigurationFieldDTOs(details.metadataFields()),
|
||||
toBankCompositionDetailsDTO(details.bankComposition()),
|
||||
details.pipelinePalettes().stream().map(PackerReadMessageMapper::normalizeMetadata).toList(),
|
||||
toDiagnosticDTOs(details.diagnostics()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user