use of org.terasology.gestalt.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class TranslationFormatTests method testDataGenGerman.
@Test
public void testDataGenGerman() throws IOException, InvalidAssetFilenameException {
byte[] resource = createSimpleTranslationFile().getBytes(StandardCharsets.UTF_8);
AssetDataFile assetDataFile = mockAssetDataFile("menu_de-DE.lang", resource);
ResourceUrn urn = createUrnFromFile(format, assetDataFile);
TranslationData data = format.load(urn, Collections.singletonList(assetDataFile));
assertEquals("Einzelspieler", data.getTranslations().get("engine:mainMenuScreen#singleplayer#text"));
}
use of org.terasology.gestalt.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));
assertEquals(new ResourceUrn("engine:menu"), data.getProjectUrn());
assertEquals(Locale.ROOT, data.getLocale());
}
use of org.terasology.gestalt.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());
ResourceUrn projUrn = new ResourceUrn(urn.getModuleName(), projName);
TranslationData data = new TranslationData(projUrn, 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.gestalt.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class NUIEditorScreen method selectAsset.
/**
* {@inheritDoc}
*/
@Override
public void selectAsset(ResourceUrn urn) {
boolean isLoaded = assetManager.isLoaded(urn, UIElement.class);
Optional<UIElement> asset = assetManager.getAsset(urn, UIElement.class);
if (asset.isPresent()) {
UIElement element = asset.get();
if (!isLoaded) {
asset.get().dispose();
}
AssetDataFile source = element.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.gestalt.assets.format.AssetDataFile in project Terasology by MovingBlocks.
the class NUIEditorScreen method setSelectedAssetPath.
/**
* {@inheritDoc}
*/
@Override
protected void setSelectedAssetPath(ResourceUrn urn) {
boolean isLoaded = assetManager.isLoaded(urn, UIElement.class);
Optional<UIElement> asset = assetManager.getAsset(urn, UIElement.class);
if (asset.isPresent()) {
UIElement element = asset.get();
if (!isLoaded) {
asset.get().dispose();
}
AssetDataFile source = element.getSource();
selectedAssetPath = getPath(source);
}
}
Aggregations