Example usage for com.badlogic.gdx.utils ArrayMap get

List of usage examples for com.badlogic.gdx.utils ArrayMap get

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ArrayMap get.

Prototype

public V get(K key) 

Source Link

Document

Returns the value for the specified key.

Usage

From source file:com.algodal.gdxscreen.GdxGame.java

License:Apache License

private void attachAssetToScreen(ArrayMap<String, GdxScreen> map, String name, String screenRef,
        String assetRef) {/*from w w  w.  java 2 s.c  om*/
    debug.assertEqual("method is called in initialize", currentState, State.Initializing);
    debug.assertNotNull(name + " ref is not null", screenRef);
    debug.assertNotNull("asset ref is not null", assetRef);
    debug.assertStringNotEmpty(name + "ref is not empty", (screenRef = screenRef.trim()));
    debug.assertStringNotEmpty("asset ref is not empty", (assetRef = assetRef.trim()));
    debug.assertTrue(name + " ref exists", map.containsKey(screenRef));
    debug.assertTrue("asset ref exists", assetMap.containsKey(assetRef));

    //get objects
    GdxScreen screen = map.get(screenRef);

    debug.assertFalse(name + " ref gets new asset ref", screen.assetRefs.contains(assetRef, false));

    //attachment
    screen.assetRefs.add(assetRef);
}

From source file:com.mygdx.game.objects.Ragdoll.java

License:Apache License

/**
 * @param empties    Blender empties containing rigid body dimension data
 * @param armatureNodeId The name of the root skeleton/armature node
 *//*ww  w .j  av a2  s .co  m*/
private void createRagdoll(Array<BlenderEmpty> empties, String armatureNodeId) {
    Node armature = modelInstance.getNode(armatureNodeId, true, true);

    // Load mass and shape half extent data from Blender json
    ArrayMap<String, Vector3> halfExtMap = new ArrayMap<String, Vector3>();
    ArrayMap<String, Float> massMap = new ArrayMap<String, Float>();

    for (BlenderEmpty empty : empties) {
        Vector3 halfExtents = new Vector3(empty.scale);
        halfExtents.x = Math.abs(halfExtents.x);
        halfExtents.y = Math.abs(halfExtents.y);
        halfExtents.z = Math.abs(halfExtents.z);
        halfExtMap.put(empty.name, halfExtents);

        float partMass = Float.parseFloat(empty.custom_properties.get("mass"));
        massMap.put(empty.name, super.mass * partMass);
    }

    ArrayMap<String, btCollisionShape> shapeMap = new ArrayMap<String, btCollisionShape>();
    ArrayMap<String, btRigidBody> bodyMap = new ArrayMap<String, btRigidBody>();

    // Create rigid bodies using the previously loaded mass and half extents.
    // Put them along with the shapes into maps.
    for (Iterator<ObjectMap.Entry<String, Vector3>> iterator = halfExtMap.iterator(); iterator.hasNext();) {
        ObjectMap.Entry<String, Vector3> entry = iterator.next();
        String partName = entry.key;
        Vector3 partHalfExt = entry.value;
        float partMass = massMap.get(partName);

        btCollisionShape partShape = new btBoxShape(partHalfExt);
        shapeMap.put(partName, partShape);

        InvisibleBody phyCmp = new InvisibleBody(partName, partShape, partMass, new Matrix4(),
                this.belongsToFlag, this.collidesWithFlag, false, true);
        phyCmp.constructionInfo.dispose();

        bodyMap.put(partName, phyCmp.body);
        this.addPart(phyCmp.body, armature.getChild(partName, true, true));
    }
    // Abdomen is the at the top of the armature hierarchy
    this.addPart(bodyMap.get("abdomen"), armature, new Vector3(0, halfExtMap.get("abdomen").y * 1.6f, 0));

    final Matrix4 localA = new Matrix4();
    final Matrix4 localB = new Matrix4();
    btHingeConstraint hingeC;
    btConeTwistConstraint coneC;
    btFixedConstraint fixedC;
    String a, b;

    // TODO: This part could probably be automated somehow...

    // Set the ragdollConstraints
    a = "abdomen";
    b = "chest";
    localA.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(-PI0_25, PI0_5);

    a = "chest";
    b = "neck";
    localA.setFromEulerAnglesRad(0, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(fixedC = new btFixedConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));

    a = "neck";
    b = "head";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);

    a = "abdomen";
    b = "left_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).scl(-1, 1, 1).trn(halfExtMap.get(a).x * 0.5f,
            -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).scl(-1, 1, 1).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "abdomen";
    b = "right_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x * 0.5f, -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "left_thigh";
    b = "left_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    a = "right_thigh";
    b = "right_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    // TODO: causes shoulder rotation
    a = "chest";
    b = "left_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(halfExtMap.get(a).x + halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(PI0_25, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    // TODO: as above
    a = "chest";
    b = "right_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x - halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(-PI0_25, 0, 0).trn(0, -halfExtMap.get("right_upper_arm").y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    a = "left_upper_arm";
    b = "left_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

    a = "right_upper_arm";
    b = "right_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

}

From source file:com.mygdx.game.pathfinding.NavMeshGraph.java

License:Apache License

/**
 * Creates a map over each triangle and its Edge connections to other triangles. Each edge must follow the
 * vertex winding order of the triangle associated with it. Since all triangles are assumed to have the same
 * winding order, this means if two triangles connect, each must have its own edge connection data, where the
 * edge follows the same winding order as the triangle which owns the edge data.
 *
 * @param indexConnections/*  w w w . jav a  2  s.c o  m*/
 * @param triangles
 * @param vertexVectors
 * @return
 */
private static ArrayMap<Triangle, Array<Edge>> createSharedEdgesMap(Array<IndexConnection> indexConnections,
        Array<Triangle> triangles, Vector3[] vertexVectors) {

    ArrayMap<Triangle, Array<Edge>> connectionMap = new ArrayMap<Triangle, Array<Edge>>();
    connectionMap.ordered = true;

    for (Triangle tri : triangles) {
        connectionMap.put(tri, new Array<Edge>());
    }

    for (IndexConnection i : indexConnections) {
        Triangle fromNode = triangles.get(i.fromTriIndex);
        Triangle toNode = triangles.get(i.toTriIndex);
        Vector3 edgeVertexA = vertexVectors[i.edgeVertexIndex1];
        Vector3 edgeVertexB = vertexVectors[i.edgeVertexIndex2];

        Edge edge = new Edge(fromNode, toNode, edgeVertexA, edgeVertexB);
        connectionMap.get(fromNode).add(edge);
        fromNode.connections.add(edge);
    }
    return connectionMap;
}

From source file:com.vlaaad.dice.game.world.controllers.ViewController.java

License:Open Source License

public static WorldObjectView createView(Player viewer, PlayerColors colors, WorldObject object) {
    WorldObjectView view = new WorldObjectView();
    ArrayMap<Object, SubView> subViewArrayMap = object.createSubViews(viewer, colors);
    for (Object key : subViewArrayMap.keys()) {
        view.addSubView(key, subViewArrayMap.get(key));
    }//from   w w  w.  jav  a  2s . c  om
    object.initView(view);
    return view;
}

From source file:com.vlaaad.dice.game.world.controllers.ViewController.java

License:Open Source License

public static void updateView(Player viewer, PlayerColors colors, WorldObject object, WorldObjectView view) {
    view.clearChildren();/*from w ww  .  j a v  a  2s  .c  om*/
    ArrayMap<Object, SubView> subViewArrayMap = object.createSubViews(viewer, colors);
    for (Object key : subViewArrayMap.keys()) {
        view.addSubView(key, subViewArrayMap.get(key));
    }
}

From source file:de.tomgrill.gdxfacebook.desktop.DesktopGDXFacebook.java

License:Apache License

private void handleSuccessSignIn(String url) {
    try {/*  w  w  w . ja v  a 2  s .  c om*/
        URL urlObj = new URL(url);
        ArrayMap<String, String> params = Utils.parseQuery(urlObj.getRef());

        /** declare a 60 days expiration as default */
        long expiresInSecondsFromNow = 60 * 60 * 24;

        try {
            expiresInSecondsFromNow = Long.parseLong(params.get("expires_in"));
        } catch (NumberFormatException nfe) {
            Gdx.app.debug(GDXFacebookVars.LOG_TAG,
                    "Given expires_in value is not a valid Long. 60 days expiration assumed and used.");
        }

        long expiresInMillisFromNow = expiresInSecondsFromNow * 1000L;
        long expiresInMillisTimestamp = expiresInMillisFromNow + TimeUtils.millis();

        accessToken = new GDXFacebookAccessToken(params.get("access_token"), expiresInMillisTimestamp);
        storeNewToken(accessToken);

        Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Sign successful. User token: " + accessToken.getToken());

        callback.onSuccess(new SignInResult(accessToken, "Sign in successful."));

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:mobi.shad.s3lib.gfx.effect.BobsMulti.java

License:Apache License

/**
 * Update effect value, calling on GUI value are changing
 * @param changeKey//from  w ww .j  a va2s  . co m
 * @param values
 */
@Override
public void setValues(String changeKey, ArrayMap<String, String> values) {

    textureFileName = values.get("texture");

    count = Integer.parseInt(values.get("count"));

    if (count > 50000) {
        count = 50000;
    }
    if (count < 1) {
        count = 1;
    }

    countSteps = Integer.parseInt(values.get("countSteps"));
    if (countSteps > 30) {
        countSteps = 30;
    }
    if (countSteps < 1) {
        countSteps = 1;
    }

    size = Float.parseFloat(values.get("size"));

    amplitudeAdd = Float.parseFloat(values.get("amplitudeAdd"));
    amplitudeAdd2 = Float.parseFloat(values.get("amplitudeAdd2"));
    multiplerAdd = Float.parseFloat(values.get("multiplerAdd"));
    stepAdd = Float.parseFloat(values.get("stepAdd"));
    speedAdd = Float.parseFloat(values.get("speedAdd"));

    speed = Float.parseFloat(values.get("speed1"));
    step = Float.parseFloat(values.get("step1"));
    amplitudeX = Float.parseFloat(values.get("amplitudeX1"));
    amplitudeY = Float.parseFloat(values.get("amplitudeY1"));
    multiplierX = Float.parseFloat(values.get("multiplierX1"));
    multiplierY = Float.parseFloat(values.get("multiplierY1"));

    speed2 = Float.parseFloat(values.get("speed2"));
    step2 = Float.parseFloat(values.get("step2"));
    amplitudeX2 = Float.parseFloat(values.get("amplitudeX2"));
    amplitudeY2 = Float.parseFloat(values.get("amplitudeY2"));
    multiplierX2 = Float.parseFloat(values.get("multiplierX2"));
    multiplierY2 = Float.parseFloat(values.get("multiplierY2"));

    speed3 = Float.parseFloat(values.get("speed3"));
    step3 = Float.parseFloat(values.get("step3"));
    amplitudeX3 = Float.parseFloat(values.get("amplitudeX3"));
    amplitudeY3 = Float.parseFloat(values.get("amplitudeY3"));
    multiplierX3 = Float.parseFloat(values.get("multiplierX3"));
    multiplierY3 = Float.parseFloat(values.get("multiplierY3"));

    if (changeKey.equals("count") || changeKey.equals("countSteps") || changeKey.equals("texture")) {
        init();
    }
}

From source file:mobi.shad.s3lib.gfx.effect.Copper.java

License:Apache License

/**
 * Update effect value, calling on GUI value are changing
 * @param changeKey/*from www . ja va  2 s .c om*/
 * @param values
 */
@Override
public void setValues(String changeKey, ArrayMap<String, String> values) {

    count = Integer.parseInt(values.get("count"));
    if (count > 100) {
        count = 100;
    }
    if (count < 1) {
        count = 1;
    }

    copperSize = Float.parseFloat(values.get("size"));
    if (copperSize > 10) {
        copperSize = 10f;
    }
    if (copperSize < 0.1) {
        copperSize = 0.1f;
    }

    positionY = Float.parseFloat(values.get("positionY"));

    copperSpeed = Float.parseFloat(values.get("speed1"));
    copperStep = Float.parseFloat(values.get("step1"));
    copperAmplitude = Float.parseFloat(values.get("amplitude1"));
    copperMultipler = Float.parseFloat(values.get("multiplier1"));

    copperSpeed2 = Float.parseFloat(values.get("speed2"));
    copperStep2 = Float.parseFloat(values.get("step2"));
    copperAmplitude2 = Float.parseFloat(values.get("amplitude2"));
    copperMultipler2 = Float.parseFloat(values.get("multiplier2"));

    if (values.get("colorMode").equals(S3Lang.get("gradient_2a"))) {
        mode = 0;
    } else if (values.get("colorMode").equals(S3Lang.get("gradient_2b"))) {
        mode = 1;
    } else if (values.get("colorMode").equals(S3Lang.get("gradient_3"))) {
        mode = 2;
    } else if (values.get("colorMode").equals(S3Lang.get("gradient_4"))) {
        mode = 3;
    } else if (values.get("colorMode").equals(S3Lang.get("4_Black_Color"))) {
        mode = 4;
    } else if (values.get("colorMode").equals(S3Lang.get("Alpha_Palette"))) {
        mode = 5;
    } else if (values.get("colorMode").equals(S3Lang.get("Alpha_Palette_2"))) {
        mode = 6;
    } else if (values.get("colorMode").equals(S3Lang.get("Alpha_Palette_3"))) {
        mode = 7;
    } else if (values.get("colorMode").equals(S3Lang.get("Alpha_Palette_4"))) {
        mode = 8;
    }

    colorOutSide = Color.valueOf(values.get("outSideColor"));
    colorInSide = Color.valueOf(values.get("inSideColor"));
    colorInSide2 = Color.valueOf(values.get("inSide2Color"));
    colorOutSide2 = Color.valueOf(values.get("outSide2Color"));
    if (changeKey.equalsIgnoreCase("colorMode") || changeKey.equalsIgnoreCase("outSideColor")
            || changeKey.equalsIgnoreCase("inSideColor") || changeKey.equalsIgnoreCase("inSide2Color")
            || changeKey.equalsIgnoreCase("outSide2Color")) {
        init();
    }
}

From source file:mobi.shad.s3lib.gfx.effect.Grid.java

License:Apache License

/**
 *
 * @param changeKey//from  w ww.j  a  va 2  s. c om
 * @param values
 */
@Override
public void setValues(String changeKey, ArrayMap<String, String> values) {
    textureFileNameEffect = values.get("texture");

    mode = Integer.parseInt(values.get("gridMode"));

    if (mode > 5) {
        mode = 5;
    }
    if (mode < 0) {
        mode = 0;
    }

    gridSize = Integer.parseInt(values.get("gridSize"));
    if (gridSize > 9) {
        gridSize = 9;
    }
    if (gridSize < 0) {
        gridSize = 0;
    }

    flagSpeed = Float.parseFloat(values.get("speed"));
    amplitudeX = Float.parseFloat(values.get("amplitudeX"));
    amplitudeY = Float.parseFloat(values.get("amplitudeY"));
    multiplierX = Float.parseFloat(values.get("multiplierX"));
    multiplierY = Float.parseFloat(values.get("multiplierY"));

    if (changeKey.equals("gridMode") || changeKey.equals("gridSize") || changeKey.equals("texture")) {
        init();
    }
}

From source file:mobi.shad.s3lib.gfx.effect.Plasma.java

License:Apache License

/**
 * Update effect value, calling on GUI value are changing
 *
 * @param changeKey//from  w  ww  . j  ava  2 s  . co  m
 * @param values
 */
@Override
public void setValues(String changeKey, ArrayMap<String, String> values) {

    colorMode = Integer.parseInt(values.get("colorMode"));
    if (colorMode > 49) {
        colorMode = 49;
    }
    if (colorMode < 0) {
        colorMode = 0;
    }

    layer1 = Boolean.parseBoolean(values.get("layer1"));
    speedX1 = Float.parseFloat(values.get("speedX1"));
    speedY1 = Float.parseFloat(values.get("speedY1"));
    divX1 = Float.parseFloat(values.get("divX1"));
    divY1 = Float.parseFloat(values.get("divY1"));

    layer2 = Boolean.parseBoolean(values.get("layer2"));
    speedX2 = Float.parseFloat(values.get("speedX2"));
    speedY2 = Float.parseFloat(values.get("speedY2"));
    divX2 = Float.parseFloat(values.get("divX2"));
    divY2 = Float.parseFloat(values.get("divY2"));

    layer3 = Boolean.parseBoolean(values.get("layer3"));
    speedX3 = Float.parseFloat(values.get("speedX3"));
    speedY3 = Float.parseFloat(values.get("speedY3"));
    divX3 = Float.parseFloat(values.get("divX3"));
    divY3 = Float.parseFloat(values.get("divY3"));

    layer4 = Boolean.parseBoolean(values.get("layer4"));
    speedX4 = Float.parseFloat(values.get("speedX4"));
    speedY4 = Float.parseFloat(values.get("speedY4"));
    divX4 = Float.parseFloat(values.get("divX4"));
    divY4 = Float.parseFloat(values.get("divY4"));

    init();
}