mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Add pattern views to the studio tooling
A StudioView is now either a SceneView (block scenes) or a PatternView: entries a module lays out from above, one block per column, at a depth below the top, over a PatternArea. BlockPattern holds the picks and the blocks they index. Both kinds register through ToolingRegistry.registerView and share one id space in the host.
This commit is contained in:
1 parent
a658cd2446
commit
2befcb9487
13 files changed
+275
-59
No files matched your search
@@ -41,7 +41,7 @@ public final class FeatureCatalog {
|
||||
private final Map<Class<?>, List<ServiceRegistration>> registrationsByService;
|
||||
private final Map<Class<?>, List<?>> providersByService;
|
||||
private final Optional<PlacementTypeRegistration> placementType;
|
||||
private final List<SceneViewRegistration> sceneViews;
|
||||
private final List<StudioViewRegistration> studioViews;
|
||||
|
||||
FeatureCatalog(
|
||||
Map<Class<?>, FeatureDescriptor<?>> settings,
|
||||
@@ -52,9 +52,9 @@ public final class FeatureCatalog {
|
||||
List<LifecycleRegistration> lifecycles,
|
||||
List<ServiceRegistration> services,
|
||||
PlacementTypeRegistration placementType,
|
||||
Collection<SceneViewRegistration> sceneViews) {
|
||||
Collection<StudioViewRegistration> studioViews) {
|
||||
this.placementType = Optional.ofNullable(placementType);
|
||||
this.sceneViews = sorted(sceneViews, registration -> registration.view().id());
|
||||
this.studioViews = sorted(studioViews, registration -> registration.view().id());
|
||||
this.settings = Map.copyOf(settings);
|
||||
this.objects = Map.copyOf(objects);
|
||||
this.mantle = Map.copyOf(mantle);
|
||||
@@ -93,9 +93,9 @@ public final class FeatureCatalog {
|
||||
return validators;
|
||||
}
|
||||
|
||||
/** The studio scene views modules registered, by view id. */
|
||||
public List<SceneViewRegistration> sceneViews() {
|
||||
return sceneViews;
|
||||
/** The studio views modules registered, of every kind, by view id. */
|
||||
public List<StudioViewRegistration> studioViews() {
|
||||
return studioViews;
|
||||
}
|
||||
|
||||
/** The lifecycle hooks modules registered, by module id, each module's in the order it registered them. */
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.volmit.object.ObjectGeneratorFactory;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.service.Providers;
|
||||
import com.volmit.tooling.SceneView;
|
||||
import com.volmit.tooling.StudioView;
|
||||
import com.volmit.tooling.ToolingRegistry;
|
||||
import com.volmit.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,7 +31,7 @@ import java.util.Set;
|
||||
* settings ids must be the registering module's id or start with it and '/' ({@link com.volmit.ModuleInfo#ownsId}).
|
||||
* Resource kinds have unique ids, types and folders, and no kind may read a folder the host reserves for its own
|
||||
* files. Lifecycle hooks and service providers are registered by the module that owns them; a service whose providers
|
||||
* are {@link Providers#ONE} has at most one. Studio scene views have unique ids the registering module owns. A failed
|
||||
* are {@link Providers#ONE} has at most one. Studio views have ids unique across their kinds that the registering module owns. A failed
|
||||
* registration leaves the registry unchanged. A failed module callback invalidates the host's whole build. This does
|
||||
* not decode JSON, discover modules or instantiate settings.
|
||||
*/
|
||||
@@ -47,7 +47,7 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry {
|
||||
private final List<ValidatorRegistration> validators = new ArrayList<>();
|
||||
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
|
||||
private final List<ServiceRegistration> services = new ArrayList<>();
|
||||
private final Map<ResourceId, SceneViewRegistration> sceneViews = new HashMap<>();
|
||||
private final Map<ResourceId, StudioViewRegistration> studioViews = new HashMap<>();
|
||||
private final Set<String> reservedFolders;
|
||||
private final List<DiscoveredModule> registered = new ArrayList<>();
|
||||
private PlacementTypeRegistration placementType;
|
||||
@@ -199,18 +199,18 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSceneView(SceneView view) {
|
||||
public void registerView(StudioView view) {
|
||||
checkOpen();
|
||||
Objects.requireNonNull(view, "view");
|
||||
ResourceId id = Objects.requireNonNull(view.id(), "view id");
|
||||
requireOwnedId("Scene view", id);
|
||||
var added = new SceneViewRegistration(view, registering);
|
||||
var existing = sceneViews.get(id);
|
||||
requireOwnedId("Studio view", id);
|
||||
var added = new StudioViewRegistration(view, registering);
|
||||
var existing = studioViews.get(id);
|
||||
if (existing != null) {
|
||||
throw new IllegalArgumentException("Scene view " + id + " is registered by module " + existing.module()
|
||||
throw new IllegalArgumentException("Studio view " + id + " is registered by module " + existing.module()
|
||||
+ " already, and module " + added.module() + " registers it too; give one of them another id");
|
||||
}
|
||||
sceneViews.put(id, added);
|
||||
studioViews.put(id, added);
|
||||
}
|
||||
|
||||
/** Catalogs a settings type named by a stage's when(...), whose owner {@link StageGraphBuilder}
|
||||
@@ -234,7 +234,7 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry {
|
||||
public FeatureCatalog freeze() {
|
||||
if (catalog == null) {
|
||||
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services,
|
||||
placementType, sceneViews.values());
|
||||
placementType, studioViews.values());
|
||||
}
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.tooling.SceneView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** A studio scene view and the module that registered it. */
|
||||
public record SceneViewRegistration(SceneView view, DiscoveredModule module) {
|
||||
public SceneViewRegistration {
|
||||
Objects.requireNonNull(view, "view");
|
||||
Objects.requireNonNull(module, "module");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "scene view " + view.id() + " of module " + module;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.tooling.PatternView;
|
||||
import com.volmit.tooling.SceneView;
|
||||
import com.volmit.tooling.StudioView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** A studio view and the module that registered it. */
|
||||
public record StudioViewRegistration(StudioView view, DiscoveredModule module) {
|
||||
public StudioViewRegistration {
|
||||
Objects.requireNonNull(view, "view");
|
||||
Objects.requireNonNull(module, "module");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return kindOf(view) + " " + view.id() + " of module " + module;
|
||||
}
|
||||
|
||||
static String kindOf(StudioView view) {
|
||||
return switch (view) {
|
||||
case SceneView ignored -> "scene view";
|
||||
case PatternView ignored -> "pattern view";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -119,25 +119,41 @@ class ModuleRegistryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void sceneViewsHaveUniqueIdsTheirModuleOwnsAndAreCataloguedById() {
|
||||
void studioViewsHaveIdsUniqueAcrossKindsTheirModuleOwnsAndAreCataloguedById() {
|
||||
var registry = new ModuleRegistry();
|
||||
ModuleSetups.run(DiscoveredModule.builtIn(new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("iris:objects", "Objects", "1"); }
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.tooling().registerSceneView(sceneView("iris:objects/procedural"));
|
||||
setup.tooling().registerSceneView(sceneView("iris:objects"));
|
||||
setup.tooling().registerView(sceneView("iris:objects/procedural"));
|
||||
setup.tooling().registerView(sceneView("iris:objects"));
|
||||
setup.tooling().registerView(patternView("iris:objects/footprints"));
|
||||
var duplicate = assertThrows(IllegalArgumentException.class,
|
||||
() -> setup.tooling().registerSceneView(sceneView("iris:objects")));
|
||||
assertTrue(duplicate.getMessage().contains("Scene view iris:objects is registered by module"), duplicate.getMessage());
|
||||
() -> setup.tooling().registerView(patternView("iris:objects")));
|
||||
assertTrue(duplicate.getMessage().contains("Studio view iris:objects is registered by module"), duplicate.getMessage());
|
||||
var foreign = assertThrows(IllegalArgumentException.class,
|
||||
() -> setup.tooling().registerSceneView(sceneView("iris:terrain/palettes")));
|
||||
() -> setup.tooling().registerView(sceneView("iris:terrain/palettes")));
|
||||
assertTrue(foreign.getMessage().contains("must be iris:objects or start with iris:objects/"), foreign.getMessage());
|
||||
}
|
||||
}), new StageGraphBuilder(), registry);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerSceneView(sceneView("iris:objects/loose")));
|
||||
assertEquals(List.of("iris:objects", "iris:objects/procedural"),
|
||||
registry.freeze().sceneViews().stream().map(view -> view.view().id().toString()).toList());
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerView(sceneView("iris:objects/loose")));
|
||||
var views = registry.freeze().studioViews();
|
||||
assertEquals(List.of("iris:objects", "iris:objects/footprints", "iris:objects/procedural"),
|
||||
views.stream().map(view -> view.view().id().toString()).toList());
|
||||
assertTrue(views.get(1).toString().startsWith("pattern view iris:objects/footprints of module"), views.get(1).toString());
|
||||
}
|
||||
|
||||
private static com.volmit.tooling.PatternView patternView(String id) {
|
||||
return new com.volmit.tooling.PatternView() {
|
||||
public com.volmit.resource.ResourceId id() { return com.volmit.resource.ResourceId.parse(id); }
|
||||
public String label() { return id; }
|
||||
public String description() { return id; }
|
||||
public List<com.volmit.tooling.PatternEntry> entries(com.volmit.world.PackWorld world) { return List.of(); }
|
||||
public Optional<com.volmit.tooling.BlockPattern> pattern(com.volmit.world.PackWorld world, String key, int depth,
|
||||
com.volmit.tooling.PatternArea area) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static com.volmit.tooling.SceneView sceneView(String id) {
|
||||
|
||||
Reference in new issue
Block a user