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.
58 lines
4.7 KiB
Java
58 lines
4.7 KiB
Java
package p.animation;
|
|
|
|
import java.util.*;
|
|
|
|
/** The single structural and asset-binding validator used by Studio and compiler. */
|
|
public final class AnimationValidator {
|
|
public List<AnimationDiagnostic> validate(AnimationDocument doc, GlyphBankLayout layout) {
|
|
var errors=new ArrayList<AnimationDiagnostic>();
|
|
if(doc.schemaVersion()!=1)add(errors,"schema_version","/schema_version","Unsupported version");
|
|
try { if(!doc.bankAssetUuid().matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"))throw new IllegalArgumentException("UUID syntax"); if(!UUID.fromString(doc.bankAssetUuid()).equals(layout.assetUuid()))add(errors,"bank_uuid","/bank_asset_uuid","Containing bank UUID does not match"); }
|
|
catch(IllegalArgumentException error){add(errors,"bank_uuid","/bank_asset_uuid","Invalid UUID");}
|
|
var current=new HashMap<String,GlyphBankLayout.Glyph>(); var indices=new HashSet<Integer>();
|
|
for(var glyph:layout.glyphs()) {
|
|
if(glyph.artifactId().isEmpty()||current.putIfAbsent(glyph.artifactId(),glyph)!=null||!indices.add(glyph.glyphId())
|
|
||glyph.glyphId()<0||glyph.glyphId()>65535||!glyph.fingerprint().matches("[0-9a-f]{64}"))
|
|
add(errors,"bank_layout","/bindings","Current bank layout has missing/duplicate/invalid identities");
|
|
}
|
|
var bound=new HashMap<String,AnimationDocument.Binding>(); indices.clear();
|
|
for(int i=0;i<doc.bindings().size();i++) {
|
|
var binding=doc.bindings().get(i);String p="/bindings/"+i;
|
|
if(binding.artifactId().isEmpty()||bound.putIfAbsent(binding.artifactId(),binding)!=null)
|
|
add(errors,"duplicate_binding",p+"/artifact_id","Artifact binding must be unique and nonempty");
|
|
if(binding.glyphId()<0||binding.glyphId()>65535||!indices.add(binding.glyphId()))add(errors,"invalid_glyph",p+"/glyph_id","Glyph ID is out of range or duplicated");
|
|
var actual=current.get(binding.artifactId());
|
|
if(actual==null)add(errors,"missing_artifact",p,"Selected artifact is absent from the current composition");
|
|
else if(actual.glyphId()!=binding.glyphId()||!actual.fingerprint().equals(binding.fingerprint()))add(errors,"binding_drift",p,"Glyph index or fingerprint changed; explicit rebind required");
|
|
if(!binding.fingerprint().matches("[0-9a-f]{64}"))add(errors,"invalid_fingerprint",p+"/fingerprint","Expected lowercase SHA-256");
|
|
}
|
|
var ids=new HashSet<String>();
|
|
for(int i=0;i<doc.animators().size();i++) {
|
|
var animator=doc.animators().get(i);String p="/animators/"+i;
|
|
if(!animator.id().matches("[A-Za-z_][A-Za-z0-9_]*")||!ids.add(animator.id()))add(errors,"animator_id",p+"/id","Animator ID must be a unique PBS identifier");
|
|
if(animator.clips().isEmpty())add(errors,"empty_animator",p+"/clips","Animator needs at least one clip");
|
|
var names=new HashSet<String>();
|
|
for(int j=0;j<animator.clips().size();j++) {
|
|
var clip=animator.clips().get(j);String cp=p+"/clips/"+j;
|
|
if(clip.name().isEmpty()||!names.add(clip.name()))add(errors,"clip_name",cp+"/name","Clip names must be nonempty and unique, with exact comparison");
|
|
if(!Set.of("once","loop").contains(clip.mode()))add(errors,"mode",cp+"/mode","Expected once or loop");
|
|
if(clip.frames().isEmpty())add(errors,"empty_clip",cp+"/frames","Clip needs at least one frame");
|
|
long total=0;
|
|
for(int k=0;k<clip.frames().size();k++) {
|
|
var frame=clip.frames().get(k);String fp=cp+"/frames/"+k;
|
|
if(!bound.containsKey(frame.artifactId()))add(errors,"unbound_frame",fp+"/artifact_id","Frame must reference a unique binding");
|
|
if(frame.durationTicks()<=0)add(errors,"invalid_duration",fp+"/duration_ticks","Duration must be positive");
|
|
else if(total>Long.MAX_VALUE-frame.durationTicks())add(errors,"overflow",fp+"/duration_ticks","Clip duration exceeds signed 64-bit range");
|
|
else total+=frame.durationTicks();
|
|
}
|
|
}
|
|
if(animator.initialClip().isEmpty()||!names.contains(animator.initialClip()))add(errors,"initial_clip_missing",p+"/initial_clip","Initial clip must exist");
|
|
}
|
|
return List.copyOf(errors);
|
|
}
|
|
public void requireValid(AnimationDocument doc,GlyphBankLayout layout) {
|
|
var errors=validate(doc,layout);if(!errors.isEmpty())throw new IllegalArgumentException(errors.toString());
|
|
}
|
|
private static void add(List<AnimationDiagnostic> list,String code,String pointer,String message){list.add(new AnimationDiagnostic(code,pointer,message));}
|
|
}
|