Search in sources :

Example 21 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class BindsSubsystem method addButtonDefaultsFor.

private void addButtonDefaultsFor(Name moduleId, Iterable<Class<?>> classes, BindsConfiguration config) {
    for (Class<?> buttonEvent : classes) {
        if (ButtonEvent.class.isAssignableFrom(buttonEvent)) {
            RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
            SimpleUri bindUri = new SimpleUri(moduleId, info.id());
            if (!config.hasBinds(bindUri)) {
                addDefaultBindings(bindUri, buttonEvent, config);
            }
        }
    }
}
Also used : RegisterBindButton(org.terasology.engine.input.RegisterBindButton) SimpleUri(org.terasology.engine.core.SimpleUri)

Example 22 with SimpleUri

use of org.terasology.engine.core.SimpleUri 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 : RegisterBindButton(org.terasology.engine.input.RegisterBindButton) BindsConfiguration(org.terasology.engine.config.facade.BindsConfiguration) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) ModuleManager(org.terasology.engine.core.module.ModuleManager) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) BindsConfig(org.terasology.engine.config.BindsConfig) FromModule(org.terasology.gestalt.module.predicates.FromModule) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) DefaultBinding(org.terasology.engine.input.DefaultBinding) Map(java.util.Map) Input(org.terasology.input.Input) RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) MouseInput(org.terasology.input.MouseInput) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) InputType(org.terasology.input.InputType) Logger(org.slf4j.Logger) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection) AxisEvent(org.terasology.engine.input.events.AxisEvent) BindableAxisImpl(org.terasology.engine.input.internal.BindableAxisImpl) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) Maps(com.google.common.collect.Maps) BindableButton(org.terasology.engine.input.BindableButton) SimpleUri(org.terasology.engine.core.SimpleUri) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) Annotation(java.lang.annotation.Annotation) BindableAxis(org.terasology.engine.input.BindableAxis) BindableRealAxis(org.terasology.engine.input.internal.BindableRealAxis) ButtonEvent(org.terasology.engine.input.events.ButtonEvent) Name(org.terasology.gestalt.naming.Name) BindableButton(org.terasology.engine.input.BindableButton) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) SimpleUri(org.terasology.engine.core.SimpleUri)

Example 23 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class LocalPlayerSystem method startAutoMove.

/**
 * Append the input for moving forward to the keyboard command queue to simulate pressing of the forward key. For an
 * input that repeats, the key must be in Down state before Repeat state can be applied to it.
 */
private void startAutoMove() {
    isAutoMove = false;
    List<Input> inputs = bindsManager.getBindsConfig().getBinds(new SimpleUri("engine:forwards"));
    Input forwardKey = getValidKey(inputs);
    if (forwardKey != null) {
        isAutoMove = true;
        inputSystem.simulateSingleKeyStroke(forwardKey);
        inputSystem.simulateRepeatedKeyStroke(forwardKey);
    }
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.core.SimpleUri)

Example 24 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class GameManifestProvider method createGameManifest.

/**
 * Generates game manifest with default settings (title, seed) if not specified.
 * Uses default world generator, and modules selection.
 * @TODO: rewrite/fix it when code will be more stable
 *
 * @param universeWrapper  contains the universe level properties
 * @param moduleManager    resolves modules
 * @param config           provides default module selection, world generator
 * @return                 game manifest with default settings
 */
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
    GameManifest gameManifest = new GameManifest();
    if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
        gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
    } else {
        gameManifest.setTitle(GameProvider.getNextGameName());
    }
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (!result.isSuccess()) {
        logger.error("Can't resolve dependencies");
        return null;
    }
    for (Module module : result.getModules()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    SimpleUri uri;
    String seed;
    WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
    if (worldSetup != null) {
        uri = worldSetup.getWorldGenerator().getUri();
        seed = worldSetup.getWorldGenerator().getWorldSeed();
    } else {
        uri = config.getWorldGeneration().getDefaultGenerator();
        seed = universeWrapper.getSeed();
    }
    gameManifest.setSeed(seed);
    String targetWorldName = "";
    Map<String, Component> worldConfig = Maps.newHashMap();
    if (worldSetup != null) {
        targetWorldName = worldSetup.getWorldName().toString();
        if (worldSetup.getWorldConfigurator() != null) {
            // horrible hack to get configs into manifest.
            // config driven by CreateWorldEntity.
            // world config set somewhere else as well no clear drive from config --> world
            gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
        }
    }
    // This is multiplied by the number of seconds in a day (86400000) to determine the exact  millisecond at which the game will start.
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
    gameManifest.addWorld(worldInfo);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 25 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class BindsSubsystem method addAxisDefaultsFor.

private void addAxisDefaultsFor(Name moduleId, Iterable<Class<?>> classes, BindsConfiguration config) {
    for (Class<?> axisEvent : classes) {
        if (AxisEvent.class.isAssignableFrom(axisEvent)) {
            RegisterRealBindAxis info = axisEvent.getAnnotation(RegisterRealBindAxis.class);
            SimpleUri bindUri = new SimpleUri(moduleId, info.id());
            if (!config.hasBinds(bindUri)) {
                addDefaultBindings(bindUri, axisEvent, config);
            }
        }
    }
}
Also used : RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) SimpleUri(org.terasology.engine.core.SimpleUri)

Aggregations

SimpleUri (org.terasology.engine.core.SimpleUri)51 Name (org.terasology.gestalt.naming.Name)13 Map (java.util.Map)6 ModuleManager (org.terasology.engine.core.module.ModuleManager)6 FBO (org.terasology.engine.rendering.opengl.FBO)6 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)6 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 Config (org.terasology.engine.config.Config)5 BindableButton (org.terasology.engine.input.BindableButton)5 Module (org.terasology.gestalt.module.Module)5 Input (org.terasology.input.Input)5 Test (org.junit.jupiter.api.Test)4 RegisterBindButton (org.terasology.engine.input.RegisterBindButton)4 Lists (com.google.common.collect.Lists)3 List (java.util.List)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 GameManifest (org.terasology.engine.game.GameManifest)3 FboConfig (org.terasology.engine.rendering.opengl.FboConfig)3