Terasology / ModuleTestingEnvironment

3 stars 15 forks source link

add ability to use assets defined in src/test #71

Open keturn opened 3 years ago

keturn commented 3 years ago

I was looking at writing tests for DynamicCities. It has systems that depend heavily on prefab assets for configuration. Sure, we can change those things to add programmatic interfaces for configuration as well, but it's a reasonable design: Configuration of these things should be data-driven, and the way modules load data is through the asset manager.

But I don't want the assets I define for specific test scenarios mixed in with all the other assets meant for gameplay.

[original discussion]

keturn commented 3 years ago

dumping a draft here:

class ModuleFactory {
    public static Module registerClasspathAssets(String packageName) {
        // This is essentially ModuleFactory.createPackageModule, but for only assets (no classes) and
        // no support for precompiled reflections cache.
        ModuleMetadata metadata = new ModuleMetadata(new Name(packageName), new Version(0, 0, 1));
        Reflections assetManifest = new Reflections(new ConfigurationBuilder()
                .addScanners(new ResourcesScanner())
                .forPackages(packageName)
        );
        ModuleFileSource fileSource = new ClasspathFileSource(assetManifest, packageName.replace('.', '/'));
        return new Module(metadata, fileSource, Collections.emptyList(), assetManifest, x -> false);
    }
}