use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class TypeSerializerTest method setup.
@Override
public void setup() {
ModuleContext.setContext(moduleManager.getEnvironment().get(new Name("unittest")));
typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
Gson gson = new Gson();
gsonSerializer = new Serializer<>(typeHandlerLibrary, new GsonPersistedDataSerializer(), new GsonPersistedDataWriter(gson), new GsonPersistedDataReader(gson));
}
use of org.terasology.gestalt.naming.Name 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.gestalt.naming.Name in project Terasology by MovingBlocks.
the class RenderGraph method addNode.
public void addNode(Node node) {
Preconditions.checkNotNull(node, "node cannot be null!");
SimpleUri nodeUri = node.getUri();
Name nodeAka = node.getAka();
// TODO how bout aka
if (nodeMap.containsKey(nodeUri)) {
throw new RuntimeException("A node with Uri " + nodeUri + " already exists!");
}
if (akaNodeMap.containsKey(nodeAka)) {
Node aNode = akaNodeMap.get(nodeAka);
logger.info("Node " + nodeUri + " also known as" + nodeAka + " already matches existing node with uri " + aNode.getUri() + " - attempting replacing...");
replaceNode(aNode, node);
} else {
nodeMap.put(nodeUri, node);
akaNodeMap.put(nodeAka, node);
graph.addNode(node);
}
// TODO this must be moved to a later stage ideally with the improved connecting of nodes which would be based on
// TODO on dep connections. So far when creating dep. connections, connections are made and destroyed, which is wrong.
// if (node instanceof AbstractNode) {
// node.setDependencies(context);
// }
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class MultiConnectFamily method registerBlock.
/**
* @param root The root block URI of the family
* @param definition The definition of the block family as passed down from the engine
* @param blockBuilder The block builder to make the blocks in the family
* @param sides A byte representing the sides which should be connected for this block
* @param rotations All of the ways the block should be rotated
* @return All of the rotations possible for the block with the given sides
*/
public Set<Block> registerBlock(BlockUri root, BlockFamilyDefinition definition, final BlockBuilderHelper blockBuilder, byte sides, Iterable<Rotation> rotations) {
Set<Block> result = Sets.newLinkedHashSet();
for (Rotation rotation : rotations) {
byte sideBits = 0;
for (Side side : SideBitFlag.getSides(sides)) {
sideBits |= SideBitFlag.getSide(rotation.rotate(side));
}
BlockUri uri = new BlockUri(root, new Name(String.valueOf(sideBits)));
Block block = blockBuilder.constructTransformedBlock(definition, rotation, uri, this);
block.setUri(uri);
blocks.put(sideBits, block);
result.add(block);
}
return result;
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class TranslationFormatTests method testGetAssetName.
@Test
public void testGetAssetName() throws InvalidAssetFilenameException {
assertEquals(new Name("menu"), format.getAssetName("menu.lang"));
assertEquals(new Name("menu_pl"), format.getAssetName("menu_pl.lang"));
}
Aggregations