Interface IScriptRunModuleConfigurator

All Known Implementing Classes:
DefaultScriptRunModuleConfigurator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface IScriptRunModuleConfigurator
Configures the list of JavaNativeModules for a particular IScriptRun.

Each IScriptLoader requires an instance of this class to ensure proper creation of the environment for a script run.

A script run module configurator is responsible for gathering the exposed classes and expansions from the ICraftTweakerRegistry and using the information exposed by ScriptRunConfiguration to create the various ZenCode modules that will then be used to build the ZenCode scripting environment and run scripts.

There are no restrictions on the amount of modules that should be created or on the relationship between them: it is up to the implementation of this class to ensure that the configuration created is valid and will not cause errors at runtime.

This method is a functional interface whose functional method is populateModules(ICraftTweakerRegistry, ScriptRunConfiguration, ModuleCreator).

Since:
9.1.0
  • Method Details

    • createDefault

      static IScriptRunModuleConfigurator createDefault(String basePackage)
      Creates a default IScriptRunModuleConfigurator for the given base package.

      The default configurator automatically sets up a hierarchy of modules, with the module for basePackage sitting at the root of the hierarchy and all expansions being gathered in a special module.

      To be more precise, the basePackage is used to gather all classes contained in it and all subpackages and package them into a module with the same name. All the other packages are then scanned and grouped based on their root package. Each root package gives birth to a module that depends uniquely on the basePackage module. At the end, all expansions are then gathered into an "expansions" module, which depends on all previously created modules.

      As an example, if the basePackage is foo and there are classes in both the bar and baz root packages, four modules will be created. The foo module will sit at the root of the hierarchy. Two modules, bar and baz, will then be created and both will depend on foo. Lastly, a fourth module named "expansions" will be created and it will depend on foo, bar, and baz.

      Parameters:
      basePackage - The base package which will be queried to create the base module.
      Returns:
      A script run module configurator carrying out the operations specified above.
      Since:
      9.1.0
    • populateModules

      Creates all necessary modules for a particular script run.
      Parameters:
      registry - An instance of ICraftTweakerRegistry from which to grab classes and other data for the creation and configuration of the modules.
      configuration - The ScriptRunConfiguration for which the script run should be created.
      creator - A IScriptRunModuleConfigurator.ModuleCreator which is responsible for the actual creation of the modules. Refer to IScriptRunModuleConfigurator.ModuleCreator.createNativeModule(String, String, List, Consumer) for more information.
      Returns:
      A Collection with all JavaNativeModules that have been created. The list need not be ordered.
      Throws:
      CompileException - If the creation of any of the module fails for any reason.
      Since:
      9.1.0