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,54 @@
|
||||
package p.studio.app.animation;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.animation.AnimationEditorControl;
|
||||
import p.animation.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Actual JavaFX editing, shared save/preview, drift repair and handoff lifecycle. */
|
||||
class AnimationDesktopTest {
|
||||
@TempDir Path root;
|
||||
@BeforeAll static void toolkit()throws Exception{
|
||||
var ready=new CompletableFuture<Void>();
|
||||
try{Platform.startup(()->{Platform.setImplicitExit(false);ready.complete(null);});}
|
||||
catch(IllegalStateException running){ready.complete(null);}
|
||||
ready.get(10,TimeUnit.SECONDS);
|
||||
}
|
||||
@AfterAll static void stopToolkit(){Platform.exit();}
|
||||
static <T>T fx(Supplier<T> work)throws Exception{var result=new CompletableFuture<T>();Platform.runLater(()->{try{result.complete(work.get());}catch(Throwable f){result.completeExceptionally(f);}});return result.get(10,TimeUnit.SECONDS);}
|
||||
static void await(BooleanSupplier test)throws Exception{long end=System.nanoTime()+TimeUnit.SECONDS.toNanos(10);while(!test.getAsBoolean()){if(System.nanoTime()>end)fail("Animation editor did not finish");Thread.sleep(10);}}
|
||||
static Button button(AnimationEditorControl editor,String text){return editor.lookupAll(".button").stream().filter(n->n instanceof Button b&&b.getText().equals(text)).map(n->(Button)n).findFirst().orElseThrow();}
|
||||
@Test void authorsPreviewsSavesRepairsAndCloses()throws Exception{
|
||||
var fixture=new AnimationIntegrationTest();fixture.root=root;fixture.setup();
|
||||
var pool=Executors.newCachedThreadPool();var stage=new Stage[1];var editor=new AnimationEditorControl[1];
|
||||
try{
|
||||
fx(()->{editor[0]=new AnimationEditorControl(fixture.project,fixture.manual,pool);var scroll=new ScrollPane(editor[0]);scroll.setFitToWidth(true);stage[0]=new Stage();stage[0].setTitle("Animation authoring acceptance");stage[0].setScene(new Scene(scroll,1040,940));stage[0].show();editor[0].bind(fixture.uuid);return null;});
|
||||
await(()->{try{return fx(()->((Label)editor[0].lookup("#animation-status")).getText().equals("New definition"));}catch(Exception e){throw new RuntimeException(e);}});
|
||||
fx(()->{((TextField)editor[0].lookup("#animation-id")).setText("hero");button(editor[0],"New animator").fire();((ComboBox<?>)editor[0].lookup("#animation-glyph")).getSelectionModel().selectFirst();((TextField)editor[0].lookup("#animation-duration")).setText("2");button(editor[0],"Add frame").fire();return null;});
|
||||
assertTrue(editor[0].hasUnsavedChanges().toCompletableFuture().get());
|
||||
editor[0].saveAll().toCompletableFuture().get(10,TimeUnit.SECONDS);
|
||||
assertFalse(editor[0].hasUnsavedChanges().toCompletableFuture().get());
|
||||
assertEquals(2,fixture.manual.execute(p.studio.api.assets.animation.AnimationService.Request.get(fixture.project,fixture.uuid)).view().document().animators().getFirst().clips().getFirst().frames().getFirst().durationTicks());
|
||||
fx(()->{button(editor[0],"Preview").fire();return null;});
|
||||
await(()->{try{return fx(()->((ImageView)editor[0].lookup("#animation-image")).getImage()!=null);}catch(Exception e){throw new RuntimeException(e);}});
|
||||
fx(()->{var snapshot=stage[0].getScene().snapshot(null);var image=new java.awt.image.BufferedImage((int)snapshot.getWidth(),(int)snapshot.getHeight(),java.awt.image.BufferedImage.TYPE_INT_ARGB);for(int y=0;y<image.getHeight();y++)for(int x=0;x<image.getWidth();x++)image.setRGB(x,y,snapshot.getPixelReader().getArgb(x,y));try{javax.imageio.ImageIO.write(image,"png",Path.of("/tmp/dec84-animation-desktop.png").toFile());}catch(Exception e){throw new RuntimeException(e);}return null;});
|
||||
var asset=(com.fasterxml.jackson.databind.node.ObjectNode)fixture.mapper.readTree(fixture.bankRoot.resolve("asset.json").toFile());((com.fasterxml.jackson.databind.node.ObjectNode)asset.path("artifacts").get(0)).put("index",1);((com.fasterxml.jackson.databind.node.ObjectNode)asset.path("artifacts").get(1)).put("index",0);fixture.mapper.writeValue(fixture.bankRoot.resolve("asset.json").toFile(),asset);
|
||||
editor[0].refreshFromDisk().toCompletableFuture().get(10,TimeUnit.SECONDS);
|
||||
fx(()->{button(editor[0],"Prepare rebind").fire();return null;});
|
||||
await(()->{try{return fx(()->!button(editor[0],"Apply rebind").isDisabled());}catch(Exception e){throw new RuntimeException(e);}});
|
||||
fx(()->{button(editor[0],"Apply rebind").fire();return null;});
|
||||
await(()->fixture.manual.execute(p.studio.api.assets.animation.AnimationService.Request.get(fixture.project,fixture.uuid)).view().diagnostics().isEmpty());
|
||||
fx(()->{editor[0].openOrigin("/animators/0/clips/0/frames/0");editor[0].close();stage[0].close();return null;});
|
||||
assertFalse(pool.isShutdown());
|
||||
}finally{fx(()->{if(editor[0]!=null)editor[0].close();if(stage[0]!=null)stage[0].close();return null;});pool.shutdownNow();fixture.close();}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user