feat(pbs): add sprite animation and shared Studio authoring

Implement DEC-0084 with factory-only Sprite/Animator structs, complete result
lowering, validated animation sidecars, generated PBS factories and JavaFX/MCP
authoring through shared services.

Qualify native dev/release with ordinary and optimized producers, zero-allocation
playback, private-cycle reclamation, canonical Composer pixels, installed JARs
and JavaFX lifecycle. Preserve the runtime checkout and existing host ABI.
This commit is contained in:
2026-11-05 15:16:07 +00:00
parent 1d8b8c2101
commit bf31184d4d
151 changed files with 4823 additions and 98 deletions
@@ -3,6 +3,14 @@ package p.packer;
import p.packer.messages.*;
public interface PackerWorkspaceService {
default p.packer.dtos.PackerGlyphBankLayoutDTO getGlyphBankLayout(GetGlyphBankLayoutRequest request) {
throw new UnsupportedOperationException("Glyph bank layout resolver is not configured");
}
default <T> T withGlyphBankLayout(GetGlyphBankLayoutRequest request, java.util.function.Function<p.packer.dtos.PackerGlyphBankLayoutDTO,T> work) {
throw new UnsupportedOperationException("Project-exclusive layout access is not configured");
}
InitWorkspaceResult initWorkspace(InitWorkspaceRequest request);
ListAssetsResult listAssets(ListAssetsRequest request);
@@ -0,0 +1,13 @@
package p.packer.dtos;
import java.nio.file.Path;
import java.util.*;
/** Immutable effective composition and pixels from the same packing helpers. */
public record PackerGlyphBankLayoutDTO(UUID assetUuid, String revision, Path assetRoot,
List<Glyph> glyphs, byte[] rgbaPalettes) {
public PackerGlyphBankLayoutDTO { glyphs=List.copyOf(glyphs);rgbaPalettes=rgbaPalettes.clone(); }
@Override public byte[] rgbaPalettes(){return rgbaPalettes.clone();}
public record Glyph(String artifactId,int glyphId,String fingerprint,Path imagePath,int width,int height,byte[] indices) {
public Glyph { indices=indices.clone(); }
@Override public byte[] indices(){return indices.clone();}
}
}
@@ -0,0 +1,6 @@
package p.packer.messages;
import java.util.UUID;
import java.util.Objects;
public record GetGlyphBankLayoutRequest(PackerProjectContext project, UUID assetUuid) {
public GetGlyphBankLayoutRequest { Objects.requireNonNull(project); Objects.requireNonNull(assetUuid); }
}
@@ -47,7 +47,8 @@ public abstract class PackerAbstractBankWalker<R> {
private List<Path> retrieveValidPaths(final Path assetRoot) throws IOException {
try (final var paths = Files.list(assetRoot)
.filter(Files::isRegularFile)
.filter(path -> !isAssetManifest(path))) {
.filter(path -> !isAssetManifest(path))
.filter(path -> !path.getFileName().toString().equals("animations.studio.json"))) {
return paths.toList();
}
}
@@ -150,6 +150,56 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
PackerReadMessageMapper.toDiagnosticDTOs(diagnostics));
}
@Override
public p.packer.dtos.PackerGlyphBankLayoutDTO getGlyphBankLayout(GetGlyphBankLayoutRequest request) {
return withGlyphBankLayout(request, java.util.function.Function.identity());
}
@Override
public <T> T withGlyphBankLayout(GetGlyphBankLayoutRequest request, java.util.function.Function<p.packer.dtos.PackerGlyphBankLayoutDTO,T> work) {
Objects.requireNonNull(request); Objects.requireNonNull(work);
return writeCoordinator.execute(request.project(), () -> work.apply(readGlyphBankLayout(request)));
}
private p.packer.dtos.PackerGlyphBankLayoutDTO readGlyphBankLayout(GetGlyphBankLayoutRequest request) {
// Refresh observes external composition/content changes without backfilling identities.
var snapshot = runtimeRegistry.refresh(request.project()).snapshot();
var matching = snapshot.assets().stream().filter(a -> a.registryEntry().isPresent()
&& request.assetUuid().toString().equals(a.registryEntry().get().assetUuid())).toList();
if (matching.size()!=1) throw new IllegalArgumentException("Bank UUID must identify one registered asset");
var asset=matching.getFirst(); var parsed=asset.parsedDeclaration();
if (!parsed.valid() || parsed.declaration().assetFamily()!=AssetFamilyCatalog.GLYPH_BANK)
throw new IllegalArgumentException("Registered asset is not a valid glyph bank: "+parsed.diagnostics());
var declaration=parsed.declaration();
if (!request.assetUuid().toString().equals(declaration.assetUuid())) throw new IllegalArgumentException("Bank UUID mismatch");
if (asset.walkDiagnostics().stream().anyMatch(PackerDiagnostic::blocking)) throw new IllegalArgumentException("Bank composition is invalid");
var materialDiagnostics=glyphMaterialSupport.validate(asset);
if(materialDiagnostics.stream().anyMatch(PackerDiagnostic::blocking))throw new IllegalArgumentException("Bank material bindings are invalid: "+materialDiagnostics);
var files=new HashMap<String,PackerRuntimeWalkFile>();
asset.walkProjection().buildCandidateFiles().forEach(f->files.put(f.relativePath(),f));
var ids=new HashSet<String>();var indices=new HashSet<Integer>();
var glyphs=new ArrayList<p.packer.dtos.PackerGlyphBankLayoutDTO.Glyph>();
var revision=new StringBuilder(request.assetUuid().toString());
var material=declaredPaletteIndexByRgba(declaration);
for(var artifact:declaration.artifacts().stream().sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index)).toList()) {
var file=files.get(artifact.file());
if(artifact.artifactId()==null||!ids.add(artifact.artifactId())||!indices.add(artifact.index())
||file==null||file.fingerprint()==null||file.diagnostics().stream().anyMatch(PackerDiagnostic::blocking))
throw new IllegalArgumentException("Missing, removed or duplicate glyph identity");
if(!(file.metadata().get("tile") instanceof PackerTileIndexedV1 tile))throw new IllegalArgumentException("Missing glyph pixels");
byte[] pixels=remapTilePaletteIndices(tile,file.metadata().get("palette"),artifact.file(),material);
glyphs.add(new p.packer.dtos.PackerGlyphBankLayoutDTO.Glyph(artifact.artifactId(),artifact.index(),file.fingerprint(),
asset.assetRoot().resolve(artifact.file()),tile.width(),tile.height(),pixels));
revision.append('\n').append(artifact.artifactId()).append(':').append(artifact.index()).append(':').append(file.fingerprint());
}
byte[] palettes=emitGlyphBankPalettes(declaration,runtimeGlyphPaletteCount(declaration));
revision.append('\n').append(HexFormat.of().formatHex(palettes));
final String hash;
try { hash=HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(revision.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8))); }
catch(java.security.NoSuchAlgorithmException impossible){throw new AssertionError(impossible);}
return new p.packer.dtos.PackerGlyphBankLayoutDTO(request.assetUuid(),hash,asset.assetRoot(),glyphs,palettes);
}
@Override
public GetAssetDetailsResult getAssetDetails(GetAssetDetailsRequest request) {
final GetAssetDetailsRequest safeRequest = Objects.requireNonNull(request, "request");