Example usage for com.badlogic.gdx.utils OrderedMap entries

List of usage examples for com.badlogic.gdx.utils OrderedMap entries

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils OrderedMap entries.

Prototype

public Entries<K, V> entries() 

Source Link

Document

Returns an iterator for the entries in the map.

Usage

From source file:com.lyeeedar.Graphics.ParticleEffects.ParticleEmitter.java

License:Open Source License

/**
 * Get a json instance set up for reading and writing a particle emitter
 * @return/*from  w  w  w.  j  a  va 2s  .com*/
 */
public static Json getJson(Json json) {
    json.setSerializer(ParticleEmitter.class, new Json.Serializer<ParticleEmitter>() {
        @SuppressWarnings("rawtypes")
        public void write(Json json, ParticleEmitter emitter, Class knownType) {
            emitter.write(json);
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        public ParticleEmitter read(Json json, Object jsonData, Class type) {

            // ----- Particle Parameters ----- //
            TimelineValue[] sprite = null;
            TimelineValue[] size = null;
            TimelineValue[] colour = null;
            TimelineValue[] velocity = null;
            // ----- End Particle Parameters ----- //

            // ----- Emitter parameters ----- //
            String name = null;
            int maxParticles = 0;
            float particleLifetime = 0;
            float particleLifetimeVar = 0;
            float emissionTime = 0;
            float ex = 0, ey = 0, ez = 0;
            int emissionType = 0;
            int blendFuncSRC = 0;
            int blendFuncDST = 0;
            String atlasName = null;
            // ----- End Emitter parameters ----- //

            // ----- Light ----- //
            float lightAttenuation = 0;
            float lightPower = 0;
            boolean isLightStatic = false;
            Color lightColour = null;
            boolean lightFlicker = false;
            float lightx = 0, lighty = 0, lightz = 0;
            // ----- End Light ----- //

            OrderedMap<String, Object> jsonMap = (OrderedMap<String, Object>) jsonData;
            Iterator<Entry<String, Object>> itr = jsonMap.entries();

            while (itr.hasNext()) {
                Entry<String, Object> entry = itr.next();

                if (entry.key.equals("sprite")) {
                    sprite = json.readValue(TimelineValue[].class, entry.value);
                } else if (entry.key.equals("size")) {
                    size = json.readValue(TimelineValue[].class, entry.value);
                } else if (entry.key.equals("colour")) {
                    colour = json.readValue(TimelineValue[].class, entry.value);
                } else if (entry.key.equals("velocity")) {
                    velocity = json.readValue(TimelineValue[].class, entry.value);
                }

                else if (entry.key.equals("name")) {
                    name = (String) entry.value;
                } else if (entry.key.equals("max particles")) {
                    maxParticles = ((Float) entry.value).intValue();
                } else if (entry.key.equals("particle lifetime")) {
                    particleLifetime = (Float) entry.value;
                } else if (entry.key.equals("particle lifetime variance")) {
                    particleLifetimeVar = (Float) entry.value;
                } else if (entry.key.equals("emission time")) {
                    emissionTime = (Float) entry.value;
                } else if (entry.key.equals("emission x")) {
                    ex = (Float) entry.value;
                } else if (entry.key.equals("emission y")) {
                    ey = (Float) entry.value;
                } else if (entry.key.equals("emission z")) {
                    ez = (Float) entry.value;
                } else if (entry.key.equals("emission type")) {
                    emissionType = ((Float) entry.value).intValue();
                } else if (entry.key.equals("blend func SRC")) {
                    blendFuncSRC = ((Float) entry.value).intValue();
                } else if (entry.key.equals("blend func DST")) {
                    blendFuncDST = ((Float) entry.value).intValue();
                } else if (entry.key.equals("atlas name")) {
                    atlasName = (String) entry.value;
                }

                else if (entry.key.equals("light attenuation")) {
                    lightAttenuation = (Float) entry.value;
                } else if (entry.key.equals("light power")) {
                    lightPower = (Float) entry.value;
                } else if (entry.key.equals("light static")) {
                    isLightStatic = (Boolean) entry.value;
                } else if (entry.key.equals("light flicker")) {
                    lightFlicker = (Boolean) entry.value;
                } else if (entry.key.equals("light colour")) {
                    lightColour = json.readValue(Color.class, entry.value);
                } else if (entry.key.equals("light offset x")) {
                    lightx = (Float) entry.value;
                } else if (entry.key.equals("light offset y")) {
                    lighty = (Float) entry.value;
                } else if (entry.key.equals("light offset z")) {
                    lightz = (Float) entry.value;
                }
            }

            ParticleEmitter emitter = new ParticleEmitter(particleLifetime, particleLifetimeVar, emissionTime,
                    ex, ey, ez, emissionType, blendFuncSRC, blendFuncDST, atlasName, name);
            emitter.maxParticles = maxParticles;

            emitter.setTimeline(sprite, size, colour, velocity);

            if (lightColour != null)
                emitter.addLight(isLightStatic, lightAttenuation, lightPower, lightColour, lightFlicker, lightx,
                        lighty, lightz);

            return emitter;
        }
    });

    return json;
}

From source file:org.matheusdev.util.JsonDOM.java

License:Open Source License

@SuppressWarnings("unchecked")
public void readJsonObject(JsonObject element, OrderedMap<String, Object> jsonData) {
    Entries<String, Object> entries = jsonData.entries();
    for (Entry<String, Object> entry : entries) {
        if (entry.value instanceof OrderedMap) {
            JsonObject obj = new JsonObject();
            element.elements.put(entry.key, obj);

            // unchecked, but safe:
            readJsonObject(obj, (OrderedMap<String, Object>) entry.value);
        } else if (entry.value instanceof Array) {
            JsonArray arr = new JsonArray();
            element.elements.put(entry.key, arr);

            // unchecked, but safe:
            readJsonArray(arr, (Array<OrderedMap<String, Object>>) entry.value);
        } else {/*from   w  w w . ja  v a  2 s.c  o m*/
            element.values.put(entry.key, entry.value.toString());
        }
    }
}