asset details (WIP)
This commit is contained in:
@@ -19,6 +19,8 @@ public interface PackerWorkspaceService {
|
||||
|
||||
DeleteAssetResult deleteAsset(DeleteAssetRequest request);
|
||||
|
||||
UpdateAssetBuildParticipationResult updateAssetBuildParticipation(UpdateAssetBuildParticipationRequest request);
|
||||
|
||||
UpdateAssetContractResponse updateAssetContract(UpdateAssetContractRequest request);
|
||||
|
||||
ApplyBankCompositionResponse applyBankComposition(ApplyBankCompositionRequest request);
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package p.packer.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record UpdateAssetBuildParticipationRequest(
|
||||
PackerProjectContext project,
|
||||
AssetReference assetReference,
|
||||
boolean includedInBuild) {
|
||||
|
||||
public UpdateAssetBuildParticipationRequest {
|
||||
Objects.requireNonNull(project, "project");
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.packer.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record UpdateAssetBuildParticipationResult(
|
||||
PackerOperationStatus status,
|
||||
String summary,
|
||||
AssetReference assetReference) {
|
||||
|
||||
public UpdateAssetBuildParticipationResult {
|
||||
Objects.requireNonNull(status, "status");
|
||||
summary = Objects.requireNonNull(summary, "summary").trim();
|
||||
if (summary.isBlank()) {
|
||||
throw new IllegalArgumentException("summary must not be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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(
|
||||
|
||||
+1
@@ -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);
|
||||
|
||||
+27
-7
@@ -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()) {
|
||||
|
||||
+59
@@ -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) {
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ final class PackerAbstractBankWalkerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PackerProbeResult processFileProbe(PackerFileProbe fileProbe, String requirements) {
|
||||
protected PackerProbeResult processFileProbe(PackerFileProbe fileProbe, java.nio.file.Path assetRoot, String requirements) {
|
||||
processCount += 1;
|
||||
return new PackerProbeResult(
|
||||
fileProbe,
|
||||
|
||||
+26
@@ -247,6 +247,32 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertEquals(1, loader.loadCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssetBuildParticipationPatchesRegistryAndLoadedSnapshotWithoutWholeProjectReload() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("update-build-participation"));
|
||||
final CountingLoader loader = countingLoader();
|
||||
final FileSystemPackerWorkspaceService service = service(ignored -> { }, loader);
|
||||
|
||||
service.listAssets(new ListAssetsRequest(project(projectRoot)));
|
||||
assertEquals(1, loader.loadCount());
|
||||
|
||||
final var result = service.updateAssetBuildParticipation(new UpdateAssetBuildParticipationRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1),
|
||||
false));
|
||||
|
||||
assertEquals(PackerOperationStatus.SUCCESS, result.status());
|
||||
assertEquals(1, loader.loadCount());
|
||||
|
||||
final var detailsResult = service.getAssetDetails(new GetAssetDetailsRequest(
|
||||
project(projectRoot),
|
||||
AssetReference.forAssetId(1)));
|
||||
assertEquals(PackerBuildParticipation.EXCLUDED, detailsResult.details().summary().buildParticipation());
|
||||
|
||||
final var registry = MAPPER.readTree(projectRoot.resolve("assets/.prometeu/index.json").toFile());
|
||||
assertFalse(registry.path("assets").get(0).path("included_in_build").asBoolean(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssetContractDropsPersistedBankCompositionWhenContractFingerprintChanges() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("update-contract-drops-bank"));
|
||||
|
||||
+4
@@ -78,6 +78,10 @@ final class PackerAssetDetailsServiceTest {
|
||||
.anyMatch(file -> file.path().equals("confirm.png")));
|
||||
assertTrue(result.details().bankComposition().availableFiles().stream()
|
||||
.allMatch(file -> !file.displayName().isBlank()));
|
||||
assertFalse(Files.exists(projectRoot.resolve("assets/ui/atlas/confirm.tile.json")));
|
||||
assertFalse(Files.exists(projectRoot.resolve("assets/ui/atlas/confirm.palette.json")));
|
||||
assertFalse(Files.exists(projectRoot.resolve("assets/.prometeu/ui/atlas/confirm.tile.json")));
|
||||
assertFalse(Files.exists(projectRoot.resolve("assets/.prometeu/ui/atlas/confirm.palette.json")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user