use of org.terasology.nui.asset.UIData in project Terasology by MovingBlocks.
the class UIFormat method load.
public UIData load(JsonElement element, Locale otherLocale) throws IOException {
NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
TypeHandlerLibrary library = CoreRegistry.get(TypeHandlerLibrary.class).copy();
library.addTypeHandler(UISkinAsset.class, new AssetTypeHandler<>(UISkinAsset.class));
library.addTypeHandler(UISkin.class, new UISkinTypeHandler());
// TODO: Rewrite to use TypeHandlerLibrary
GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new GsonTypeSerializationLibraryAdapterFactory(library)).registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
// override the String TypeAdapter from the serialization library
gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
Gson gson = gsonBuilder.create();
return gson.fromJson(element, UIData.class);
}
use of org.terasology.nui.asset.UIData in project Terasology by MovingBlocks.
the class UIFormat method load.
@Override
public UIData load(ResourceUrn resourceUrn, List<AssetDataFile> inputs) throws IOException {
try (JsonReader reader = new JsonReader(new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8))) {
reader.setLenient(true);
UIData data = load(new JsonParser().parse(reader));
data.setSource(inputs.get(0));
return data;
}
}
Aggregations