Search in sources :

Example 1 with AssetDataFile

use of org.terasology.gestalt.assets.format.AssetDataFile 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 2 with AssetDataFile

use of org.terasology.gestalt.assets.format.AssetDataFile 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 3 with AssetDataFile

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

the class TranslationFormatTests method mockAssetDataFile.

// TODO: consider making this available to other test classes
private static AssetDataFile mockAssetDataFile(String fname, byte[] resource) throws IOException {
    AssetDataFile assetDataFile = mock(AssetDataFile.class);
    when(assetDataFile.openStream()).thenReturn(new BufferedInputStream(new ByteArrayInputStream(resource)));
    when(assetDataFile.getFilename()).thenReturn(fname);
    return assetDataFile;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile)

Example 4 with AssetDataFile

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

the class GLSLShaderFormat method load.

@Override
public ShaderData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    String vertProgram = null;
    String fragProgram = null;
    String geomProgram = null;
    ShaderMetadata metadata = new ShaderMetadata();
    for (AssetDataFile input : inputs) {
        String fileName = input.getFilename();
        if (fileName.endsWith(VERTEX_SUFFIX)) {
            vertProgram = readInput(input);
        } else if (fileName.endsWith(FRAGMENT_SUFFIX)) {
            fragProgram = readInput(input);
        } else if (fileName.endsWith(GEOMETRY_SUFFIX)) {
            geomProgram = readInput(input);
        } else {
            metadata = readMetadata(input);
        }
    }
    if (vertProgram != null && fragProgram != null) {
        return new ShaderData(vertProgram, fragProgram, geomProgram, metadata.getParameters());
    }
    throw new IOException("Failed to load shader '" + urn + "' - missing vertex or fragment program");
}
Also used : AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) IOException(java.io.IOException)

Example 5 with AssetDataFile

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

the class NUISkinEditorScreen method selectAsset.

/**
 * {@inheritDoc}
 */
@Override
public void selectAsset(ResourceUrn urn) {
    boolean isLoaded = assetManager.isLoaded(urn, UISkinAsset.class);
    Optional<UISkinAsset> asset = assetManager.getAsset(urn, UISkinAsset.class);
    if (asset.isPresent()) {
        UISkinAsset skin = asset.get();
        if (!isLoaded) {
            asset.get().dispose();
        }
        AssetDataFile source = skin.getSource();
        String content = null;
        try (JsonReader reader = new JsonReader(new InputStreamReader(source.openStream(), Charsets.UTF_8))) {
            reader.setLenient(true);
            content = new JsonParser().parse(reader).toString();
        } catch (IOException e) {
            logger.error(String.format("Could not load asset source file for %s", urn.toString()), e);
        }
        if (content != null) {
            JsonTree node = JsonTreeConverter.serialize(new JsonParser().parse(content));
            selectedAssetPending = urn.toString();
            resetState(node);
        }
    }
}
Also used : UISkinAsset(org.terasology.nui.skin.UISkinAsset) InputStreamReader(java.io.InputStreamReader) JsonTree(org.terasology.nui.widgets.treeView.JsonTree) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) JsonReader(com.google.gson.stream.JsonReader) IOException(java.io.IOException) JsonParser(com.google.gson.JsonParser)

Aggregations

AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)12 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 Test (org.junit.jupiter.api.Test)4 TranslationData (org.terasology.engine.i18n.assets.TranslationData)4 JsonParser (com.google.gson.JsonParser)3 JsonReader (com.google.gson.stream.JsonReader)3 UIElement (org.terasology.nui.asset.UIElement)3 JsonTree (org.terasology.nui.widgets.treeView.JsonTree)3 UISkinAsset (org.terasology.nui.skin.UISkinAsset)2 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Locale (java.util.Locale)1 UIFormat (org.terasology.engine.rendering.nui.asset.UIFormat)1 UISkinFormat (org.terasology.engine.rendering.nui.skin.UISkinFormat)1 Name (org.terasology.gestalt.naming.Name)1