Home | History | Annotate | Download | only in assets
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.assets;
     18 
     19 import com.badlogic.gdx.files.FileHandle;
     20 
     21 /** Describes an asset to be loaded by it's filename, type and {@link AssetLoaderParameters}. Instances of this are used in
     22  * {@link AssetLoadingTask} to load the actual asset.
     23  * @author mzechner */
     24 public class AssetDescriptor<T> {
     25 	public final String fileName;
     26 	public final Class<T> type;
     27 	public final AssetLoaderParameters params;
     28 	/** The resolved file. May be null if the fileName has not been resolved yet. */
     29 	public FileHandle file;
     30 
     31 	public AssetDescriptor (String fileName, Class<T> assetType) {
     32 		this(fileName, assetType, null);
     33 	}
     34 
     35 	/** Creates an AssetDescriptor with an already resolved name. */
     36 	public AssetDescriptor (FileHandle file, Class<T> assetType) {
     37 		this(file, assetType, null);
     38 	}
     39 
     40 	public AssetDescriptor (String fileName, Class<T> assetType, AssetLoaderParameters<T> params) {
     41 		this.fileName = fileName.replaceAll("\\\\", "/");
     42 		this.type = assetType;
     43 		this.params = params;
     44 	}
     45 
     46 	/** Creates an AssetDescriptor with an already resolved name. */
     47 	public AssetDescriptor (FileHandle file, Class<T> assetType, AssetLoaderParameters<T> params) {
     48 		this.fileName = file.path().replaceAll("\\\\", "/");
     49 		this.file = file;
     50 		this.type = assetType;
     51 		this.params = params;
     52 	}
     53 
     54 	@Override
     55 	public String toString () {
     56 		StringBuffer buffer = new StringBuffer();
     57 		buffer.append(fileName);
     58 		buffer.append(", ");
     59 		buffer.append(type.getName());
     60 		return buffer.toString();
     61 	}
     62 }
     63