Search in sources :

Example 1 with Name

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));
}
Also used : GsonPersistedDataSerializer(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataSerializer) GsonPersistedDataWriter(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataWriter) GsonPersistedDataReader(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataReader) Gson(com.google.gson.Gson) SerializedName(org.terasology.persistence.typeHandling.annotations.SerializedName) Name(org.terasology.gestalt.naming.Name)

Example 2 with Name

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);
}
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 Name

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);
// }
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Name(org.terasology.gestalt.naming.Name)

Example 4 with Name

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;
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Block(org.terasology.engine.world.block.Block) Rotation(org.terasology.engine.math.Rotation) Name(org.terasology.gestalt.naming.Name)

Example 5 with Name

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"));
}
Also used : Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Aggregations

Name (org.terasology.gestalt.naming.Name)58 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)15 Module (org.terasology.gestalt.module.Module)14 SimpleUri (org.terasology.engine.core.SimpleUri)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)10 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)7 IOException (java.io.IOException)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 List (java.util.List)5 GameEngine (org.terasology.engine.core.GameEngine)5 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)5 BlockUri (org.terasology.engine.world.block.BlockUri)5 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)5 UIText (org.terasology.nui.widgets.UIText)5 Map (java.util.Map)4 Set (java.util.Set)4 Config (org.terasology.engine.config.Config)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3