Search in sources :

Example 1 with ProbabilityWeightsAcoustic

use of org.blockartistry.DynSurround.client.footsteps.implem.ProbabilityWeightsAcoustic in project DynamicSurroundings by OreCruncher.

the class AcousticsJsonReader method solveAcousticsCompound.

private IAcoustic solveAcousticsCompound(final JsonObject unsolved) throws JsonParseException {
    IAcoustic ret = null;
    if (!unsolved.has("type") || unsolved.get("type").getAsString().equals("basic")) {
        final BasicAcoustic a = new BasicAcoustic();
        prepareDefaults(a);
        setupClassics(a, unsolved);
        ret = a;
    } else {
        final String type = unsolved.get("type").getAsString();
        if (type.equals("simultaneous")) {
            final List<IAcoustic> acoustics = new ArrayList<>();
            final JsonArray sim = unsolved.getAsJsonArray("array");
            final Iterator<JsonElement> iter = sim.iterator();
            while (iter.hasNext()) {
                final JsonElement subElement = iter.next();
                acoustics.add(solveAcoustic(subElement));
            }
            final SimultaneousAcoustic a = new SimultaneousAcoustic(acoustics);
            ret = a;
        } else if (type.equals("delayed")) {
            final DelayedAcoustic a = new DelayedAcoustic();
            prepareDefaults(a);
            setupClassics(a, unsolved);
            if (unsolved.has("delay")) {
                a.setDelayMin(unsolved.get("delay").getAsInt());
                a.setDelayMax(unsolved.get("delay").getAsInt());
            } else {
                a.setDelayMin(unsolved.get("delay_min").getAsInt());
                a.setDelayMax(unsolved.get("delay_max").getAsInt());
            }
            ret = a;
        } else if (type.equals("probability")) {
            final List<Integer> weights = new ArrayList<>();
            final List<IAcoustic> acoustics = new ArrayList<>();
            final JsonArray sim = unsolved.getAsJsonArray("array");
            final Iterator<JsonElement> iter = sim.iterator();
            while (iter.hasNext()) {
                JsonElement subElement = iter.next();
                weights.add(subElement.getAsInt());
                if (!iter.hasNext())
                    throw new JsonParseException("Probability has odd number of children!");
                subElement = iter.next();
                acoustics.add(solveAcoustic(subElement));
            }
            final ProbabilityWeightsAcoustic a = new ProbabilityWeightsAcoustic(acoustics, weights);
            ret = a;
        }
    }
    return ret;
}
Also used : SimultaneousAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.SimultaneousAcoustic) IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) ProbabilityWeightsAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.ProbabilityWeightsAcoustic) ArrayList(java.util.ArrayList) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) DelayedAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.DelayedAcoustic) BasicAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.BasicAcoustic)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 BasicAcoustic (org.blockartistry.DynSurround.client.footsteps.implem.BasicAcoustic)1 DelayedAcoustic (org.blockartistry.DynSurround.client.footsteps.implem.DelayedAcoustic)1 ProbabilityWeightsAcoustic (org.blockartistry.DynSurround.client.footsteps.implem.ProbabilityWeightsAcoustic)1 SimultaneousAcoustic (org.blockartistry.DynSurround.client.footsteps.implem.SimultaneousAcoustic)1 IAcoustic (org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic)1