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:
@@ -0,0 +1,75 @@
|
||||
package p.animation;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.node.*;
|
||||
import java.util.*;
|
||||
import static p.animation.AnimationDocument.*;
|
||||
|
||||
/** Strict UTF-8 JSON. Integer values never pass through floating point. */
|
||||
public final class AnimationCodec {
|
||||
private final ObjectMapper mapper = new ObjectMapper().enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION)
|
||||
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||
public AnimationDocument decode(String json) {
|
||||
try {
|
||||
JsonNode root = mapper.readTree(json);
|
||||
object(root, "", "schema_version", "bank_asset_uuid", "bindings", "animators");
|
||||
int version = integer(root.get("schema_version"), "/schema_version");
|
||||
if (version != 1) throw invalid("/schema_version", "Unsupported schema version");
|
||||
var bindings = new ArrayList<Binding>(); int i=0;
|
||||
for (var node : array(root.get("bindings"), "/bindings")) {
|
||||
String p="/bindings/"+i++; object(node,p,"artifact_id","glyph_id","fingerprint");
|
||||
bindings.add(new Binding(string(node.get("artifact_id"),p+"/artifact_id"), integer(node.get("glyph_id"),p+"/glyph_id"), string(node.get("fingerprint"),p+"/fingerprint")));
|
||||
}
|
||||
var animators = new ArrayList<Animator>(); i=0;
|
||||
for (var node : array(root.get("animators"), "/animators")) {
|
||||
String p="/animators/"+i++; object(node,p,"id","initial_clip","clips");
|
||||
var clips = new ArrayList<Clip>(); int j=0;
|
||||
for(var clip : array(node.get("clips"),p+"/clips")) {
|
||||
String cp=p+"/clips/"+j++; object(clip,cp,"name","mode","frames");
|
||||
var frames=new ArrayList<Frame>(); int k=0;
|
||||
for(var frame:array(clip.get("frames"),cp+"/frames")) {
|
||||
String fp=cp+"/frames/"+k++; object(frame,fp,"artifact_id","duration_ticks");
|
||||
frames.add(new Frame(string(frame.get("artifact_id"),fp+"/artifact_id"), exactLong(frame.get("duration_ticks"),fp+"/duration_ticks")));
|
||||
}
|
||||
clips.add(new Clip(string(clip.get("name"),cp+"/name"),string(clip.get("mode"),cp+"/mode"),frames));
|
||||
}
|
||||
animators.add(new Animator(string(node.get("id"),p+"/id"),string(node.get("initial_clip"),p+"/initial_clip"),clips));
|
||||
}
|
||||
return new AnimationDocument(version,string(root.get("bank_asset_uuid"),"/bank_asset_uuid"),bindings,animators);
|
||||
} catch (java.io.IOException error) { throw invalid("", error.getMessage()); }
|
||||
}
|
||||
public String encode(AnimationDocument document) {
|
||||
ObjectNode root=mapper.createObjectNode(); root.put("schema_version",document.schemaVersion()); root.put("bank_asset_uuid",document.bankAssetUuid());
|
||||
var bindings=root.putArray("bindings");
|
||||
for(var binding:document.bindings()) bindings.addObject().put("artifact_id",binding.artifactId()).put("glyph_id",binding.glyphId()).put("fingerprint",binding.fingerprint());
|
||||
var animators=root.putArray("animators");
|
||||
for(var animator:document.animators()) {
|
||||
var node=animators.addObject().put("id",animator.id()).put("initial_clip",animator.initialClip()); var clips=node.putArray("clips");
|
||||
for(var clip:animator.clips()) { var c=clips.addObject().put("name",clip.name()).put("mode",clip.mode()); var frames=c.putArray("frames");
|
||||
for(var frame:clip.frames()) frames.addObject().put("artifact_id",frame.artifactId()).put("duration_ticks",frame.durationTicks()); }
|
||||
}
|
||||
try { return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)+"\n"; }
|
||||
catch(java.io.IOException error) { throw new IllegalStateException(error); }
|
||||
}
|
||||
private static void object(JsonNode value,String pointer,String... names) {
|
||||
if(value==null||!value.isObject())throw invalid(pointer,"Expected object");
|
||||
var expected=Set.of(names); var keys=value.fieldNames();
|
||||
while(keys.hasNext()){var key=keys.next();if(!expected.contains(key))throw invalid(pointer+"/"+key,"Unknown field");}
|
||||
for(var name:names)if(!value.has(name))throw invalid(pointer+"/"+name,"Missing required field");
|
||||
}
|
||||
private static JsonNode array(JsonNode node,String pointer){if(node==null||!node.isArray())throw invalid(pointer,"Expected array");return node;}
|
||||
private static String string(JsonNode node,String pointer){
|
||||
if(node==null||!node.isTextual())throw invalid(pointer,"Expected string");
|
||||
String text=node.textValue();
|
||||
for(int i=0;i<text.length();i++){
|
||||
char c=text.charAt(i);
|
||||
if(Character.isHighSurrogate(c)){if(i+1>=text.length()||!Character.isLowSurrogate(text.charAt(++i)))throw invalid(pointer,"Unpaired Unicode surrogate");}
|
||||
else if(Character.isLowSurrogate(c))throw invalid(pointer,"Unpaired Unicode surrogate");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
private static long exactLong(JsonNode node,String pointer){if(node==null||!node.isIntegralNumber()||!node.canConvertToLong())throw invalid(pointer,"Expected exact signed 64-bit integer");return node.longValue();}
|
||||
private static int integer(JsonNode node,String pointer){long value=exactLong(node,pointer);if(value<Integer.MIN_VALUE||value>Integer.MAX_VALUE)throw invalid(pointer,"Integer out of range");return (int)value;}
|
||||
private static IllegalArgumentException invalid(String pointer,String message){return new IllegalArgumentException(pointer+": "+message);}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package p.animation;
|
||||
public record AnimationDiagnostic(String code, String pointer, String message) {}
|
||||
@@ -0,0 +1,24 @@
|
||||
package p.animation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Canonical editorial values; slots, palette, position and playback clocks are external. */
|
||||
public record AnimationDocument(int schemaVersion, String bankAssetUuid, List<Binding> bindings, List<Animator> animators) {
|
||||
public static final String FILE_NAME = "animations.studio.json";
|
||||
public AnimationDocument {
|
||||
Objects.requireNonNull(bankAssetUuid); bindings = List.copyOf(bindings); animators = List.copyOf(animators);
|
||||
}
|
||||
public record Binding(String artifactId, int glyphId, String fingerprint) {
|
||||
public Binding { Objects.requireNonNull(artifactId); Objects.requireNonNull(fingerprint); }
|
||||
}
|
||||
public record Animator(String id, String initialClip, List<Clip> clips) {
|
||||
public Animator { Objects.requireNonNull(id); Objects.requireNonNull(initialClip); clips = List.copyOf(clips); }
|
||||
}
|
||||
public record Clip(String name, String mode, List<Frame> frames) {
|
||||
public Clip { Objects.requireNonNull(name); Objects.requireNonNull(mode); frames = List.copyOf(frames); }
|
||||
}
|
||||
public record Frame(String artifactId, long durationTicks) {
|
||||
public Frame { Objects.requireNonNull(artifactId); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package p.animation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
/** Open an authored field through the Studio editor; this port never writes files. */
|
||||
@FunctionalInterface
|
||||
public interface AnimationOriginNavigation { void open(Path projectRoot,UUID assetUuid,String jsonPointer); }
|
||||
@@ -0,0 +1,28 @@
|
||||
package p.animation;
|
||||
|
||||
import java.util.*;
|
||||
import static p.animation.AnimationDocument.*;
|
||||
|
||||
/** Binding-only proposal, correlated with the exact source and bank revisions. */
|
||||
public final class AnimationRebind {
|
||||
public record Difference(Binding before, Binding after, List<String> affectedFrames) { public Difference { affectedFrames=List.copyOf(affectedFrames); } }
|
||||
public record Proposal(AnimationDocument document, List<Difference> differences, String proposalHash, String bankRevision) { public Proposal { differences=List.copyOf(differences); } }
|
||||
public Proposal prepare(AnimationDocument document,String revision,GlyphBankLayout bank) {
|
||||
var current=new HashMap<String,GlyphBankLayout.Glyph>();bank.glyphs().forEach(g->current.put(g.artifactId(),g));
|
||||
var bindings=new ArrayList<Binding>();var differences=new ArrayList<Difference>();
|
||||
for(var binding:document.bindings()) {
|
||||
var glyph=current.get(binding.artifactId());
|
||||
Binding updated=glyph==null?binding:new Binding(glyph.artifactId(),glyph.glyphId(),glyph.fingerprint());bindings.add(updated);
|
||||
if(!updated.equals(binding)||glyph==null){var affected=new ArrayList<String>();
|
||||
for(int a=0;a<document.animators().size();a++)for(int c=0;c<document.animators().get(a).clips().size();c++){
|
||||
var frames=document.animators().get(a).clips().get(c).frames();
|
||||
for(int f=0;f<frames.size();f++)if(frames.get(f).artifactId().equals(binding.artifactId()))affected.add("/animators/"+a+"/clips/"+c+"/frames/"+f);
|
||||
}
|
||||
differences.add(new Difference(binding,glyph==null?null:updated,affected));
|
||||
}
|
||||
}
|
||||
var candidate=new AnimationDocument(document.schemaVersion(),document.bankAssetUuid(),bindings,document.animators());
|
||||
String hash=AnimationRevision.of(revision+"\n"+bank.revision()+"\n"+new AnimationCodec().encode(candidate));
|
||||
return new Proposal(candidate,differences,hash,bank.revision());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package p.animation;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HexFormat;
|
||||
public final class AnimationRevision {
|
||||
private AnimationRevision() {}
|
||||
public static String of(String value) { return of(value.getBytes(StandardCharsets.UTF_8)); }
|
||||
public static String of(byte[] value) {
|
||||
try { return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(value)); }
|
||||
catch (java.security.NoSuchAlgorithmException impossible) { throw new AssertionError(impossible); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p.animation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
/** Validated language-neutral build input, owned by one project and registered bank. */
|
||||
public record AnimationSource(String projectName, Path projectRoot, Path definitionPath,
|
||||
String documentRevision, AnimationDocument document, GlyphBankLayout bank) {
|
||||
public AnimationSource { Objects.requireNonNull(projectName); Objects.requireNonNull(projectRoot); Objects.requireNonNull(definitionPath); Objects.requireNonNull(documentRevision); Objects.requireNonNull(document); Objects.requireNonNull(bank); }
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package p.animation;
|
||||
|
||||
import java.util.*;
|
||||
import static p.animation.AnimationDocument.*;
|
||||
|
||||
/** Explicit-tick editorial playback, qualified against the PBS implementation. */
|
||||
public final class AnimationTimeline {
|
||||
public enum State { Stopped, Playing, Paused, Finished }
|
||||
public record Observation(String clipName, String artifactId, int glyphId, long phase, State state) {}
|
||||
private final Animator animator;
|
||||
private final Map<String,Binding> bindings;
|
||||
private Clip clip;
|
||||
private long phase;
|
||||
private State state=State.Stopped;
|
||||
public AnimationTimeline(AnimationDocument document,String animatorId) {
|
||||
animator=document.animators().stream().filter(a->a.id().equals(animatorId)).findFirst().orElseThrow(()->new IllegalArgumentException("unknown_animator"));
|
||||
var values=new HashMap<String,Binding>();document.bindings().forEach(b->values.put(b.artifactId(),b));bindings=Map.copyOf(values);
|
||||
clip=find(animator.initialClip());
|
||||
}
|
||||
private Clip find(String name){return animator.clips().stream().filter(c->c.name().equals(name)).findFirst().orElseThrow(()->new IllegalArgumentException("unknown_clip"));}
|
||||
public void select(String name){var selected=find(name);clip=selected;phase=0;state=State.Stopped;}
|
||||
public void play(String name){select(name);state=State.Playing;}
|
||||
public void pause(){if(state==State.Playing)state=State.Paused;}
|
||||
public void resume(){if(state==State.Paused)state=State.Playing;}
|
||||
public void stop(){phase=0;state=State.Stopped;}
|
||||
public void restart(){phase=0;state=State.Playing;}
|
||||
public void advance(int ticks){
|
||||
if(ticks<0)throw new IllegalArgumentException("invalid_ticks");
|
||||
if(ticks==0||state!=State.Playing)return;
|
||||
if(phase>Long.MAX_VALUE-ticks)throw new IllegalArgumentException("overflow");
|
||||
long next=phase+ticks;long total=total(clip);var nextState=state;
|
||||
if(clip.mode().equals("loop"))next%=total;
|
||||
else if(next>=total){next=total;nextState=State.Finished;}
|
||||
phase=next;state=nextState;
|
||||
}
|
||||
public Observation observation(){
|
||||
long end=0;Frame selected=clip.frames().getLast();
|
||||
for(var frame:clip.frames()){end=Math.addExact(end,frame.durationTicks());if(phase<end){selected=frame;break;}}
|
||||
var binding=bindings.get(selected.artifactId());if(binding==null)throw new IllegalArgumentException("unbound_frame");
|
||||
return new Observation(clip.name(),selected.artifactId(),binding.glyphId(),phase,state);
|
||||
}
|
||||
public static Observation sample(AnimationDocument doc,String animatorId,String clipName,long elapsedTicks){
|
||||
if(elapsedTicks<0)throw new IllegalArgumentException("invalid_ticks");
|
||||
var timeline=new AnimationTimeline(doc,animatorId);timeline.play(clipName);long total=total(timeline.clip);
|
||||
if(timeline.clip.mode().equals("loop"))timeline.phase=elapsedTicks%total;
|
||||
else {timeline.phase=Math.min(elapsedTicks,total);if(elapsedTicks>=total)timeline.state=State.Finished;}
|
||||
return timeline.observation();
|
||||
}
|
||||
private static long total(Clip clip){long total=0;for(var frame:clip.frames())total=Math.addExact(total,frame.durationTicks());return total;}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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));}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package p.animation;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Effective Packer composition. Paths locate current images; identity never derives from them. */
|
||||
public record GlyphBankLayout(UUID assetUuid, String revision, Path assetRoot, List<Glyph> glyphs, byte[] rgbaPalettes) {
|
||||
public GlyphBankLayout { Objects.requireNonNull(assetUuid); Objects.requireNonNull(revision); glyphs = List.copyOf(glyphs); rgbaPalettes=rgbaPalettes.clone(); }
|
||||
public GlyphBankLayout(UUID uuid,String revision,Path root,List<Glyph> glyphs){this(uuid,revision,root,glyphs,new byte[0]);}
|
||||
@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 { Objects.requireNonNull(artifactId); Objects.requireNonNull(fingerprint); indices=indices.clone(); }
|
||||
public Glyph(String id,int glyph,String hash,Path path){this(id,glyph,hash,path,0,0,new byte[0]);}
|
||||
@Override public byte[] indices(){return indices.clone();}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package p.animation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
/** App-composed port; compiler callers inject a public Packer API adapter. */
|
||||
@FunctionalInterface
|
||||
public interface GlyphBankLayoutSource {
|
||||
GlyphBankLayout resolve(Path projectRoot, UUID assetUuid);
|
||||
default <T> T withLayout(Path projectRoot, UUID assetUuid, java.util.function.Function<GlyphBankLayout,T> work) {
|
||||
throw new UnsupportedOperationException("Project-exclusive animation access is not configured");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package p.animation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.*;
|
||||
import static p.animation.AnimationDocument.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AnimationContractTest {
|
||||
static final UUID ID=UUID.fromString("12345678-1234-1234-1234-123456789abc");
|
||||
static final String HASH="a".repeat(64);
|
||||
static AnimationDocument document(String mode){return new AnimationDocument(1,ID.toString(),List.of(new Binding("a",7,HASH),new Binding("b",11,HASH),new Binding("c",4,HASH)),List.of(new Animator("hero"," idle ",List.of(new Clip(" idle ",mode,List.of(new Frame("a",2),new Frame("b",3),new Frame("c",1)))))));}
|
||||
static GlyphBankLayout bank(){return new GlyphBankLayout(ID,"bank1",null,List.of(new GlyphBankLayout.Glyph("a",7,HASH,null),new GlyphBankLayout.Glyph("b",11,HASH,null),new GlyphBankLayout.Glyph("c",4,HASH,null)));}
|
||||
@Test void strictCodecPreservesExactLongAndRejectsAmbiguousJson(){
|
||||
var codec=new AnimationCodec();var doc=new AnimationDocument(1,ID.toString(),List.of(new Binding("a",7,HASH)),List.of(new Animator("hero","idle",List.of(new Clip("idle","once",List.of(new Frame("a",9007199254740993L)))))));
|
||||
String json=codec.encode(doc);assertEquals(doc,codec.decode(json));
|
||||
for(var invalid:List.of(json.replace("9007199254740993","9007199254740993.0"),json.replace("9007199254740993","9223372036854775808"),json.replace("\"schema_version\" : 1","\"schema_version\" : 1, \"schema_version\" : 1"),json.replace("\"schema_version\" : 1","\"unknown\" : 1, \"schema_version\" : 1"),json+"{}"))assertThrows(IllegalArgumentException.class,()->codec.decode(invalid),invalid);
|
||||
}
|
||||
@Test void identityDriftBlocksAndRebindIsAnExplicitImmutableProposal(){
|
||||
var doc=document("loop");var validator=new AnimationValidator();assertTrue(validator.validate(doc,bank()).isEmpty());
|
||||
var changed=new GlyphBankLayout(ID,"bank2",null,List.of(new GlyphBankLayout.Glyph("a",8,"b".repeat(64),null),new GlyphBankLayout.Glyph("b",11,HASH,null),new GlyphBankLayout.Glyph("c",4,HASH,null)));
|
||||
assertTrue(validator.validate(doc,changed).stream().anyMatch(d->d.code().equals("binding_drift")));
|
||||
var proposal=new AnimationRebind().prepare(doc,"document1",changed);
|
||||
assertEquals(7,doc.bindings().getFirst().glyphId());assertEquals(8,proposal.document().bindings().getFirst().glyphId());
|
||||
assertTrue(validator.validate(proposal.document(),changed).isEmpty());assertFalse(proposal.differences().getFirst().affectedFrames().isEmpty());
|
||||
assertNotEquals(proposal.proposalHash(),new AnimationRebind().prepare(doc,"document2",changed).proposalHash());
|
||||
}
|
||||
@Test void timelineMatchesTheNativeBoundaryOracleAndPreservesFailures(){
|
||||
for(var mode:List.of("once","loop")){
|
||||
var doc=document(mode);long[] ticks={0,1,2,4,5,6,601};int[] glyphs=mode.equals("loop")?new int[]{7,7,11,11,4,7,7}:new int[]{7,7,11,11,4,4,4};
|
||||
for(int i=0;i<ticks.length;i++)assertEquals(glyphs[i],AnimationTimeline.sample(doc,"hero"," idle ",ticks[i]).glyphId());
|
||||
var timeline=new AnimationTimeline(doc,"hero");timeline.play(" idle ");timeline.advance(2);timeline.pause();var paused=timeline.observation();timeline.advance(100);assertEquals(paused,timeline.observation());
|
||||
assertThrows(IllegalArgumentException.class,()->timeline.advance(-1));assertEquals(paused,timeline.observation());
|
||||
assertThrows(IllegalArgumentException.class,()->timeline.select("idle"));assertEquals(paused,timeline.observation());
|
||||
timeline.resume();timeline.stop();assertEquals(7,timeline.observation().glyphId());timeline.restart();assertEquals(AnimationTimeline.State.Playing,timeline.observation().state());
|
||||
}
|
||||
}
|
||||
@Test void overflowAndInvalidReferencesAreBlockingDiagnostics(){
|
||||
var doc=new AnimationDocument(1,ID.toString(),List.of(new Binding("a",7,HASH)),List.of(new Animator("hero","idle",List.of(new Clip("idle","once",List.of(new Frame("a",Long.MAX_VALUE),new Frame("missing",1)))))));
|
||||
var errors=new AnimationValidator().validate(doc,bank());assertTrue(errors.stream().anyMatch(d->d.code().equals("overflow")));assertTrue(errors.stream().anyMatch(d->d.code().equals("unbound_frame")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user