asset details (WIP)

This commit is contained in:
2026-03-24 13:42:53 +00:00
parent fb56b0eb72
commit b07642f35c
160 changed files with 701 additions and 1109 deletions
@@ -29,7 +29,7 @@ public abstract class PackerAbstractBankWalker<R> {
}
protected abstract Set<String> getSupportedMimeTypes();
protected abstract PackerProbeResult processFileProbe(PackerFileProbe fileProbe, R requirements);
protected abstract PackerProbeResult processFileProbe(PackerFileProbe fileProbe, Path assetRoot, R requirements);
private Optional<PackerFileProbe> getFileProbeIfSupported(
final Path filePath,
@@ -79,7 +79,7 @@ public abstract class PackerAbstractBankWalker<R> {
cachedEntry.get().diagnostics()));
continue;
}
probeResults.add(processFileProbe(fileProbe, requirements));
probeResults.add(processFileProbe(fileProbe, assetRoot, requirements));
}
} catch (IOException exception) {
diagnostics.add(new PackerDiagnostic(
@@ -26,6 +26,7 @@ public class PackerSoundBankWalker extends PackerAbstractBankWalker<PackerSoundB
@Override
protected PackerProbeResult processFileProbe(
final PackerFileProbe fileProbe,
final java.nio.file.Path assetRoot,
final PackerSoundBankRequirements requirements) {
final List<PackerDiagnostic> diagnostics = new ArrayList<>();
return new PackerProbeResult(fileProbe, Map.of(), diagnostics);
@@ -31,6 +31,7 @@ public class PackerTileBankWalker extends PackerAbstractBankWalker<PackerTileBan
@Override
protected PackerProbeResult processFileProbe(
final PackerFileProbe fileProbe,
final Path assetRoot,
final PackerTileBankRequirements requirements) {
final List<PackerDiagnostic> diagnostics = new ArrayList<>();
@@ -123,16 +124,20 @@ public class PackerTileBankWalker extends PackerAbstractBankWalker<PackerTileBan
final var tile = new PackerTileIndexedV1(image.getWidth(), image.getHeight(), paletteIndices);
final var palette = buildPalette(paletteIndexByRgb);
serializeProbeArtifacts(fileProbe, tile, palette, diagnostics);
// Disabled for now: derived tile/palette JSON artifacts are not emitted during normal walks.
// If we want filesystem-side debug artifacts again, uncomment the call below.
// serializeProbeArtifacts(fileProbe, assetRoot, tile, palette, diagnostics);
return new PackerProbeResult(fileProbe, Map.of("tile", tile, "palette", palette), diagnostics);
}
/*
private void serializeProbeArtifacts(
final PackerFileProbe fileProbe,
final Path assetRoot,
final PackerTileIndexedV1 tile,
final PackerPaletteV1 palette,
final List<PackerDiagnostic> diagnostics) {
final Path basePath = baseOutputPath(fileProbe.path());
final Path basePath = baseOutputPath(assetRoot, fileProbe.path());
final Path tileOutputPath = Path.of(basePath + ".tile.json");
final Path paletteOutputPath = Path.of(basePath + ".palette.json");
@@ -152,17 +157,32 @@ public class PackerTileBankWalker extends PackerAbstractBankWalker<PackerTileBan
}
}
private Path baseOutputPath(final Path sourcePath) {
private Path baseOutputPath(final Path assetRoot, final Path sourcePath) {
final Path assetsRoot = assetsRoot(assetRoot);
final Path relativeSourcePath = assetsRoot.relativize(sourcePath.toAbsolutePath().normalize());
final String fileName = sourcePath.getFileName().toString();
final int extensionStart = fileName.lastIndexOf('.');
final String outputBaseName = extensionStart > 0 ? fileName.substring(0, extensionStart) : fileName;
final Path parent = sourcePath.getParent();
if (parent == null) {
return Path.of(outputBaseName);
final Path relativeParent = relativeSourcePath.getParent();
final Path outputRoot = assetsRoot.resolve(".prometeu");
if (relativeParent == null) {
return outputRoot.resolve(outputBaseName);
}
return parent.resolve(outputBaseName);
return outputRoot.resolve(relativeParent).resolve(outputBaseName);
}
private Path assetsRoot(final Path assetRoot) {
Path current = assetRoot.toAbsolutePath().normalize();
while (current != null && current.getFileName() != null) {
if ("assets".equals(current.getFileName().toString())) {
return current;
}
current = current.getParent();
}
throw new IllegalStateException("Unable to resolve assets root for tile artifact output: " + assetRoot);
}
*/
private Map<String, Object> toTilePayload(final PackerTileIndexedV1 tile) {
final List<Integer> indices = new ArrayList<>(tile.paletteIndices().length);
for (final byte value : tile.paletteIndices()) {
@@ -171,6 +171,14 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return writeCoordinator.execute(project, () -> deleteAssetInWriteLane(safeRequest, events));
}
@Override
public UpdateAssetBuildParticipationResult updateAssetBuildParticipation(UpdateAssetBuildParticipationRequest request) {
final UpdateAssetBuildParticipationRequest safeRequest = Objects.requireNonNull(request, "request");
final PackerProjectContext project = safeRequest.project();
final PackerOperationEventEmitter events = new PackerOperationEventEmitter(project, eventSink);
return writeCoordinator.execute(project, () -> updateAssetBuildParticipationInWriteLane(safeRequest, events));
}
private CreateAssetResult createAssetInWriteLane(
CreateAssetRequest request,
PackerOperationEventEmitter events) {
@@ -347,6 +355,57 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
}
}
private UpdateAssetBuildParticipationResult updateAssetBuildParticipationInWriteLane(
UpdateAssetBuildParticipationRequest request,
PackerOperationEventEmitter events) {
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());
final Path assetRoot = evaluation.resolved().assetRoot();
final String relativeAssetRoot = relativeAssetRoot(project, assetRoot);
if (evaluation.resolved().registryEntry().isEmpty()) {
return new UpdateAssetBuildParticipationResult(
PackerOperationStatus.FAILED,
"Asset must be registered before changing build participation.",
null);
}
if (!evaluation.canDelete()) {
return new UpdateAssetBuildParticipationResult(
PackerOperationStatus.FAILED,
Objects.requireNonNullElse(evaluation.reason(), "Asset build participation cannot be updated."),
null);
}
try {
final PackerRegistryEntry currentEntry = evaluation.resolved().registryEntry().orElseThrow();
final PackerRegistryEntry updatedEntry = new PackerRegistryEntry(
currentEntry.assetId(),
currentEntry.assetUuid(),
currentEntry.root(),
request.includedInBuild());
final PackerRegistryState registry = workspaceFoundation.loadRegistry(project);
final PackerRegistryState updatedRegistry = replaceRegistryEntryRoot(registry, updatedEntry);
workspaceFoundation.saveRegistry(project, updatedRegistry);
runtimeRegistry.update(project, (currentSnapshot, generation) -> new PackerRuntimeSnapshot(
generation,
updatedRegistry,
currentSnapshot.assets(),
currentSnapshot.cacheState()));
final UpdateAssetBuildParticipationResult result = new UpdateAssetBuildParticipationResult(
PackerOperationStatus.SUCCESS,
(request.includedInBuild() ? "Included" : "Excluded") + " asset in build: " + relativeAssetRoot,
AssetReference.forAssetId(updatedEntry.assetId()));
events.emit(PackerEventKind.ACTION_APPLIED, result.summary(), List.of(relativeAssetRoot));
return result;
} catch (RuntimeException exception) {
return new UpdateAssetBuildParticipationResult(
PackerOperationStatus.FAILED,
"Unable to update asset build participation: " + exception.getMessage(),
null);
}
}
private MoveAssetResult moveAssetInWriteLane(
MoveAssetRequest request,
PackerOperationEventEmitter events) {