Search in sources :

Example 1 with UIData

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);
}
Also used : TranslationSystem(org.terasology.engine.i18n.TranslationSystem) GsonTypeSerializationLibraryAdapterFactory(org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory) UISkinAsset(org.terasology.nui.skin.UISkinAsset) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) UISkinTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler) UIData(org.terasology.nui.asset.UIData) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) NUIManager(org.terasology.engine.rendering.nui.NUIManager)

Example 2 with UIData

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonReader(com.google.gson.stream.JsonReader) UIData(org.terasology.nui.asset.UIData) JsonParser(com.google.gson.JsonParser)

Aggregations

UIData (org.terasology.nui.asset.UIData)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 InputStreamReader (java.io.InputStreamReader)1 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)1 UISkinTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler)1 GsonTypeSerializationLibraryAdapterFactory (org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory)1 NUIManager (org.terasology.engine.rendering.nui.NUIManager)1 CaseInsensitiveEnumTypeAdapterFactory (org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory)1 UISkinAsset (org.terasology.nui.skin.UISkinAsset)1 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)1