use of org.terasology.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, UISkin.class);
Optional<UISkin> asset = assetManager.getAsset(urn, UISkin.class);
if (asset.isPresent()) {
UISkin 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);
}
}
}
use of org.terasology.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class NUISkinEditorScreen method setSelectedAssetPath.
/**
* {@inheritDoc}
*/
@Override
protected void setSelectedAssetPath(ResourceUrn urn) {
boolean isLoaded = assetManager.isLoaded(urn, UISkin.class);
Optional<UISkin> asset = assetManager.getAsset(urn, UISkin.class);
if (asset.isPresent()) {
UISkin skin = asset.get();
if (!isLoaded) {
asset.get().dispose();
}
AssetDataFile source = skin.getSource();
selectedAssetPath = getPath(source);
}
}
use of org.terasology.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;
ShaderMetadata metadata = new ShaderMetadata();
for (AssetDataFile input : inputs) {
if (input.getFilename().endsWith(VERTEX_SUFFIX)) {
vertProgram = readInput(input);
} else if (input.getFilename().endsWith(FRAGMENT_SUFFIX)) {
fragProgram = readInput(input);
} else {
metadata = readMetadata(input);
}
}
if (vertProgram != null && fragProgram != null) {
return new ShaderData(vertProgram, fragProgram, metadata.getParameters());
}
throw new IOException("Failed to load shader '" + urn + "' - missing vertex or fragment program");
}
use of org.terasology.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class TranslationFormat method load.
@Override
public TranslationData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
if (inputs.size() != 1) {
throw new IOException("Failed to load translation data '" + urn + "': " + inputs);
}
AssetDataFile file = inputs.get(0);
Locale locale = localeFromFilename(file.getFilename());
Name projName = basenameFromFilename(file.getFilename());
SimpleUri projUri = new SimpleUri(urn.getModuleName(), projName);
TranslationData data = new TranslationData(projUri, locale);
try (InputStreamReader isr = new InputStreamReader(file.openStream(), Charsets.UTF_8)) {
Map<String, String> entry = gson.fromJson(isr, MAP_TOKEN.getType());
data.addAll(entry);
} catch (JsonParseException e) {
throw new IOException("Could not parse file '" + file + "'", e);
}
return data;
}
use of org.terasology.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class TranslationFormatTests method testEmptyDataGenRoot.
@Test
public void testEmptyDataGenRoot() throws IOException, InvalidAssetFilenameException {
AssetDataFile assetDataFile = mockAssetDataFile("menu.lang", "{}".getBytes(StandardCharsets.UTF_8));
ResourceUrn urn = createUrnFromFile(format, assetDataFile);
TranslationData data = format.load(urn, Collections.singletonList(assetDataFile));
Assert.assertEquals(new SimpleUri("engine:menu"), data.getProjectUri());
Assert.assertEquals(Locale.ROOT, data.getLocale());
}
Aggregations