Search in sources :

Example 16 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class RegisterBiomes method step.

@Override
public boolean step() {
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    ModuleEnvironment moduleEnvironment = context.get(ModuleManager.class).getEnvironment();
    BiomeManager biomeManager;
    if (networkSystem.getMode().isAuthority()) {
        biomeManager = new BiomeManager(moduleEnvironment, gameManifest.getBiomeIdMap());
    // biomeManager.subscribe(CoreRegistry.get(NetworkSystem.class));
    // TODO figure out what this does
    } else {
        biomeManager = new BiomeManager(moduleEnvironment, gameManifest.getBiomeIdMap());
    }
    context.put(BiomeManager.class, biomeManager);
    // This registration is for other modules
    context.put(BiomeRegistry.class, biomeManager);
    return true;
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) NetworkSystem(org.terasology.network.NetworkSystem) ModuleManager(org.terasology.engine.module.ModuleManager)

Example 17 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class RegisterMods method step.

@Override
public boolean step() {
    if (applyModulesThread != null) {
        if (!applyModulesThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else {
        ModuleManager moduleManager = context.get(ModuleManager.class);
        List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(moduleIds);
        if (result.isSuccess()) {
            oldEnvironment = moduleManager.getEnvironment();
            ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
            for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
                logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
            }
            EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
            applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
            applyModulesThread.start();
            return false;
        } else {
            logger.warn("Missing at least one required module or dependency: {}", moduleIds);
            context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
            return true;
        }
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.modes.StateMainMenu) ResolutionResult(org.terasology.module.ResolutionResult) GameEngine(org.terasology.engine.GameEngine) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) Name(org.terasology.naming.Name) DependencyResolver(org.terasology.module.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler)

Example 18 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class BindsSubsystem method updateDefaultBinds.

private void updateDefaultBinds(Context passedContext, BindsConfiguration config) {
    ModuleManager moduleManager = passedContext.get(ModuleManager.class);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
            ResolutionResult result = resolver.resolve(moduleId);
            if (result.isSuccess()) {
                try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                    FromModule filter = new FromModule(environment, moduleId);
                    Iterable<Class<?>> buttons = environment.getTypesAnnotatedWith(RegisterBindButton.class, filter);
                    Iterable<Class<?>> axes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class, filter);
                    addButtonDefaultsFor(moduleId, buttons, config);
                    addAxisDefaultsFor(moduleId, axes, config);
                }
            }
        }
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleManager(org.terasology.engine.module.ModuleManager) FromModule(org.terasology.module.predicates.FromModule) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name)

Example 19 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class BindsSubsystem method registerButtonBinds.

private void registerButtonBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
        SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
        if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
            try {
                BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
                bindButton.setMode(info.mode());
                bindButton.setRepeating(info.repeating());
                bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
                logger.debug("Registered button bind: {}", bindUri);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register button bind \"{}\"", e);
            }
        } else {
            logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
        }
    }
}
Also used : BindsConfiguration(org.terasology.config.facade.BindsConfiguration) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) DependencyResolver(org.terasology.module.DependencyResolver) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) RegisterBindAxis(org.terasology.input.RegisterBindAxis) FromModule(org.terasology.module.predicates.FromModule) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) ButtonEvent(org.terasology.input.events.ButtonEvent) ResolutionResult(org.terasology.module.ResolutionResult) Map(java.util.Map) Input(org.terasology.input.Input) BindableRealAxis(org.terasology.input.internal.BindableRealAxis) SimpleUri(org.terasology.engine.SimpleUri) MouseInput(org.terasology.input.MouseInput) BindAxisEvent(org.terasology.input.BindAxisEvent) BindableButton(org.terasology.input.BindableButton) AxisEvent(org.terasology.input.events.AxisEvent) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) Name(org.terasology.naming.Name) ModuleManager(org.terasology.engine.module.ModuleManager) InputType(org.terasology.input.InputType) Context(org.terasology.context.Context) Logger(org.slf4j.Logger) BindableAxis(org.terasology.input.BindableAxis) Collection(java.util.Collection) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BindableAxisImpl(org.terasology.input.internal.BindableAxisImpl) Maps(com.google.common.collect.Maps) List(java.util.List) BindsConfig(org.terasology.config.BindsConfig) DefaultBinding(org.terasology.input.DefaultBinding) RegisterBindButton(org.terasology.input.RegisterBindButton) BindButtonEvent(org.terasology.input.BindButtonEvent) Annotation(java.lang.annotation.Annotation) RegisterRealBindAxis(org.terasology.input.RegisterRealBindAxis) BindableButtonImpl(org.terasology.input.internal.BindableButtonImpl) BindableButton(org.terasology.input.BindableButton) RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri)

Example 20 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class BindsSubsystem method registerBinds.

@Override
public void registerBinds() {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment environment = moduleManager.getEnvironment();
    clearBinds();
    registerButtonBinds(environment);
    registerAxisBinds(environment);
    registerRealAxisBinds(environment);
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ModuleManager(org.terasology.engine.module.ModuleManager)

Aggregations

ModuleEnvironment (org.terasology.module.ModuleEnvironment)23 ModuleManager (org.terasology.engine.module.ModuleManager)18 DependencyResolver (org.terasology.module.DependencyResolver)9 Module (org.terasology.module.Module)9 ResolutionResult (org.terasology.module.ResolutionResult)9 Name (org.terasology.naming.Name)8 FromModule (org.terasology.module.predicates.FromModule)5 SimpleUri (org.terasology.engine.SimpleUri)4 RegisterBindButton (org.terasology.input.RegisterBindButton)4 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)2 StateMainMenu (org.terasology.engine.modes.StateMainMenu)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 RegisterBindAxis (org.terasology.input.RegisterBindAxis)2 NetworkSystem (org.terasology.network.NetworkSystem)2 WorldProvider (org.terasology.world.WorldProvider)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 BlockManager (org.terasology.world.block.BlockManager)2 UnresolvedWorldGeneratorException (org.terasology.world.generator.UnresolvedWorldGeneratorException)2 WorldInfo (org.terasology.world.internal.WorldInfo)2 Lists (com.google.common.collect.Lists)1