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