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());
}
}
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);
}
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"));
}
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));
}
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;
}
Aggregations