Search in sources :

Example 16 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
    CoreRegistry.put(BlockManager.class, blockManager);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    extraDataManager = new ExtraBlockDataManager();
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
    fullLightData.getBaseSection().setDisplayName("Torch");
    fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    fullLightData.getBaseSection().setLuminance(Chunks.MAX_LIGHT);
    fullLightData.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);
    fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) AssetManager(org.terasology.gestalt.assets.management.AssetManager) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TranslationFormatTests method testEmptyDataGenGermany.

@Test
public void testEmptyDataGenGermany() throws IOException, InvalidAssetFilenameException {
    AssetDataFile assetDataFile = mockAssetDataFile("menu_de-DE.lang", "{}".getBytes(StandardCharsets.UTF_8));
    ResourceUrn urn = createUrnFromFile(format, assetDataFile);
    TranslationData data = format.load(urn, Collections.singletonList(assetDataFile));
    assertEquals(Locale.GERMANY, data.getLocale());
    assertTrue(data.getTranslations().isEmpty());
}
Also used : AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) TranslationData(org.terasology.engine.i18n.assets.TranslationData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 18 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TranslationFormatTests method testMultiLine.

@Test
public void testMultiLine() throws IOException, InvalidAssetFilenameException {
    byte[] resource = createSimpleMultiLineTranslationFile().getBytes(StandardCharsets.UTF_8);
    AssetDataFile assetDataFile = mockAssetDataFile("game.lang", resource);
    ResourceUrn urn = createUrnFromFile(format, assetDataFile);
    TranslationData data = format.load(urn, Collections.singletonList(assetDataFile));
    assertEquals("line 1 \n line 2 \n line 3", data.getTranslations().get("multi-line"));
    assertEquals("line 1 \n line 2 \n line 3", data.getTranslations().get("single-line"));
}
Also used : AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) TranslationData(org.terasology.engine.i18n.assets.TranslationData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 19 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TranslationSystemImpl method translate.

@Override
public String translate(String text, Locale otherLocale) {
    TemplateEngine templateEngine = new TemplateEngineImpl(id -> {
        ResourceUrn uri = new ResourceUrn(id);
        ResourceUrn projectUri = new ResourceUrn(uri.getModuleName(), uri.getResourceName());
        TranslationProject project = getProject(projectUri);
        if (project != null) {
            Optional<String> opt = project.translate(uri.getFragmentName(), otherLocale);
            if (opt.isPresent()) {
                return opt.get();
            } else {
                logger.warn("No translation for '{}'", id);
                return "?" + uri.getFragmentName() + "?";
            }
        } else {
            logger.warn("Invalid project id '{}'", id);
            return "?" + uri.getFragmentName() + "?";
        }
    });
    return templateEngine.transform(text);
}
Also used : TemplateEngine(org.terasology.engine.persistence.TemplateEngine) TemplateEngineImpl(org.terasology.engine.persistence.TemplateEngineImpl) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 20 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class FontFormat method parsePage.

private void parsePage(FontDataBuilder builder, Name moduleName, String pageInfo) throws IOException {
    Matcher pageMatcher = pagePattern.matcher(pageInfo);
    if (pageMatcher.matches()) {
        int pageId = Integer.parseInt(pageMatcher.group(1));
        Name textureName = new Name(pageMatcher.group(2).substring(0, pageMatcher.group(2).lastIndexOf('.')));
        Optional<Material> material = assetManager.getAsset(new ResourceUrn(moduleName, new Name("font"), textureName), Material.class);
        if (!material.isPresent()) {
            throw new IOException("Failed to load font - unable to resolve font page '" + textureName + "'");
        } else {
            builder.addPage(pageId, assetManager.getAsset(new ResourceUrn(moduleName, textureName), Texture.class).get(), material.get());
        }
    } else {
        throw new IOException("Failed to load font - invalid page line '" + pageInfo + "'");
    }
}
Also used : Matcher(java.util.regex.Matcher) Material(org.terasology.engine.rendering.assets.material.Material) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Aggregations

ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)90 Test (org.junit.jupiter.api.Test)19 Name (org.terasology.gestalt.naming.Name)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)10 IOException (java.io.IOException)9 AssetManager (org.terasology.gestalt.assets.management.AssetManager)9 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)8 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)7 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)7 BlockUri (org.terasology.engine.world.block.BlockUri)7 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)7 Texture (org.terasology.engine.rendering.assets.texture.Texture)5 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)5 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)5 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)5 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ByteBuffer (java.nio.ByteBuffer)4