Search in sources :

Example 1 with UISkin

use of org.terasology.nui.skin.UISkin in project Terasology by MovingBlocks.

the class UIDeltaFormat method apply.

@Override
public void apply(AssetDataFile input, UIData assetData) throws IOException {
    try (JsonReader reader = new JsonReader(new InputStreamReader(input.openStream(), Charsets.UTF_8))) {
        JsonElement jsonElement = new JsonParser().parse(reader);
        String skinUri = jsonElement.getAsJsonObject().get("skin").getAsString();
        String filePath = input.toString();
        String moduleName = filePath.substring(1, filePath.indexOf('/', 1));
        Optional<UISkin> skin = Assets.getSkin(moduleName + ":" + skinUri);
        if (skin.isPresent()) {
            assetData.getRootWidget().setSkin(skin.get());
        } else {
            logger.warn("Failed to load skin " + skinUri + " for the delta file " + input.getFilename());
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) UISkin(org.terasology.nui.skin.UISkin) JsonReader(com.google.gson.stream.JsonReader) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 InputStreamReader (java.io.InputStreamReader)1 UISkin (org.terasology.nui.skin.UISkin)1