Tiled Parser and Scene & Palette Management in Studio
This commit is contained in:
+4
-1
@@ -5,7 +5,7 @@ import java.util.Locale;
|
||||
|
||||
public enum OutputFormatCatalog {
|
||||
GLYPH_INDEXED_V1(AssetFamilyCatalog.GLYPH_BANK, "GLYPH/indexed_v1", "GLYPH/indexed_v1"),
|
||||
SCENE_TILED_V1(AssetFamilyCatalog.SCENE_BANK, "SCENE/tiled_v1", "SCENE/tiled_v1"),
|
||||
SCENE_TILED_V1(AssetFamilyCatalog.SCENE_BANK, "SCENE/tilemap_v1", "SCENE/tilemap_v1"),
|
||||
SOUND_V1(AssetFamilyCatalog.SOUND_BANK, "SOUND/v1", "SOUND/v1"),
|
||||
UNKNOWN(AssetFamilyCatalog.UNKNOWN, "unknown", "Unknown");
|
||||
|
||||
@@ -54,6 +54,9 @@ public enum OutputFormatCatalog {
|
||||
return UNKNOWN;
|
||||
}
|
||||
final String normalized = manifestValue.trim().toLowerCase(Locale.ROOT);
|
||||
if ("scene/tiled_v1".equals(normalized)) {
|
||||
return SCENE_TILED_V1;
|
||||
}
|
||||
if ("sound/bank_v1".equals(normalized)) {
|
||||
return SOUND_V1;
|
||||
}
|
||||
|
||||
+5
-1
@@ -3,11 +3,15 @@ package p.packer.models;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PackerAssetArtifactSelection(
|
||||
String artifactId,
|
||||
String file,
|
||||
int index) {
|
||||
int index,
|
||||
String fingerprint) {
|
||||
|
||||
public PackerAssetArtifactSelection {
|
||||
artifactId = artifactId == null || artifactId.isBlank() ? null : artifactId.trim();
|
||||
file = Objects.requireNonNull(file, "file").trim();
|
||||
fingerprint = fingerprint == null || fingerprint.isBlank() ? null : fingerprint.trim();
|
||||
if (file.isBlank()) {
|
||||
throw new IllegalArgumentException("file must not be blank");
|
||||
}
|
||||
|
||||
+196
-12
@@ -4,6 +4,7 @@ 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 com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import p.packer.PackerWorkspacePaths;
|
||||
import p.packer.PackerWorkspaceService;
|
||||
import p.packer.events.PackerEventKind;
|
||||
@@ -49,6 +50,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
private final FileSystemPackerCacheRepository cacheRepository;
|
||||
private final PackerProjectWriteCoordinator writeCoordinator;
|
||||
private final PackerEventSink eventSink;
|
||||
private final PackerGlyphMaterialSupport glyphMaterialSupport;
|
||||
|
||||
public FileSystemPackerWorkspaceService(
|
||||
ObjectMapper mapper,
|
||||
@@ -69,6 +71,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
this.cacheRepository = Objects.requireNonNull(cacheRepository, "cacheRepository");
|
||||
this.writeCoordinator = Objects.requireNonNull(writeCoordinator, "writeCoordinator");
|
||||
this.eventSink = Objects.requireNonNull(eventSink, "eventSink");
|
||||
this.glyphMaterialSupport = new PackerGlyphMaterialSupport(mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +85,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
public ListAssetsResult listAssets(ListAssetsRequest request) {
|
||||
final var project = Objects.requireNonNull(request, "request").project();
|
||||
final var snapshot = request.deepSync()
|
||||
? runtimeRegistry.refresh(project).snapshot()
|
||||
? writeCoordinator.execute(project, () -> refreshAfterArtifactIdentityBackfill(project))
|
||||
: runtimeRegistry.getOrLoad(project).snapshot();
|
||||
final var events = new PackerOperationEventEmitter(project, eventSink);
|
||||
final var registry = snapshot.registry();
|
||||
@@ -146,7 +149,11 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
|
||||
@Override
|
||||
public GetAssetDetailsResult getAssetDetails(GetAssetDetailsRequest request) {
|
||||
return detailsService.getAssetDetails(request);
|
||||
final GetAssetDetailsRequest safeRequest = Objects.requireNonNull(request, "request");
|
||||
return writeCoordinator.execute(safeRequest.project(), () -> {
|
||||
backfillLoadedArtifactIdentity(safeRequest.project());
|
||||
return detailsService.getAssetDetails(safeRequest);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,7 +179,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
@Override
|
||||
public ValidatePackWorkspaceResult validatePackWorkspace(ValidatePackWorkspaceRequest request) {
|
||||
final PackerProjectContext project = Objects.requireNonNull(request, "request").project();
|
||||
final PackerRuntimeSnapshot snapshot = runtimeRegistry.getOrLoad(project).snapshot();
|
||||
final PackerRuntimeSnapshot snapshot = writeCoordinator.execute(project, () -> refreshAfterArtifactIdentityBackfill(project));
|
||||
final List<PackerPackValidationAssetDTO> blockedAssets = snapshot.assets().stream()
|
||||
.filter(this::isEffectivelyIncludedInPackSet)
|
||||
.map(this::toPackValidationAssetDTO)
|
||||
@@ -322,7 +329,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
final long startedAt = System.currentTimeMillis();
|
||||
workspaceFoundation.initWorkspace(new InitWorkspaceRequest(project));
|
||||
|
||||
final PackerRuntimeSnapshot refreshedSnapshot = runtimeRegistry.refresh(project).snapshot();
|
||||
final PackerRuntimeSnapshot refreshedSnapshot = refreshAfterArtifactIdentityBackfill(project);
|
||||
final PackerRuntimeSnapshot frozenSnapshot = createFrozenPackingSnapshot(refreshedSnapshot);
|
||||
final List<PackerPackValidationAssetDTO> blockedAssets = frozenSnapshot.assets().stream()
|
||||
.filter(this::isEffectivelyIncludedInPackSet)
|
||||
@@ -500,6 +507,12 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
try {
|
||||
if (request.includedInBuild() && !sceneBankCanEnterBuild(assetRoot)) {
|
||||
return new UpdateAssetBuildParticipationResult(
|
||||
PackerOperationStatus.FAILED,
|
||||
"Scene Bank must enable at least one layer before entering the build.",
|
||||
null);
|
||||
}
|
||||
final PackerRegistryEntry currentEntry = evaluation.resolved().registryEntry().orElseThrow();
|
||||
final PackerRegistryEntry updatedEntry = new PackerRegistryEntry(
|
||||
currentEntry.assetId(),
|
||||
@@ -677,17 +690,49 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
supportFile.put("schema_version", 1);
|
||||
supportFile.put("map_width", 16);
|
||||
supportFile.put("map_height", 16);
|
||||
supportFile.put("layer_count", 1);
|
||||
supportFile.put("layers", List.of(Map.of(
|
||||
"index", 1,
|
||||
"name", "Layer 1",
|
||||
"tilemap", "layer-1.tmx",
|
||||
"tileset_asset_root", "")));
|
||||
supportFile.put("layer_count", 4);
|
||||
final List<Map<String, Object>> layers = new ArrayList<>();
|
||||
for (int index = 1; index <= 4; index += 1) {
|
||||
layers.add(Map.of(
|
||||
"index", index,
|
||||
"enabled", false,
|
||||
"name", "Layer " + index,
|
||||
"width", 16,
|
||||
"height", 16,
|
||||
"tilemap", "layer-" + index + ".tmx",
|
||||
"tileset_asset_root", ""));
|
||||
}
|
||||
supportFile.put("layers", layers);
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(
|
||||
assetRoot.resolve(SCENE_BANK_SUPPORT_FILE).toFile(),
|
||||
supportFile);
|
||||
}
|
||||
|
||||
private boolean sceneBankCanEnterBuild(Path assetRoot) {
|
||||
final Path supportFilePath = assetRoot.resolve(SCENE_BANK_SUPPORT_FILE);
|
||||
if (!Files.isRegularFile(supportFilePath)) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
final JsonNode root = mapper.readTree(supportFilePath.toFile());
|
||||
if (!(root instanceof ObjectNode objectNode)) {
|
||||
return false;
|
||||
}
|
||||
final JsonNode layersNode = objectNode.get("layers");
|
||||
if (!(layersNode instanceof ArrayNode layers)) {
|
||||
return false;
|
||||
}
|
||||
for (JsonNode layer : layers) {
|
||||
if (layer.path("enabled").asBoolean(false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeRelativeAssetRoot(String candidate) {
|
||||
final String raw = Objects.requireNonNullElse(candidate, "").trim().replace('\\', '/');
|
||||
if (raw.isBlank()) {
|
||||
@@ -802,6 +847,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
parsed.diagnostics(),
|
||||
runtimeAsset.walkDiagnostics(),
|
||||
collectPackRelevantWalkFileDiagnostics(runtimeAsset),
|
||||
glyphMaterialSupport.validate(runtimeAsset),
|
||||
packExecutionSupportDiagnostics(parsed.declaration(), runtimeAsset.manifestPath()),
|
||||
identityMismatchDiagnostics(registryEntry, parsed, runtimeAsset.manifestPath()))
|
||||
.flatMap(Collection::stream)
|
||||
@@ -852,6 +898,84 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
cacheRepository.save(project, snapshot.cacheState());
|
||||
}
|
||||
|
||||
private PackerRuntimeSnapshot refreshAfterArtifactIdentityBackfill(PackerProjectContext project) {
|
||||
final PackerRuntimeSnapshot snapshot = runtimeRegistry.refresh(project).snapshot();
|
||||
return backfillArtifactIdentity(snapshot)
|
||||
? runtimeRegistry.refresh(project).snapshot()
|
||||
: snapshot;
|
||||
}
|
||||
|
||||
private PackerRuntimeSnapshot backfillLoadedArtifactIdentity(PackerProjectContext project) {
|
||||
final PackerRuntimeSnapshot snapshot = runtimeRegistry.getOrLoad(project).snapshot();
|
||||
return backfillArtifactIdentity(snapshot)
|
||||
? runtimeRegistry.refresh(project).snapshot()
|
||||
: snapshot;
|
||||
}
|
||||
|
||||
private boolean backfillArtifactIdentity(PackerRuntimeSnapshot snapshot) {
|
||||
boolean changed = false;
|
||||
for (PackerRuntimeAsset runtimeAsset : snapshot.assets()) {
|
||||
try {
|
||||
changed = backfillArtifactIdentity(runtimeAsset) || changed;
|
||||
} catch (IOException exception) {
|
||||
throw new IllegalStateException("Unable to update artifact fingerprints for " + runtimeAsset.manifestPath(), exception);
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean backfillArtifactIdentity(PackerRuntimeAsset runtimeAsset) throws IOException {
|
||||
if (runtimeAsset.parsedDeclaration().declaration() == null || runtimeAsset.parsedDeclaration().declaration().artifacts().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final Path manifestPath = runtimeAsset.manifestPath();
|
||||
if (!Files.isRegularFile(manifestPath)) {
|
||||
return false;
|
||||
}
|
||||
final JsonNode rawManifest = mapper.readTree(manifestPath.toFile());
|
||||
if (!(rawManifest instanceof ObjectNode manifest) || !(manifest.path("artifacts") instanceof ArrayNode artifactsNode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Map<String, PackerRuntimeWalkFile> walkFilesByPath = new LinkedHashMap<>();
|
||||
runtimeAsset.walkProjection().buildCandidateFiles().forEach(file -> walkFilesByPath.put(file.relativePath(), file));
|
||||
final Set<String> artifactIds = new HashSet<>();
|
||||
for (JsonNode artifactNode : artifactsNode) {
|
||||
if (artifactNode.isObject()) {
|
||||
final String artifactId = artifactNode.path("artifact_id").asText("").trim();
|
||||
if (!artifactId.isBlank()) {
|
||||
artifactIds.add(artifactId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
for (JsonNode artifactNode : artifactsNode) {
|
||||
if (!(artifactNode instanceof ObjectNode artifactObject)) {
|
||||
continue;
|
||||
}
|
||||
final String file = artifactObject.path("file").asText("").trim();
|
||||
if (file.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (artifactObject.path("artifact_id").asText("").isBlank()) {
|
||||
artifactObject.put("artifact_id", nextArtifactId(artifactIds));
|
||||
changed = true;
|
||||
}
|
||||
final String fingerprint = Optional.ofNullable(walkFilesByPath.get(file))
|
||||
.map(PackerRuntimeWalkFile::fingerprint)
|
||||
.orElse(null);
|
||||
if (fingerprint != null && !fingerprint.isBlank() && !fingerprint.equals(artifactObject.path("fingerprint").asText(null))) {
|
||||
artifactObject.put("fingerprint", fingerprint);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private PackerRuntimeSnapshot createFrozenPackingSnapshot(PackerRuntimeSnapshot snapshot) {
|
||||
final PackerRuntimeAssetMaterializer materializer = new PackerRuntimeAssetMaterializer(new PackerAssetWalker(mapper));
|
||||
final List<PackerRuntimeAsset> assets = snapshot.assets().stream()
|
||||
@@ -1277,7 +1401,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
try {
|
||||
patchManifestArtifacts(manifest, request);
|
||||
patchManifestArtifacts(manifest, request, evaluation.resolved().runtimeAsset());
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
final var runtime = runtimeRegistry.update(project, (currentSnapshot, generation) -> runtimePatchService.afterUpdateAssetContract(
|
||||
currentSnapshot,
|
||||
@@ -1388,21 +1512,81 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
});
|
||||
}
|
||||
|
||||
private void patchManifestArtifacts(ObjectNode manifest, ApplyBankCompositionRequest request) {
|
||||
private void patchManifestArtifacts(
|
||||
ObjectNode manifest,
|
||||
ApplyBankCompositionRequest request,
|
||||
Optional<PackerRuntimeAsset> runtimeAsset) {
|
||||
manifest.remove("inputs");
|
||||
|
||||
final Map<String, ExistingArtifactEntry> existingArtifactsByFile = existingArtifactsByFile(manifest.path("artifacts"));
|
||||
final Map<String, PackerRuntimeWalkFile> walkFilesByPath = new LinkedHashMap<>();
|
||||
runtimeAsset.ifPresent(asset -> asset.walkProjection().buildCandidateFiles().forEach(file -> walkFilesByPath.put(file.relativePath(), file)));
|
||||
final var artifactsNode = manifest.putArray("artifacts");
|
||||
for (int index = 0; index < request.selectedFiles().size(); index += 1) {
|
||||
final String file = Objects.requireNonNullElse(request.selectedFiles().get(index), "").trim();
|
||||
if (file.isBlank() || !isTrustedRelativePath(file)) {
|
||||
throw new IllegalArgumentException("Selected artifact file paths must stay inside the asset root.");
|
||||
}
|
||||
final ExistingArtifactEntry existing = existingArtifactsByFile.get(file);
|
||||
final var artifactNode = artifactsNode.addObject();
|
||||
artifactNode.put("artifact_id", existing != null && existing.artifactId() != null ? existing.artifactId() : nextArtifactId());
|
||||
artifactNode.put("file", file);
|
||||
artifactNode.put("index", index);
|
||||
final String fingerprint = Optional.ofNullable(walkFilesByPath.get(file))
|
||||
.map(PackerRuntimeWalkFile::fingerprint)
|
||||
.orElse(existing == null ? null : existing.fingerprint());
|
||||
if (fingerprint != null && !fingerprint.isBlank()) {
|
||||
artifactNode.put("fingerprint", fingerprint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ExistingArtifactEntry> existingArtifactsByFile(JsonNode artifactsNode) {
|
||||
if (!(artifactsNode instanceof ArrayNode artifactsArray)) {
|
||||
return Map.of();
|
||||
}
|
||||
final Map<String, ExistingArtifactEntry> existing = new LinkedHashMap<>();
|
||||
for (JsonNode entry : artifactsArray) {
|
||||
if (!entry.isObject()) {
|
||||
continue;
|
||||
}
|
||||
final String file = entry.path("file").asText("").trim();
|
||||
if (file.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
existing.put(file, new ExistingArtifactEntry(
|
||||
blankToNull(entry.path("artifact_id").asText(null)),
|
||||
blankToNull(entry.path("fingerprint").asText(null))));
|
||||
}
|
||||
return Map.copyOf(existing);
|
||||
}
|
||||
|
||||
private String nextArtifactId() {
|
||||
return "art-" + UUID.randomUUID().toString().replace("-", "").substring(0, 12);
|
||||
}
|
||||
|
||||
private String nextArtifactId(Set<String> existingArtifactIds) {
|
||||
String artifactId = nextArtifactId();
|
||||
while (existingArtifactIds.contains(artifactId)) {
|
||||
artifactId = nextArtifactId();
|
||||
}
|
||||
existingArtifactIds.add(artifactId);
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
private String blankToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
final String trimmed = value.trim();
|
||||
return trimmed.isBlank() ? null : trimmed;
|
||||
}
|
||||
|
||||
private record ExistingArtifactEntry(
|
||||
String artifactId,
|
||||
String fingerprint) {
|
||||
}
|
||||
|
||||
private void patchManifestPipelinePalettes(ObjectNode manifest, ApplyPaletteOverhaulingRequest request) {
|
||||
final ObjectNode outputNode = mutableObject(manifest, "output");
|
||||
final ObjectNode pipelineNode = mutableObject(outputNode, "pipeline");
|
||||
|
||||
+9
-1
@@ -404,8 +404,10 @@ public final class PackerAssetDeclarationParser {
|
||||
true));
|
||||
continue;
|
||||
}
|
||||
final JsonNode artifactIdNode = entry.path("artifact_id");
|
||||
final JsonNode fileNode = entry.path("file");
|
||||
final JsonNode indexNode = entry.path("index");
|
||||
final JsonNode fingerprintNode = entry.path("fingerprint");
|
||||
if (!fileNode.isTextual() || fileNode.asText().isBlank() || !indexNode.isInt() || indexNode.asInt() < 0) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
@@ -425,7 +427,13 @@ public final class PackerAssetDeclarationParser {
|
||||
true));
|
||||
continue;
|
||||
}
|
||||
result.add(new PackerAssetArtifactSelection(relativePath, indexNode.asInt()));
|
||||
final String artifactId = artifactIdNode.isTextual() && !artifactIdNode.asText().isBlank()
|
||||
? artifactIdNode.asText().trim()
|
||||
: null;
|
||||
final String fingerprint = fingerprintNode.isTextual() && !fingerprintNode.asText().isBlank()
|
||||
? fingerprintNode.asText().trim()
|
||||
: null;
|
||||
result.add(new PackerAssetArtifactSelection(artifactId, relativePath, indexNode.asInt(), fingerprint));
|
||||
}
|
||||
result.sort(Comparator.comparingInt(PackerAssetArtifactSelection::index));
|
||||
return List.copyOf(result);
|
||||
|
||||
+50
-14
@@ -1,5 +1,6 @@
|
||||
package p.packer.services;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -16,6 +17,8 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public final class PackerAssetDetailsService {
|
||||
private static final ObjectMapper GLYPH_MATERIAL_MAPPER = new ObjectMapper();
|
||||
|
||||
private final PackerRuntimeRegistry runtimeRegistry;
|
||||
private final PackerAssetReferenceResolver assetReferenceResolver;
|
||||
|
||||
@@ -48,6 +51,7 @@ public final class PackerAssetDetailsService {
|
||||
diagnostics.addAll(parsed.diagnostics());
|
||||
diagnostics.addAll(runtimeAsset.walkDiagnostics());
|
||||
appendWalkFileDiagnostics(runtimeAsset, diagnostics);
|
||||
diagnostics.addAll(new PackerGlyphMaterialSupport(GLYPH_MATERIAL_MAPPER).validate(runtimeAsset));
|
||||
if (!parsed.valid()) {
|
||||
return failureResult(project, request.assetReference(), resolved, diagnostics);
|
||||
}
|
||||
@@ -149,8 +153,9 @@ public final class PackerAssetDetailsService {
|
||||
.map(this::toBankCompositionFile)
|
||||
.toList();
|
||||
|
||||
final List<PackerBankCompositionFile> selectedFiles = selectedPathsFor(declaration).stream()
|
||||
.map(path -> resolveSelectedBankFile(runtimeAsset.assetRoot(), path, walkFilesByPath, assetCacheEntry))
|
||||
final List<PackerBankCompositionFile> selectedFiles = declaration.artifacts().stream()
|
||||
.sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index))
|
||||
.map(artifact -> resolveSelectedBankFile(runtimeAsset.assetRoot(), artifact, walkFilesByPath, assetCacheEntry))
|
||||
.flatMap(Optional::stream)
|
||||
.toList();
|
||||
|
||||
@@ -160,13 +165,6 @@ public final class PackerAssetDetailsService {
|
||||
walkProjection.measuredBankSizeBytes());
|
||||
}
|
||||
|
||||
private List<String> selectedPathsFor(PackerAssetDeclaration declaration) {
|
||||
return declaration.artifacts().stream()
|
||||
.sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index))
|
||||
.map(PackerAssetArtifactSelection::file)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> resolvePipelinePalettes(PackerAssetDeclaration declaration) {
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
if (!(palettesNode instanceof ArrayNode palettesArray)) {
|
||||
@@ -219,16 +217,17 @@ public final class PackerAssetDetailsService {
|
||||
|
||||
private Optional<PackerBankCompositionFile> resolveSelectedBankFile(
|
||||
Path assetRoot,
|
||||
String relativePath,
|
||||
PackerAssetArtifactSelection artifact,
|
||||
Map<String, PackerRuntimeWalkFile> walkFilesByPath,
|
||||
Optional<PackerAssetCacheEntry> assetCacheEntry) {
|
||||
final String relativePath = artifact.file();
|
||||
final PackerRuntimeWalkFile runtimeWalkFile = walkFilesByPath.get(relativePath);
|
||||
if (runtimeWalkFile != null) {
|
||||
return Optional.of(toBankCompositionFile(runtimeWalkFile));
|
||||
return Optional.of(toSelectedBankCompositionFile(runtimeWalkFile, artifact));
|
||||
}
|
||||
final Optional<PackerFileCacheEntry> cachedFile = assetCacheEntry.flatMap(entry -> entry.findFile(relativePath));
|
||||
if (cachedFile.isPresent()) {
|
||||
return Optional.of(toBankCompositionFile(cachedFile.get()));
|
||||
return Optional.of(toSelectedBankCompositionFile(cachedFile.get(), artifact));
|
||||
}
|
||||
|
||||
final Path filePath = assetRoot.resolve(relativePath).toAbsolutePath().normalize();
|
||||
@@ -242,8 +241,8 @@ public final class PackerAssetDetailsService {
|
||||
filePath.getFileName().toString(),
|
||||
Files.size(filePath),
|
||||
Files.getLastModifiedTime(filePath).toMillis(),
|
||||
null,
|
||||
Map.of()));
|
||||
artifact.fingerprint(),
|
||||
selectedArtifactMetadata(artifact, Map.of())));
|
||||
} catch (Exception exception) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -269,6 +268,43 @@ public final class PackerAssetDetailsService {
|
||||
file.metadata());
|
||||
}
|
||||
|
||||
private PackerBankCompositionFile toSelectedBankCompositionFile(
|
||||
PackerRuntimeWalkFile file,
|
||||
PackerAssetArtifactSelection artifact) {
|
||||
return new PackerBankCompositionFile(
|
||||
file.relativePath(),
|
||||
Path.of(file.relativePath()).getFileName().toString(),
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
selectedArtifactMetadata(artifact, file.metadata()));
|
||||
}
|
||||
|
||||
private PackerBankCompositionFile toSelectedBankCompositionFile(
|
||||
PackerFileCacheEntry file,
|
||||
PackerAssetArtifactSelection artifact) {
|
||||
return new PackerBankCompositionFile(
|
||||
file.relativePath(),
|
||||
Path.of(file.relativePath()).getFileName().toString(),
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
selectedArtifactMetadata(artifact, file.metadata()));
|
||||
}
|
||||
|
||||
private Map<String, Object> selectedArtifactMetadata(
|
||||
PackerAssetArtifactSelection artifact,
|
||||
Map<String, Object> metadata) {
|
||||
final Map<String, Object> decorated = new LinkedHashMap<>(metadata);
|
||||
if (artifact.artifactId() != null) {
|
||||
decorated.put("artifactId", artifact.artifactId());
|
||||
}
|
||||
if (artifact.fingerprint() != null) {
|
||||
decorated.put("selectedFingerprint", artifact.fingerprint());
|
||||
}
|
||||
return Map.copyOf(decorated);
|
||||
}
|
||||
|
||||
private List<PackerCodecConfigurationField> metadataFields(
|
||||
List<PackerCodecConfigurationField> definitions,
|
||||
Map<String, String> outputMetadata) {
|
||||
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
package p.packer.services;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.packer.messages.diagnostics.PackerDiagnosticCategory;
|
||||
import p.packer.messages.diagnostics.PackerDiagnosticSeverity;
|
||||
import p.packer.models.PackerAssetArtifactSelection;
|
||||
import p.packer.models.PackerAssetDeclaration;
|
||||
import p.packer.models.PackerDiagnostic;
|
||||
import p.packer.models.PackerRuntimeAsset;
|
||||
import p.packer.models.PackerRuntimeWalkFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
final class PackerGlyphMaterialSupport {
|
||||
static final String GLYPH_MATERIAL_SUPPORT_FILE = "glyph-material.json";
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
PackerGlyphMaterialSupport(ObjectMapper mapper) {
|
||||
this.mapper = Objects.requireNonNull(mapper, "mapper");
|
||||
}
|
||||
|
||||
List<PackerDiagnostic> validate(PackerRuntimeAsset runtimeAsset) {
|
||||
final PackerAssetDeclaration declaration = runtimeAsset.parsedDeclaration().declaration();
|
||||
if (declaration == null || declaration.assetFamily() != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
return List.of();
|
||||
}
|
||||
final Path supportFile = runtimeAsset.assetRoot().resolve(GLYPH_MATERIAL_SUPPORT_FILE);
|
||||
if (!Files.isRegularFile(supportFile)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
final List<PackerDiagnostic> diagnostics = new ArrayList<>();
|
||||
final Optional<GlyphMaterialFile> parsed = readSupportFile(supportFile, diagnostics);
|
||||
if (parsed.isEmpty()) {
|
||||
return List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
final Map<String, PackerAssetArtifactSelection> selectedArtifactsById = new LinkedHashMap<>();
|
||||
for (PackerAssetArtifactSelection artifact : declaration.artifacts()) {
|
||||
if (artifact.artifactId() != null) {
|
||||
selectedArtifactsById.put(artifact.artifactId(), artifact);
|
||||
}
|
||||
}
|
||||
final Map<String, PackerRuntimeWalkFile> selectedFilesByPath = new LinkedHashMap<>();
|
||||
runtimeAsset.walkProjection().buildCandidateFiles().forEach(file -> selectedFilesByPath.put(file.relativePath(), file));
|
||||
|
||||
final Map<String, SchemaEvaluation> schemaEvaluations = new LinkedHashMap<>();
|
||||
for (GlyphMaterialSchema schema : parsed.get().schemas()) {
|
||||
final boolean declaredInconsistent = schema.status() == GlyphMaterialSchemaStatus.INCONSISTENT;
|
||||
boolean drifted = false;
|
||||
for (GlyphMaterialArtifactBinding binding : schema.artifactBindings()) {
|
||||
final PackerAssetArtifactSelection artifact = selectedArtifactsById.get(binding.artifactId());
|
||||
if (artifact == null) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material schema '" + schema.schemaId() + "' references unknown selected artifact id '" + binding.artifactId() + "'.",
|
||||
supportFile));
|
||||
drifted = true;
|
||||
continue;
|
||||
}
|
||||
final PackerRuntimeWalkFile currentFile = selectedFilesByPath.get(artifact.file());
|
||||
final String currentFingerprint = currentFile != null
|
||||
? currentFile.fingerprint()
|
||||
: artifact.fingerprint();
|
||||
if (currentFingerprint == null || !currentFingerprint.equals(binding.fingerprint())) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material schema '" + schema.schemaId() + "' is inconsistent because artifact '" + binding.artifactId() + "' drifted.",
|
||||
supportFile));
|
||||
drifted = true;
|
||||
}
|
||||
}
|
||||
if (declaredInconsistent) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material schema '" + schema.schemaId() + "' is marked inconsistent.",
|
||||
supportFile));
|
||||
}
|
||||
schemaEvaluations.put(schema.schemaId(), new SchemaEvaluation(schema, declaredInconsistent || drifted));
|
||||
}
|
||||
|
||||
for (GlyphMaterialPalette palette : parsed.get().palettes()) {
|
||||
final SchemaEvaluation schema = schemaEvaluations.get(palette.schemaId());
|
||||
if (schema == null) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material palette '" + palette.paletteId() + "' references unknown schema '" + palette.schemaId() + "'.",
|
||||
supportFile));
|
||||
continue;
|
||||
}
|
||||
if (palette.colors().size() != schema.schema().materialIndices().size()) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material palette '" + palette.paletteId() + "' must define exactly "
|
||||
+ schema.schema().materialIndices().size() + " colors for schema '" + palette.schemaId() + "'.",
|
||||
supportFile));
|
||||
}
|
||||
if (palette.version() < schema.schema().version()) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material palette '" + palette.paletteId() + "' is stale because version "
|
||||
+ palette.version() + " is older than schema '" + palette.schemaId() + "' version "
|
||||
+ schema.schema().version() + ".",
|
||||
supportFile));
|
||||
}
|
||||
if (schema.inconsistent()) {
|
||||
diagnostics.add(blocking(
|
||||
"Glyph material palette '" + palette.paletteId() + "' is invalid because schema '"
|
||||
+ palette.schemaId() + "' is inconsistent.",
|
||||
supportFile));
|
||||
}
|
||||
}
|
||||
|
||||
return List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
private Optional<GlyphMaterialFile> readSupportFile(Path supportFile, List<PackerDiagnostic> diagnostics) {
|
||||
final JsonNode root;
|
||||
try {
|
||||
root = mapper.readTree(supportFile.toFile());
|
||||
} catch (IOException exception) {
|
||||
diagnostics.add(blocking("Unable to parse glyph-material.json: " + exception.getMessage(), supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
if (root == null || !root.isObject()) {
|
||||
diagnostics.add(blocking("glyph-material.json must contain a JSON object at the root.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!(root.path("schemas") instanceof ArrayNode schemasNode) || !(root.path("palettes") instanceof ArrayNode palettesNode)) {
|
||||
diagnostics.add(blocking("glyph-material.json must define array fields 'schemas' and 'palettes'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final List<GlyphMaterialSchema> schemas = new ArrayList<>();
|
||||
final Set<String> schemaIds = new HashSet<>();
|
||||
for (JsonNode schemaNode : schemasNode) {
|
||||
final Optional<GlyphMaterialSchema> schema = parseSchema(schemaNode, supportFile, diagnostics);
|
||||
if (schema.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!schemaIds.add(schema.get().schemaId())) {
|
||||
diagnostics.add(blocking("glyph-material.json contains duplicate schema_id '" + schema.get().schemaId() + "'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
schemas.add(schema.get());
|
||||
}
|
||||
|
||||
final List<GlyphMaterialPalette> palettes = new ArrayList<>();
|
||||
final Set<String> paletteIds = new HashSet<>();
|
||||
for (JsonNode paletteNode : palettesNode) {
|
||||
final Optional<GlyphMaterialPalette> palette = parsePalette(paletteNode, schemaIds, supportFile, diagnostics);
|
||||
if (palette.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!paletteIds.add(palette.get().paletteId())) {
|
||||
diagnostics.add(blocking("glyph-material.json contains duplicate palette_id '" + palette.get().paletteId() + "'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
palettes.add(palette.get());
|
||||
}
|
||||
return Optional.of(new GlyphMaterialFile(List.copyOf(schemas), List.copyOf(palettes)));
|
||||
}
|
||||
|
||||
private Optional<GlyphMaterialSchema> parseSchema(
|
||||
JsonNode schemaNode,
|
||||
Path supportFile,
|
||||
List<PackerDiagnostic> diagnostics) {
|
||||
if (!schemaNode.isObject()) {
|
||||
diagnostics.add(blocking("Each glyph material schema must be an object.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final String schemaId = schemaNode.path("schema_id").asText("").trim();
|
||||
final GlyphMaterialSchemaStatus status = GlyphMaterialSchemaStatus.fromManifestValue(schemaNode.path("status").asText(null));
|
||||
final int version = schemaNode.path("version").asInt(0);
|
||||
if (schemaId.isBlank() || status == null || version <= 0) {
|
||||
diagnostics.add(blocking("Each glyph material schema must define non-blank 'schema_id', valid 'status', and positive 'version'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final JsonNode materialIndicesNode = schemaNode.path("material_indices");
|
||||
if (!materialIndicesNode.isObject()) {
|
||||
diagnostics.add(blocking("Schema '" + schemaId + "' must define object 'material_indices'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final Map<Integer, String> materialIndices = new TreeMap<>();
|
||||
materialIndicesNode.fields().forEachRemaining(entry -> {
|
||||
try {
|
||||
final int index = Integer.parseInt(entry.getKey());
|
||||
final String color = normalizeHtmlColor(entry.getValue().asText(null));
|
||||
if (index >= 1 && index <= 15 && color != null) {
|
||||
materialIndices.put(index, color);
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
// validated below
|
||||
}
|
||||
});
|
||||
if (materialIndices.isEmpty()
|
||||
|| materialIndices.size() != materialIndicesNode.size()
|
||||
|| !denseIndices(materialIndices.keySet())) {
|
||||
diagnostics.add(blocking("Schema '" + schemaId + "' must define dense material_indices in range 1..15 using #RRGGBB values.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!(schemaNode.path("artifact_bindings") instanceof ArrayNode bindingsNode) || bindingsNode.isEmpty()) {
|
||||
diagnostics.add(blocking("Schema '" + schemaId + "' must define non-empty 'artifact_bindings'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final List<GlyphMaterialArtifactBinding> bindings = new ArrayList<>();
|
||||
final Set<String> artifactIds = new HashSet<>();
|
||||
for (JsonNode bindingNode : bindingsNode) {
|
||||
final String artifactId = bindingNode.path("artifact_id").asText("").trim();
|
||||
final String fingerprint = bindingNode.path("fingerprint").asText("").trim();
|
||||
if (artifactId.isBlank() || fingerprint.isBlank() || !artifactIds.add(artifactId)) {
|
||||
diagnostics.add(blocking("Schema '" + schemaId + "' must define unique artifact bindings with 'artifact_id' and 'fingerprint'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
bindings.add(new GlyphMaterialArtifactBinding(artifactId, fingerprint));
|
||||
}
|
||||
return Optional.of(new GlyphMaterialSchema(schemaId, status, version, Map.copyOf(materialIndices), List.copyOf(bindings)));
|
||||
}
|
||||
|
||||
private Optional<GlyphMaterialPalette> parsePalette(
|
||||
JsonNode paletteNode,
|
||||
Set<String> schemaIds,
|
||||
Path supportFile,
|
||||
List<PackerDiagnostic> diagnostics) {
|
||||
if (!paletteNode.isObject()) {
|
||||
diagnostics.add(blocking("Each glyph material palette must be an object.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final String paletteId = paletteNode.path("palette_id").asText("").trim();
|
||||
final String schemaId = paletteNode.path("schema_id").asText("").trim();
|
||||
final int version = paletteNode.path("version").asInt(0);
|
||||
if (paletteId.isBlank() || schemaId.isBlank() || version <= 0 || !schemaIds.contains(schemaId)) {
|
||||
diagnostics.add(blocking("Each glyph material palette must define non-blank 'palette_id', valid 'schema_id', and positive 'version'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!(paletteNode.path("colors") instanceof ArrayNode colorsNode)) {
|
||||
diagnostics.add(blocking("Palette '" + paletteId + "' must define array 'colors'.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
final List<String> colors = new ArrayList<>();
|
||||
for (JsonNode colorNode : colorsNode) {
|
||||
final String color = normalizeHtmlColor(colorNode.asText(null));
|
||||
if (color == null) {
|
||||
diagnostics.add(blocking("Palette '" + paletteId + "' must use #RRGGBB colors.", supportFile));
|
||||
return Optional.empty();
|
||||
}
|
||||
colors.add(color);
|
||||
}
|
||||
return Optional.of(new GlyphMaterialPalette(paletteId, schemaId, version, List.copyOf(colors)));
|
||||
}
|
||||
|
||||
private static PackerDiagnostic blocking(String message, Path path) {
|
||||
return new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
message,
|
||||
path,
|
||||
true);
|
||||
}
|
||||
|
||||
private boolean denseIndices(Set<Integer> indices) {
|
||||
int expected = 1;
|
||||
for (Integer index : new TreeSet<>(indices)) {
|
||||
if (index == null || index != expected) {
|
||||
return false;
|
||||
}
|
||||
expected += 1;
|
||||
}
|
||||
return !indices.isEmpty();
|
||||
}
|
||||
|
||||
private String normalizeHtmlColor(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
final String normalized = value.trim().toUpperCase();
|
||||
return normalized.matches("^#[0-9A-F]{6}$") ? normalized : null;
|
||||
}
|
||||
|
||||
private record GlyphMaterialFile(
|
||||
List<GlyphMaterialSchema> schemas,
|
||||
List<GlyphMaterialPalette> palettes) {
|
||||
}
|
||||
|
||||
private record GlyphMaterialSchema(
|
||||
String schemaId,
|
||||
GlyphMaterialSchemaStatus status,
|
||||
int version,
|
||||
Map<Integer, String> materialIndices,
|
||||
List<GlyphMaterialArtifactBinding> artifactBindings) {
|
||||
}
|
||||
|
||||
private record GlyphMaterialPalette(
|
||||
String paletteId,
|
||||
String schemaId,
|
||||
int version,
|
||||
List<String> colors) {
|
||||
}
|
||||
|
||||
private record GlyphMaterialArtifactBinding(
|
||||
String artifactId,
|
||||
String fingerprint) {
|
||||
}
|
||||
|
||||
private record SchemaEvaluation(
|
||||
GlyphMaterialSchema schema,
|
||||
boolean inconsistent) {
|
||||
}
|
||||
|
||||
private enum GlyphMaterialSchemaStatus {
|
||||
OK("ok"),
|
||||
INCONSISTENT("inconsistent");
|
||||
|
||||
private final String manifestValue;
|
||||
|
||||
GlyphMaterialSchemaStatus(String manifestValue) {
|
||||
this.manifestValue = manifestValue;
|
||||
}
|
||||
|
||||
static GlyphMaterialSchemaStatus fromManifestValue(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
for (GlyphMaterialSchemaStatus candidate : values()) {
|
||||
if (candidate.manifestValue.equalsIgnoreCase(value.trim())) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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