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:
@@ -171,8 +171,28 @@ public class StudioApplicationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
CompilerBuildGateway compilerBuildGateway() {
|
||||
return new CompilerBuildGatewayAdapter();
|
||||
p.animation.GlyphBankLayoutSource glyphBankLayoutSource(PackerWorkspaceService packer,ObjectMapper mapper) {
|
||||
return new p.studio.app.assets.PackerGlyphBankLayouts(packer,mapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
p.studio.core.assets.animation.DefaultAnimationService animationEngine(p.animation.GlyphBankLayoutSource layouts,AssetCatalog catalog) {
|
||||
return new p.studio.core.assets.animation.DefaultAnimationService(layouts,catalog);
|
||||
}
|
||||
|
||||
@Bean
|
||||
p.studio.api.assets.animation.AnimationService animationService(p.studio.core.assets.animation.DefaultAnimationService engine,p.studio.api.automation.ProjectAccess access) {
|
||||
return new p.studio.core.assets.animation.ManualAnimationService(engine,access);
|
||||
}
|
||||
|
||||
@Bean
|
||||
p.studio.api.assets.animation.AnimationTasks animationTasks(p.studio.core.project.ProjectAccessRegistry projects,ProjectCatalog catalog,p.studio.core.assets.animation.DefaultAnimationService engine) {
|
||||
return new p.studio.core.session.TaskAnimationService(projects,catalog,engine);
|
||||
}
|
||||
|
||||
@Bean
|
||||
CompilerBuildGateway compilerBuildGateway(p.animation.GlyphBankLayoutSource layouts) {
|
||||
return new CompilerBuildGatewayAdapter(layouts);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -213,8 +233,8 @@ public class StudioApplicationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
LspServerLifecycle lspServerLifecycle() {
|
||||
return new LspServerLifecycleImpl();
|
||||
LspServerLifecycle lspServerLifecycle(p.animation.GlyphBankLayoutSource layouts,StudioEventBus events) {
|
||||
return new LspServerLifecycleImpl(layouts,(root,uuid,pointer)->events.publish(new p.studio.ui.javafx.events.StudioAnimationOriginRequestedEvent(root,uuid,pointer)));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -284,13 +304,15 @@ public class StudioApplicationConfiguration {
|
||||
TiledAssetService tiledAssetService,
|
||||
SceneBankWorkflow sceneBankWorkflow,
|
||||
WindowStateStore windowStateStore,
|
||||
ProjectActivityHistoryStore activityHistoryStore, p.studio.api.automation.AgentConnectionGuide connectionGuide) {
|
||||
return new StudioUiFactory(projectCatalog, knownProjects, languageCatalog, projectSessionFactory,
|
||||
ProjectActivityHistoryStore activityHistoryStore, p.studio.api.automation.AgentConnectionGuide connectionGuide, p.studio.api.assets.animation.AnimationService animationService) {
|
||||
var factory = new StudioUiFactory(projectCatalog, knownProjects, languageCatalog, projectSessionFactory,
|
||||
executionControllerFactory, projectWorkspaceInitializer, studioExecutor, i18n, theme, eventBus, shipper,
|
||||
assetCatalog, assetCommands, assetPacking, assetDetails, assetCreationCatalog, assetMetadataService,
|
||||
assetWorkspaceStorage, assetCapacityPolicy, bankCompositionSessionFactory, assetColorSchemaFactory,
|
||||
tiledAssetService, sceneBankWorkflow, windowStateStore,
|
||||
activityHistoryStore, connectionGuide);
|
||||
factory.setAnimationService(animationService);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -300,8 +322,8 @@ public class StudioApplicationConfiguration {
|
||||
|
||||
@Bean
|
||||
p.studio.api.automation.ProjectKnowledge projectKnowledge(
|
||||
p.studio.core.project.ProjectAccessRegistry projects, ProjectCatalog catalog, ObjectMapper mapper) {
|
||||
return new p.studio.app.compiler.CompilerProjectKnowledge(projects, catalog, mapper);
|
||||
p.studio.core.project.ProjectAccessRegistry projects, ProjectCatalog catalog, ObjectMapper mapper, p.animation.GlyphBankLayoutSource layouts) {
|
||||
return new p.studio.app.compiler.CompilerProjectKnowledge(projects, catalog, mapper, layouts);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -331,10 +353,11 @@ public class StudioApplicationConfiguration {
|
||||
@Bean
|
||||
p.studio.app.mcp.McpToolRegistry mcpToolRegistry(p.studio.app.mcp.McpToolCatalog catalog, ObjectMapper mapper,
|
||||
p.studio.api.automation.ProjectKnowledge knowledge, p.studio.api.automation.LanguageQueries language,
|
||||
p.studio.api.automation.TaskTools tasks, java.util.Optional<p.studio.core.runtime.HeadlessGateway> headless) {
|
||||
p.studio.api.automation.TaskTools tasks, p.studio.api.assets.animation.AnimationTasks animations, java.util.Optional<p.studio.core.runtime.HeadlessGateway> headless) {
|
||||
var handlers = new java.util.LinkedHashMap<>(p.studio.app.mcp.McpProjectKnowledgeTools.handlers(knowledge, mapper));
|
||||
handlers.putAll(p.studio.app.mcp.McpLanguageTools.handlers(language, mapper));
|
||||
handlers.putAll(p.studio.app.mcp.McpTaskTools.handlers(tasks, mapper, headless.isPresent()));
|
||||
handlers.putAll(p.studio.app.mcp.McpAnimationTools.handlers(animations, mapper));
|
||||
return new p.studio.app.mcp.McpToolRegistry(catalog, mapper, handlers);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ public final class StudioUiFactory {
|
||||
private final ProjectActivityHistoryStore activityHistoryStore;
|
||||
private final p.studio.api.automation.AgentConnectionGuide connectionGuide;
|
||||
|
||||
private p.studio.api.assets.animation.AnimationService animationService;
|
||||
public void setAnimationService(p.studio.api.assets.animation.AnimationService service){this.animationService=service;}
|
||||
|
||||
public StudioUiFactory(
|
||||
ProjectCatalog projectCatalog,
|
||||
KnownProjects knownProjects,
|
||||
@@ -113,11 +116,13 @@ public final class StudioUiFactory {
|
||||
}
|
||||
|
||||
public StudioWindowCoordinator create(Stage stage) {
|
||||
return new StudioWindowCoordinator(stage, projectCatalog, knownProjects, languageCatalog, projectSessionFactory,
|
||||
var coordinator = new StudioWindowCoordinator(stage, projectCatalog, knownProjects, languageCatalog, projectSessionFactory,
|
||||
executionControllerFactory, projectWorkspaceInitializer, executor, i18n, theme, eventBus, shipper,
|
||||
assetCatalog, assetCommands, assetPacking, assetDetails, assetCreationCatalog, assetMetadataService,
|
||||
assetWorkspaceStorage, assetCapacityPolicy, bankCompositionSessionFactory, assetColorSchemaFactory,
|
||||
tiledAssetService, sceneBankWorkflow, windowStateStore,
|
||||
activityHistoryStore, connectionGuide);
|
||||
if(animationService!=null)coordinator.setAnimationService(animationService);
|
||||
return coordinator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package p.studio.app.assets;
|
||||
import p.animation.*;
|
||||
import p.packer.PackerWorkspaceService;
|
||||
import p.packer.messages.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
/** Only application composition knows the public Packer adapter. */
|
||||
public final class PackerGlyphBankLayouts implements GlyphBankLayoutSource {
|
||||
private final PackerWorkspaceService packer;private final ObjectMapper mapper;
|
||||
public PackerGlyphBankLayouts(PackerWorkspaceService packer,ObjectMapper mapper){this.packer=packer;this.mapper=mapper;}
|
||||
private GetGlyphBankLayoutRequest request(Path root,UUID uuid){
|
||||
try{return new GetGlyphBankLayoutRequest(new PackerProjectContext(mapper.readTree(root.resolve("prometeu.json").toFile()).path("name").asText(),root),uuid);}
|
||||
catch(java.io.IOException e){throw new IllegalArgumentException("Cannot read project identity",e);}
|
||||
}
|
||||
private static GlyphBankLayout map(p.packer.dtos.PackerGlyphBankLayoutDTO bank){
|
||||
return new GlyphBankLayout(bank.assetUuid(),bank.revision(),bank.assetRoot(),bank.glyphs().stream().map(g->new GlyphBankLayout.Glyph(g.artifactId(),g.glyphId(),g.fingerprint(),g.imagePath(),g.width(),g.height(),g.indices())).toList(),bank.rgbaPalettes());
|
||||
}
|
||||
@Override public GlyphBankLayout resolve(Path root,UUID uuid){return map(packer.getGlyphBankLayout(request(root,uuid)));}
|
||||
@Override public <T> T withLayout(Path root,UUID uuid,Function<GlyphBankLayout,T> work){return packer.withGlyphBankLayout(request(root,uuid),bank->work.apply(map(bank)));}
|
||||
}
|
||||
@@ -11,11 +11,15 @@ import java.util.LinkedHashSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class CompilerBuildGatewayAdapter implements CompilerBuildGateway {
|
||||
private final p.animation.GlyphBankLayoutSource layouts;
|
||||
public CompilerBuildGatewayAdapter(){this(null);}
|
||||
public CompilerBuildGatewayAdapter(p.animation.GlyphBankLayoutSource layouts){this.layouts=layouts;}
|
||||
@Override
|
||||
public CompilerBuildOutput compile(ProjectReference project, Consumer<String> logSink) {
|
||||
final var config = new BuilderPipelineConfig(false, project.rootPath().toString());
|
||||
var context=BuilderPipelineContext.fromConfig(config);context.glyphBankLayoutSource=layouts;
|
||||
final var result = BuilderPipelineService.INSTANCE.build(
|
||||
BuilderPipelineContext.fromConfig(config),
|
||||
context,
|
||||
LogAggregator.with(logSink));
|
||||
final var capabilities = new LinkedHashSet<>(
|
||||
result.compileResult().analysisSnapshot().irBackend()
|
||||
|
||||
@@ -26,9 +26,13 @@ public final class CompilerProjectKnowledge implements ProjectKnowledge {
|
||||
private final ProjectAccessRegistry openProjects;
|
||||
private final ProjectCatalog projects;
|
||||
private final ObjectMapper mapper;
|
||||
private final CompilerLanguageServiceBridge languageBridge = new CompilerLanguageServiceBridge();
|
||||
private final CompilerLanguageServiceBridge languageBridge;
|
||||
|
||||
public CompilerProjectKnowledge(ProjectAccessRegistry openProjects, ProjectCatalog projects, ObjectMapper mapper) {
|
||||
this(openProjects,projects,mapper,null);
|
||||
}
|
||||
public CompilerProjectKnowledge(ProjectAccessRegistry openProjects,ProjectCatalog projects,ObjectMapper mapper,p.animation.GlyphBankLayoutSource layouts) {
|
||||
this.languageBridge=new CompilerLanguageServiceBridge(layouts);
|
||||
this.openProjects = Objects.requireNonNull(openProjects);
|
||||
this.projects = Objects.requireNonNull(projects);
|
||||
this.mapper = Objects.requireNonNull(mapper);
|
||||
|
||||
@@ -18,6 +18,7 @@ final class ContractSchema {
|
||||
if (schema.has("const") && !schema.get("const").equals(value)) fail();
|
||||
if (schema.has("type")) {
|
||||
boolean valid = switch (schema.get("type").asText()) {
|
||||
case "null" -> value.isNull();
|
||||
case "object" -> value.isObject();
|
||||
case "array" -> value.isArray();
|
||||
case "string" -> value.isTextual();
|
||||
@@ -27,6 +28,8 @@ final class ContractSchema {
|
||||
};
|
||||
if (!valid) fail();
|
||||
}
|
||||
if(schema.has("pattern")&&!value.textValue().matches(schema.get("pattern").textValue()))fail();
|
||||
if(schema.has("minItems")&&value.size()<schema.get("minItems").intValue())fail();
|
||||
if (schema.has("minLength") && value.textValue().codePointCount(0, value.textValue().length()) < schema.get("minLength").intValue()) fail();
|
||||
if (schema.has("minimum") && value.longValue() < schema.get("minimum").longValue()) fail();
|
||||
if (schema.has("maximum") && value.longValue() > schema.get("maximum").longValue()) fail();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package p.studio.app.mcp;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import p.animation.AnimationCodec;
|
||||
import p.studio.api.assets.animation.*;
|
||||
import p.studio.api.automation.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** Wire adaptation only; UI and AI call the same shared application service. */
|
||||
public final class McpAnimationTools {
|
||||
private McpAnimationTools(){}
|
||||
public static Map<String,Function<JsonNode,McpToolResult>> handlers(AnimationTasks tasks,ObjectMapper mapper){
|
||||
return Map.of("studio_animation_query",args->call(tasks,mapper,args),"studio_animation_update",args->call(tasks,mapper,args));
|
||||
}
|
||||
private static McpToolResult call(AnimationTasks tasks,ObjectMapper mapper,JsonNode args){
|
||||
try {
|
||||
var response=tasks.execute(Path.of(args.required("projectRoot").textValue()),args.required("taskId").textValue(),project->new AnimationService.Request(
|
||||
AnimationService.Operation.valueOf(args.required("operation").textValue().toUpperCase(Locale.ROOT)),project,
|
||||
args.has("assetUuid")?UUID.fromString(args.get("assetUuid").textValue()):null,
|
||||
text(args,"animatorId"),text(args,"clipName"),args.has("elapsedTicks")?args.get("elapsedTicks").longValue():null,
|
||||
args.has("paletteId")?args.get("paletteId").intValue():null,text(args,"expectedRevision"),
|
||||
args.has("document")?new AnimationCodec().decode(args.get("document").toString()):null,text(args,"proposalHash"),text(args,"expectedBankRevision")));
|
||||
ObjectNode value=mapper.valueToTree(response);
|
||||
canonicalView(mapper,value.get("view"));if(value.path("definitions").isArray())for(var view:value.get("definitions"))canonicalView(mapper,view);
|
||||
if(response.proposal()!=null)((ObjectNode)value.get("proposal")).set("document",mapper.readTree(new AnimationCodec().encode(response.proposal().document())));
|
||||
if(response.preview()!=null)((ObjectNode)value.get("preview")).remove("image");
|
||||
return McpToolResult.successWithCapture(mapper,value,response.preview()==null?null:response.preview().image(),false);
|
||||
}catch(ControlDeniedException|AutomationException authority){throw authority;}
|
||||
catch(IllegalArgumentException invalid){return McpToolResult.failure(mapper,new AutomationFailure(AutomationFailure.Code.ANIMATION_INVALID,invalid.getMessage()));}
|
||||
catch(IllegalStateException conflict){return McpToolResult.failure(mapper,new AutomationFailure(conflict.getMessage()!=null&&conflict.getMessage().contains("conflict")?AutomationFailure.Code.ANIMATION_CONFLICT:AutomationFailure.Code.INFRASTRUCTURE_FAILURE,conflict.getMessage()));}
|
||||
catch(java.io.IOException failure){throw new IllegalStateException("Cannot encode animation response",failure);}
|
||||
}
|
||||
private static String text(JsonNode node,String field){return node.hasNonNull(field)?node.get(field).textValue():null;}
|
||||
private static void canonicalView(ObjectMapper mapper,JsonNode view)throws java.io.IOException{
|
||||
if(view!=null&&view.isObject()&&view.hasNonNull("document"))((ObjectNode)view).set("document",mapper.readTree(view.required("json").asText()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user