Java Resource Load getResource(String fileName, int type)

Here you can find the source of getResource(String fileName, int type)

Description

Returns a game resource.

License

Open Source License

Parameter

Parameter Description
fileName The name of the requested resource, without file ending.
type The resource type (ResourceHelper.RES_XXX).

Return

The requested resource file.

Declaration

public static File getResource(String fileName, int type) 

Method Source Code


//package com.java2s;
/*//from  w  w w  .j a  v  a  2 s  .c  o  m
 * Copyright (c) 2014 mgamelabs
 * To see our full license terms, please visit https://github.com/mgamelabs/mengine/blob/master/LICENSE.md
 * All rights reserved.
 */

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final int RES_PREFERENCE = 2;
    public static final int RES_SAVE = 3;
    public static final int RES_MATERIAL = 4;
    public static final int RES_MODEL = 5;
    public static final int RES_SOUND = 6;
    public static final int RES_TEXTURE = 7;
    public static final int RES_TEXTURE_ANIMATED = 8;
    public static final int RES_SHADER_V = 9;
    public static final int RES_SHADER_F = 10;
    private static List<String> paths = new ArrayList<String>();

    /**
     * Returns a game resource.
     *
     * @param fileName The name of the requested resource, without file ending.
     * @param type     The resource type (ResourceHelper.RES_XXX).
     * @return The requested resource file.
     */
    public static File getResource(String fileName, int type) {

        String filePath;

        switch (type) {

        default:
            filePath = paths.get(type) + fileName;
            break;
        case RES_PREFERENCE:
            filePath = paths.get(type) + fileName + ".properties";
            break;
        case RES_SAVE:
            filePath = paths.get(type) + fileName + ".mess";
            break;
        case RES_MATERIAL:
            filePath = paths.get(type) + fileName + ".mtl";
            break;
        case RES_MODEL:
            filePath = paths.get(type) + fileName + ".obj";
            break;
        case RES_SOUND:
            filePath = paths.get(type) + fileName + ".wav";
            break;
        case RES_TEXTURE:
            filePath = paths.get(type) + fileName + ".png";
            break;
        case RES_TEXTURE_ANIMATED:
            filePath = paths.get(type) + fileName + ".meta";
            break;
        case RES_SHADER_V:
            filePath = paths.get(type) + fileName + ".vs";
            break;
        case RES_SHADER_F:
            filePath = paths.get(type) + fileName + ".fs";
            break;

        }

        return new File(filePath);

    }
}

Related

  1. getResource(Class c, String name)
  2. getResource(ClassLoader classLoader, final String path)
  3. getResource(final String aResName)
  4. getResource(final String resource)
  5. getResource(String fileName)
  6. getResource(String name)
  7. getResource(String path)
  8. getResource(String propertiesPath)
  9. getResource(String uri)