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

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

Introduction

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

Prototype

public ArrayMap(ArrayMap array) 

Source Link

Document

Creates a new map containing the elements in the specified map.

Usage

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca tekstur zaadowan z dysku/*ww w.j  av  a  2  s. co  m*/
 *
 * @param fileName
 * @return
 */
public static Texture getTexture(String fileName, int destAndroidResolution) {

    Texture texture;

    if (textureResuorce == null) {
        textureResuorce = new ArrayMap<String, TextureHandle>(20);
    }

    if (!textureResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load texture (def size: " + destAndroidResolution + ") from file: " + fileName,
                    3);
        }

        try {
            if (destAndroidResolution == 0) {
                FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
                texture = new Texture(fileHandle);
                texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            } else {
                Pixmap px = new Pixmap(S3File.getFileHandle(fileName, true, false));
                Pixmap px2 = new Pixmap(destAndroidResolution, destAndroidResolution, Pixmap.Format.RGBA8888);
                px2.drawPixmap(px, 0, 0, px.getWidth(), px.getHeight(), 0, 0, destAndroidResolution,
                        destAndroidResolution);
                texture = new Texture(px2);
                texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
                texture.draw(px2, 0, 0);
            }

            if (USE_CACHE_RESOURCE) {
                if (textureResuorce.containsKey(fileName)) {
                    textureResuorce.removeKey(fileName);
                }
                TextureHandle textureHeandle = new TextureHandle();
                textureHeandle.fileName = fileName;
                textureHeandle.texture = texture;
                textureHeandle.width = texture.getWidth();
                textureHeandle.height = texture.getHeight();
                textureHeandle.defResolution = destAndroidResolution;
                textureResuorce.put(fileName, textureHeandle);
            }

        } catch (Exception e) {
            S3Log.error("S3ResourceManager::getTexture", "Error create texture data ....", e);

            Pixmap pixmap = new Pixmap(S3Constans.proceduralTextureSizeLow, S3Constans.proceduralTextureSizeLow,
                    Pixmap.Format.RGBA4444);
            pixmap.setColor(Color.RED);
            pixmap.fill();
            texture = new Texture(pixmap);
            texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            texture.draw(pixmap, 0, 0);
        }
    } else {

        if (LOG) {
            S3Log.trace(TAG,
                    "Load texture from cache (def size: " + destAndroidResolution + ") from file: " + fileName,
                    2);
        }
        TextureHandle textureHandle = textureResuorce.get(fileName);
        texture = textureHandle.texture;
    }
    if (LOG) {
        S3Log.trace(TAG, "Texture size width: " + texture.getWidth() + "px height: " + texture.getHeight());
    }
    return texture;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca tekstur zaadowan z dysku//from  w  w  w.j av  a 2 s.  c  o m
 *
 * @param fileName
 * @return
 */
public static TextureRegion getTextureRegion(String fileName) {

    TextureRegion textureRegion;

    if (regionResuorce == null) {
        regionResuorce = new ArrayMap<String, TextureRegion>(20);
    }

    if (!regionResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load textureRegion region: " + fileName, 3);
        }

        try {
            FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
            textureRegion = new TextureRegion(assetManager.get(fileHandle.path(), Texture.class));
            textureRegion.getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

            if (USE_CACHE_RESOURCE) {
                if (regionResuorce.containsKey(fileName)) {
                    regionResuorce.removeKey(fileName);
                }
                regionResuorce.put(fileName, textureRegion);
            }

        } catch (Exception e) {
            S3Log.error("S3ResourceManager::getTexture", "Error create textureRegion data ....", e);

            try {
                Pixmap pixmap = new Pixmap(S3Constans.proceduralTextureSizeLow,
                        S3Constans.proceduralTextureSizeLow, Pixmap.Format.RGBA4444);
                pixmap.setColor(Color.RED);
                pixmap.fill();
                Texture text2 = new Texture(pixmap);
                text2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
                text2.draw(pixmap, 0, 0);
                textureRegion = new TextureRegion(text2);
            } catch (Exception ex) {
                textureRegion = regionResuorce.firstValue();
            }
        }
    } else {

        if (LOG) {
            S3Log.trace(TAG, "Load textureRegion region from cache: " + fileName, 2);
        }
        textureRegion = regionResuorce.get(fileName);
    }
    return textureRegion;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca tekstur zaadowan z dysku/*  www.  j av a 2s  .c om*/
 *
 * @param fileName
 * @return
 */
public static TextureRegion getTextureRegion(String fileName, int index) {

    TextureRegion texture = null;

    if (regionResuorce == null) {
        regionResuorce = new ArrayMap<String, TextureRegion>(20);
    }

    if (regionAnimResuorce == null) {
        regionAnimResuorce = new ArrayMap<String, TextureRegion>();
    }

    if (regionAnimResuorce.containsKey(fileName + index)) {
        if (LOG) {
            S3Log.trace(TAG, "Load texture region: " + fileName + " index: " + index, 2);
        }
        texture = regionAnimResuorce.get(fileName + index);
        if (LOG) {
            S3Log.trace(TAG, "Texture size width: " + texture.getTexture().getWidth() + "px height: "
                    + texture.getTexture().getHeight());
        }
    }
    return texture;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * @param fileName/*from  ww w .  j av a 2s.  com*/
 * @param destAndroidResolution
 * @return
 */
public static Pixmap getPixmap(String fileName, int destAndroidResolution) {

    Pixmap pixmap;

    if (pixmapResuorce == null) {
        pixmapResuorce = new ArrayMap<String, Pixmap>(20);
    }

    if (!pixmapResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load pixmap (def size: " + destAndroidResolution + ") from file: " + fileName, 3);
        }
        try {

            FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
            pixmap = assetManager.get(fileHandle.path(), Pixmap.class);
            if (USE_CACHE_RESOURCE) {
                pixmapResuorce.put(fileName, pixmap);
            }
        } catch (Exception e) {
            S3Log.error("S3ResourceManager::getPixmap", "Error create pixmap data ....", e);
            pixmap = new Pixmap(S3Constans.proceduralTextureSizeLow, S3Constans.proceduralTextureSizeLow,
                    Pixmap.Format.RGBA4444);
            pixmap.setColor(Color.RED);
            pixmap.fill();
        }
    } else {

        if (LOG) {
            S3Log.trace(TAG,
                    "Load pixmap from cache (def size: " + destAndroidResolution + ") from file: " + fileName,
                    1);
        }
        pixmap = pixmapResuorce.get(fileName);
    }

    if (LOG) {
        S3Log.trace(TAG, "Pixmap size width: " + pixmap.getWidth() + "px height: " + pixmap.getHeight() + "px ",
                0);
    }
    return pixmap;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca objekt skina zaadowany z dysku
 *
 * @param fileName/*w w w.j av a2 s  . com*/
 * @return
 */
public static Skin getSkin(String fileName) {

    if (skinResuorce == null) {
        skinResuorce = new ArrayMap<String, Skin>(10);
    }

    Skin skin;
    if (!skinResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load skin from file: " + fileName, 3);
        }
        FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
        skin = new Skin(fileHandle);
        if (USE_CACHE_RESOURCE) {
            skinResuorce.put(fileName, skin);
        }
    } else {
        if (LOG) {
            S3Log.trace(TAG, "Load skin from cache: " + fileName, 1);
        }
        skin = skinResuorce.get(fileName);
    }
    if (S3Constans.DEBUG) {
        S3Log.log("S3ResourceManager::getStyleName", "Skin: " + skin.toString(), 0);
    }
    return skin;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca objekt Xml.Element, ktry jest parsowany w pozostaych czciach
 * programu//from  w w w  . j  ava 2 s.c o m
 *
 * @param fileName
 * @return
 */
public static XmlReader.Element getXml(String fileName) {

    if (xmlResuorce == null) {
        xmlResuorce = new ArrayMap<String, XmlReader.Element>(10);
    }

    XmlReader.Element xml = new XmlReader.Element(null, null);
    if (!xmlResuorce.containsKey(fileName) || reBindProcess == true) {
        if (LOG) {
            S3Log.trace(TAG, "Load XML from file: " + fileName, 1);
        }
        FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
        XmlReader reader = new XmlReader();
        try {
            xml = reader.parse(fileHandle);
            if (USE_CACHE_RESOURCE) {
                xmlResuorce.put(fileName, xml);
            }
        } catch (IOException ex) {
            Logger.getLogger(S3ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        if (LOG) {
            S3Log.trace(TAG, "Load XML from cache: " + fileName, 1);
        }
        xml = xmlResuorce.get(fileName);
    }
    return xml;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * ?aduje program Shadera z dysku//from  w w w .j av  a  2  s .c  o m
 *
 * @param fileName
 * @return
 */
public static ShaderProgram getShaderProgram(String fileName) {
    ShaderProgram shaderProgram;

    if (shaderProgramResuorce == null) {
        shaderProgramResuorce = new ArrayMap<String, ShaderProgram>(10);
    }

    if (!shaderProgramResuorce.containsKey(fileName) || reBindProcess == true) {
        if (LOG) {
            S3Log.trace(TAG, "Load ShaderProgram from file: " + fileName, 3);
        }
        FileHandle vertexHandle = S3File.getFileHandle(fileName + ".vertex", true, false);
        FileHandle fragmentHandle = S3File.getFileHandle(fileName + ".fragment", true, false);
        shaderProgram = getShaderProgramFromString(vertexHandle.readString(), fragmentHandle.readString(),
                fileName);
        if (USE_CACHE_RESOURCE) {
            shaderProgramResuorce.put(fileName, shaderProgram);
        }
    } else {
        if (LOG) {
            S3Log.trace(TAG, "Load ShaderProgram from cache: " + fileName, 1);
        }
        shaderProgram = shaderProgramResuorce.get(fileName);
    }
    return shaderProgram;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca objekt Xml.Element, ktry jest parsowany w pozostaych czciach
 * programu/*from ww  w.j  a v a  2 s. c  o m*/
 *
 * @param fileName
 * @return
 */
public static BitmapFont getBitmapFont(String fileName) {

    if (bitmapFontResuorce == null) {
        bitmapFontResuorce = new ArrayMap<String, BitmapFont>(10);
    }

    BitmapFont bitmapFont;

    if (!bitmapFontResuorce.containsKey(fileName) || reBindProcess == true) {
        if (LOG) {
            S3Log.trace(TAG, "Load Bitmap Font from file: " + fileName, 1);
        }
        FileHandle fileHandle = S3File.getFileHandle("ui/" + fileName, true, false);
        if (fileHandle.exists()) {
            bitmapFont = new BitmapFont(fileHandle);
            bitmapFontResuorce.put(fileName, bitmapFont);
        } else {
            bitmapFont = null;
        }
    } else {
        if (LOG) {
            S3Log.trace(TAG, "Load Bitmap Font from cache: " + fileName, 1);
        }
        bitmapFont = bitmapFontResuorce.get(fileName);
    }
    return bitmapFont;
}

From source file:mobi.shad.s3lib.unit.Unit.java

License:Apache License

public Unit() {
    this.id = "Untitled_" + index;
    current = index;/*  w ww.  j  a  v  a  2s  . c  om*/
    index++;
    components = new ArrayMap<Class<? extends Component>, Component>(5);
}

From source file:mobi.shad.s3lib.unit.Unit.java

License:Apache License

public Unit(String id) {
    this.id = id;
    current = index;//from   w  w  w .  j av  a  2 s . co  m
    index++;
    components = new ArrayMap<Class<? extends Component>, Component>(5);
}