Search in sources :

Example 26 with SimpleUri

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

the class BindsSubsystem method registerAxisBinds.

private void registerAxisBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindAxis.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindAxis info = registerBindClass.getAnnotation(RegisterBindAxis.class);
        Name moduleId = environment.getModuleProviding(registerBindClass);
        SimpleUri id = new SimpleUri(moduleId, info.id());
        if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
            BindableButton positiveButton = getBindButton(new SimpleUri(info.positiveButton()));
            BindableButton negativeButton = getBindButton(new SimpleUri(info.negativeButton()));
            if (positiveButton == null) {
                logger.warn("Failed to register axis \"{}\", missing positive button \"{}\"", id, info.positiveButton());
                continue;
            }
            if (negativeButton == null) {
                logger.warn("Failed to register axis \"{}\", missing negative button \"{}\"", id, info.negativeButton());
                continue;
            }
            try {
                BindableAxis bindAxis = registerBindAxis(id.toString(), (BindAxisEvent) registerBindClass.newInstance(), positiveButton, negativeButton);
                bindAxis.setSendEventMode(info.eventMode());
                logger.debug("Registered axis bind: {}", id);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register axis bind \"{}\"", id, e);
            }
        } else {
            logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
        }
    }
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) SimpleUri(org.terasology.engine.core.SimpleUri) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.engine.input.BindableAxis) Name(org.terasology.gestalt.naming.Name)

Example 27 with SimpleUri

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

the class BindsSubsystem method registerRealAxisBinds.

private void registerRealAxisBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class);
    for (Class<?> registerBindClass : classes) {
        RegisterRealBindAxis info = registerBindClass.getAnnotation(RegisterRealBindAxis.class);
        Name moduleId = environment.getModuleProviding(registerBindClass);
        SimpleUri id = new SimpleUri(moduleId, info.id());
        if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
            try {
                BindAxisEvent instance = (BindAxisEvent) registerBindClass.newInstance();
                BindableAxis bindAxis = registerRealBindAxis(id.toString(), instance);
                bindAxis.setSendEventMode(info.eventMode());
                for (Input input : bindsConfiguration.getBinds(id)) {
                    linkAxisToInput(input, id);
                }
                logger.debug("Registered axis bind: {}", id);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register axis bind \"{}\"", id, e);
            }
        } else {
            logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
        }
    }
}
Also used : RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) ControllerInput(org.terasology.input.ControllerInput) Input(org.terasology.input.Input) MouseInput(org.terasology.input.MouseInput) SimpleUri(org.terasology.engine.core.SimpleUri) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.engine.input.BindableAxis) Name(org.terasology.gestalt.naming.Name)

Example 28 with SimpleUri

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

the class StateHeadlessSetup method createGameManifest.

public GameManifest createGameManifest() {
    GameManifest gameManifest = new GameManifest();
    Config config = context.get(Config.class);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    for (Name moduleName : config.getDefaultModSelection().listModules()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
        if (module != null) {
            gameManifest.addModule(module.getId(), module.getVersion());
        } else {
            logger.warn("ModuleRegistry has no latest version for module {}", moduleName);
        }
    }
    WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
    // If no valid default world generator set then try to find one - no option to pick one manually in headless
    if (!worldGenConfig.getDefaultGenerator().isValid()) {
        // find the first gameplay module that is available, it should have a preferred world gen
        for (Name moduleName : config.getDefaultModSelection().listModules()) {
            Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
            if (StandardModuleExtension.isGameplayModule(module)) {
                SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
                worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
                break;
            }
        }
    }
    SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
    gameManifest.setTitle(worldGenConfig.getWorldTitle());
    gameManifest.setSeed(worldGenConfig.getDefaultSeed());
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, worldGenConfig.getWorldTitle(), gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), worldGeneratorUri);
    gameManifest.addWorld(worldInfo);
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Name(org.terasology.gestalt.naming.Name)

Example 29 with SimpleUri

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

the class BehaviorNodeFactory method determineAnimationPoolUris.

private List<ComponentFieldUri> determineAnimationPoolUris() {
    final List<ComponentFieldUri> animationSetUris = Lists.newArrayList();
    for (ComponentMetadata<?> componentMetadata : componentLibrary.iterateComponentMetadata()) {
        SimpleUri uri = new SimpleUri(componentMetadata.getId().toString());
        for (FieldMetadata<?, ?> fieldMetadata : componentMetadata.getFields()) {
            if (fieldMetadata.getType().isAssignableFrom(List.class)) {
                Type fieldType = fieldMetadata.getField().getGenericType();
                if (fieldType instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) fieldType;
                    Type[] typeArguments = parameterizedType.getActualTypeArguments();
                    if (typeArguments.length == 1) {
                        Class<?> typeClass = ReflectionUtil.getRawType(typeArguments[0]);
                        if (typeClass.isAssignableFrom(MeshAnimation.class)) {
                            animationSetUris.add(new ComponentFieldUri(uri, fieldMetadata.getName()));
                        }
                    }
                }
            }
        }
    }
    return animationSetUris;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SimpleUri(org.terasology.engine.core.SimpleUri) ComponentFieldUri(org.terasology.engine.core.ComponentFieldUri)

Example 30 with SimpleUri

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

the class BindsSubsystemTest method testRegisterBinds.

@Test
public void testRegisterBinds() {
    registerBindButtonClasses.add(TestEventButton.class);
    bindsSubsystem.updateConfigWithDefaultBinds();
    bindsSubsystem.registerBinds();
    BindableButton button = bindsSubsystem.getKeyBinds().get(KeyId.T);
    assertNotNull(button);
    assertEquals(button.getId(), new SimpleUri(TEST_MODULE, "testEvent"));
    assertEquals(button.getDisplayName(), "${engine-tests:menu#theTestEvent}");
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) SimpleUri(org.terasology.engine.core.SimpleUri) Test(org.junit.jupiter.api.Test)

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