Terasology / ModuleTestingEnvironment

3 stars 15 forks source link

add ability to use a WorldGenerator defined in src/test (not src/main) #70

Open keturn opened 2 years ago

keturn commented 2 years ago

MTE has a way to specify which world generator should be used: The @UseWorldGenerator annotation.

That works fine for WorldGenerators defined in the module or dependencies of the module, but it does not currently allow you to define a WorldGenerator in your classes under the src/test sources.

It would be nice to be able to do so. With the current limitation, any world generators defined for testing (i.e. to make worlds that have very specific properties in predicable places, unlike the random worlds for game modes) will show up mixed in with the other world types that are provided for gameplay.

[original discussion]

keturn commented 2 years ago

A few possible ways to go about this:

  1. Change ModuleManager (and perhaps the ModuleFactory it uses when running tests) to make sure its class-manifest scans include the classes in both the main and test source sets. I think that should be sufficient for the RegisterWorldGenerator annotation to work successfully in test sources.

  2. Alternatively, instead of taking a URI in UseWorldGenerator and using a registry to resolve it, take a direct class reference: @UseWorldGenerator(CitiesTestWorld.class)

There are some obstacles to using a class reference there: We really want to build a GameManifest for the game we're about to launch, and the GameManifest doesn't currently have any interface for a world type without a registered URI. Some creativity will be required to get past that, but in the end I think being able to use a class reference will make the tests easier to navigate.

Cervator commented 2 years ago

I threw this note on Discord but just so we don't forget: another (simple) possibility is using some sort of debug annotation on world generators, to mark them to not show up in the available list in-game - potentially unless a player toggles a debug mode. That lets a player still try them out and lets you safely define test-only generators.