Search in sources :

Example 11 with ModuleEnvironment

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

the class NUIManagerInternal method refreshWidgetsLibrary.

public void refreshWidgetsLibrary() {
    widgetsLibrary = new WidgetLibrary(context);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    for (Class<? extends UIWidget> type : environment.getSubtypesOf(UIWidget.class)) {
        widgetsLibrary.register(new SimpleUri(environment.getModuleProviding(type), type.getSimpleName()), type);
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) SimpleUri(org.terasology.engine.SimpleUri) ModuleManager(org.terasology.engine.module.ModuleManager)

Example 12 with ModuleEnvironment

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = new ColumnLayout();
    mainLayout.setHorizontalSpacing(8);
    mainLayout.setVerticalSpacing(8);
    mainLayout.setFamily("option-grid");
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu#category-mouse}")));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (module.isCodeModule()) {
            ResolutionResult result = resolver.resolve(moduleId);
            if (result.isSuccess()) {
                try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                    for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                        InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                        inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                    }
                    for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                        if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                            RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                            inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                        }
                    }
                }
            }
        }
    }
    addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
    for (InputCategory category : inputCategories.values()) {
        addInputSection(category, mainLayout, inputsById);
    }
    mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
    List<String> controllers = inputSystem.getControllerDevice().getControllers();
    for (String name : controllers) {
        ControllerInfo cfg = inputDeviceConfiguration.getController(name);
        addInputSection(mainLayout, name, cfg);
    }
    ScrollableArea area = find("area", ScrollableArea.class);
    area.setContent(mainLayout);
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RegisterBindButton(org.terasology.input.RegisterBindButton) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) FromModule(org.terasology.module.predicates.FromModule) Module(org.terasology.module.Module) FromModule(org.terasology.module.predicates.FromModule) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo)

Example 13 with ModuleEnvironment

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

the class WorldGeneratorManager method refresh.

public void refresh() {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    List<WorldGeneratorInfo> infos = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (module.isCodeModule()) {
            DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
            ResolutionResult resolutionResult = resolver.resolve(module.getId());
            if (resolutionResult.isSuccess()) {
                try (ModuleEnvironment tempEnvironment = moduleManager.loadEnvironment(resolutionResult.getModules(), false)) {
                    for (Class<?> generatorClass : tempEnvironment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) {
                        if (tempEnvironment.getModuleProviding(generatorClass).equals(module.getId())) {
                            RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class);
                            if (isValidWorldGenerator(generatorClass)) {
                                SimpleUri uri = new SimpleUri(moduleId, annotation.id());
                                infos.add(new WorldGeneratorInfo(uri, annotation.displayName(), annotation.description()));
                            } else {
                                logger.error("{} marked to be registered as a World Generator, but is not a subclass of WorldGenerator or lacks the correct constructor", generatorClass);
                            }
                        }
                    }
                } catch (Exception e) {
                    logger.error("Error loading world generator in module {}, skipping", module.getId(), e);
                }
            } else {
                logger.warn("Could not resolve dependencies for module: {}", module);
            }
        }
    }
    Collections.sort(infos);
    generatorInfo = ImmutableList.copyOf(infos);
}
Also used : RegisterWorldGenerator(org.terasology.world.generator.RegisterWorldGenerator) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) UnresolvedWorldGeneratorException(org.terasology.world.generator.UnresolvedWorldGeneratorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(org.terasology.naming.Name) DependencyResolver(org.terasology.module.DependencyResolver)

Example 14 with ModuleEnvironment

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

the class WorldGeneratorManager method createGenerator.

/**
 * @param uri uri of the world generator to create.
 * @param context objects from this context will be injected into the
 * @return The instantiated world generator.
 */
public static WorldGenerator createGenerator(SimpleUri uri, Context context) throws UnresolvedWorldGeneratorException {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    Module module = moduleManager.getEnvironment().get(uri.getModuleName());
    if (module == null) {
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(uri.getModuleName());
        if (!result.isSuccess()) {
            if (moduleManager.getRegistry().getLatestModuleVersion(uri.getModuleName()) == null) {
                throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
            } else {
                throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - unable to resolve module dependencies");
            }
        }
        try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
            return createWorldGenerator(uri, context, environment);
        }
    } else {
        return createWorldGenerator(uri, context, moduleManager.getEnvironment());
    }
}
Also used : UnresolvedWorldGeneratorException(org.terasology.world.generator.UnresolvedWorldGeneratorException) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) DependencyResolver(org.terasology.module.DependencyResolver)

Example 15 with ModuleEnvironment

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

the class StateIngame method dispose.

@Override
public void dispose(boolean shuttingDown) {
    ChunkProvider chunkProvider = context.get(ChunkProvider.class);
    chunkProvider.dispose();
    boolean save = networkSystem.getMode().isAuthority();
    if (save) {
        storageManager.waitForCompletionOfPreviousSaveAndStartSaving();
    }
    networkSystem.shutdown();
    // TODO: Shutdown background threads
    eventSystem.process();
    GameThread.processWaitingProcesses();
    nuiManager.clear();
    context.get(AudioManager.class).stopAllSounds();
    if (worldRenderer != null) {
        worldRenderer.dispose();
        worldRenderer = null;
    }
    componentSystemManager.shutdown();
    context.get(PhysicsEngine.class).dispose();
    entityManager.clear();
    if (storageManager != null) {
        storageManager.finishSavingAndShutdown();
    }
    ModuleEnvironment oldEnvironment = context.get(ModuleManager.class).getEnvironment();
    context.get(ModuleManager.class).loadEnvironment(Collections.<Module>emptySet(), true);
    if (!shuttingDown) {
        context.get(EnvironmentSwitchHandler.class).handleSwitchToEmptyEnvironment(context);
    }
    if (oldEnvironment != null) {
        oldEnvironment.close();
    }
    console.dispose();
    GameThread.clearWaitingProcesses();
    /*
         * Clear the binding as otherwise the complete ingame state would be
         * referenced.
         */
    nuiManager.getHUD().clearVisibleBinding();
}
Also used : AudioManager(org.terasology.audio.AudioManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) PhysicsEngine(org.terasology.physics.engine.PhysicsEngine) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ModuleManager(org.terasology.engine.module.ModuleManager) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler)

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