Search in sources :

Example 1 with SimpleUri

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

the class WorldSerializerImpl method createPrefab.

private void createPrefab(EntityData.Prefab prefabData) {
    SimpleUri uri = new SimpleUri(prefabData.getName());
    try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(moduleManager.getEnvironment().get(uri.getModuleName()))) {
        PrefabData protoPrefab = prefabSerializer.deserialize(prefabData);
        Assets.generateAsset(new ResourceUrn(prefabData.getName()), protoPrefab, Prefab.class);
    } catch (Exception e) {
        logger.error("Failed to create prefab {}", prefabData.getName());
    }
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleContext(org.terasology.engine.core.module.ModuleContext) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 2 with SimpleUri

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

the class WorldGeneratorManager method refresh.

public void refresh() {
    ModuleManager moduleManager = verifyNotNull(context.get(ModuleManager.class), "no ModuleManager");
    List<WorldGeneratorInfo> infos = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        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.engine.world.generator.RegisterWorldGenerator) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 3 with SimpleUri

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

the class WorldGeneratorManagerTest method hasUnittestWorldGenerator.

@Test
void hasUnittestWorldGenerator() {
    manager = new WorldGeneratorManager(context);
    assertThat(manager.getWorldGenerators()).comparingElementsUsing(Correspondence.transforming(WorldGeneratorInfo::getUri, "info")).contains(new SimpleUri("unittest:stub"));
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleUri

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

the class InputSystemTests method testKeyBinding.

@Test
public void testKeyBinding() {
    Map<Integer, BindableButton> keyBinds = new HashMap<>();
    // mock binding to the TestEventButton, this is done by the BindsManager over the annotations by default
    keyBinds.put(KeyId.T, new BindableButtonImpl(new SimpleUri("engine-tests", "testEvent"), "theTestEvent", new TestEventButton()));
    when(bindsManager.getKeyBinds()).thenReturn(keyBinds);
    pressKey(Key.T);
    inputSystem.update(1f);
    verify(clientEntity).send(Mockito.any(TestEventButton.class));
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) HashMap(java.util.HashMap) SimpleUri(org.terasology.engine.core.SimpleUri) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) Test(org.junit.jupiter.api.Test)

Example 5 with SimpleUri

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

the class AbstractNode method isDependentOn.

/**
 * Is {@code thisNode} dependent on {@param anotherNode}?
 * @param anotherNode
 * @return If this node has at least one {@param anotherNode}'s connection on input - true. Otherwise false.
 */
public boolean isDependentOn(Node anotherNode) {
    boolean isDependent = false;
    // for all my input connections
    for (DependencyConnection connection : inputConnections.values()) {
        if (!connection.getConnectedConnections().isEmpty()) {
            Map<String, DependencyConnection> connectedConnections = connection.getConnectedConnections();
            SimpleUri anotherNodeUri = anotherNode.getUri();
            // for all connection's connected connections get parent node and see if it matches anotherNode
            for (DependencyConnection connectedConnection : connectedConnections.values()) {
                if (connectedConnection.getParentNode().equals(anotherNodeUri)) {
                    isDependent = true;
                }
            }
        }
    }
    return isDependent;
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection) 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