Search in sources :

Example 1 with SimMultipleChildren

use of com.ray3k.stripe.scenecomposer.SimMultipleChildren in project skin-composer by raeleus.

the class DialogSceneComposerModel method primeStyles.

private void primeStyles(SimActor simActor) {
    for (var field : ClassReflection.getFields(simActor.getClass())) {
        if (field.getType() == StyleData.class) {
            try {
                var style = (StyleData) field.get(simActor);
                if (style != null) {
                    StyleData foundStyle = jsonData.findStyle(style.clazz, style.name);
                    if (foundStyle == null)
                        foundStyle = jsonData.findStyle(style.clazz, "default");
                    if (foundStyle == null)
                        foundStyle = jsonData.findStyle(style.clazz, "default-horizontal");
                    field.set(simActor, foundStyle);
                }
            } catch (ReflectionException e) {
                e.printStackTrace(System.out);
            }
        } else if (field.getType() == DrawableData.class) {
            try {
                var drawable = (DrawableData) field.get(simActor);
                if (drawable != null) {
                    var foundDrawable = atlasData.getDrawable(drawable.name);
                    field.set(simActor, foundDrawable);
                }
            } catch (ReflectionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    if (simActor instanceof SimMultipleChildren) {
        for (var child : ((SimMultipleChildren) simActor).getChildren()) {
            if (child != null)
                primeStyles(child);
        }
    }
    if (simActor instanceof SimSingleChild) {
        var child = ((SimSingleChild) simActor).getChild();
        if (child != null)
            primeStyles(child);
    }
}
Also used : ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) DrawableData(com.ray3k.skincomposer.data.DrawableData) SimSingleChild(com.ray3k.stripe.scenecomposer.SimSingleChild) StyleData(com.ray3k.skincomposer.data.StyleData) SimMultipleChildren(com.ray3k.stripe.scenecomposer.SimMultipleChildren)

Aggregations

ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)1 DrawableData (com.ray3k.skincomposer.data.DrawableData)1 StyleData (com.ray3k.skincomposer.data.StyleData)1 SimMultipleChildren (com.ray3k.stripe.scenecomposer.SimMultipleChildren)1 SimSingleChild (com.ray3k.stripe.scenecomposer.SimSingleChild)1