OSDN Git Service

ran gdx-tools HeaderFixer tool
[mikumikustudio/libgdx-mikumikustudio.git] / gdx / src / com / badlogic / gdx / assets / loaders / ParticleEffectLoader.java
1 /*******************************************************************************\r
2  * Copyright 2011 See AUTHORS file.\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * \r
8  *   http://www.apache.org/licenses/LICENSE-2.0\r
9  * \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  ******************************************************************************/
16
17 package com.badlogic.gdx.assets.loaders;
18
19 import com.badlogic.gdx.assets.AssetDescriptor;
20 import com.badlogic.gdx.assets.AssetLoaderParameters;
21 import com.badlogic.gdx.assets.AssetManager;
22 import com.badlogic.gdx.files.FileHandle;
23 import com.badlogic.gdx.graphics.g2d.ParticleEffect;
24 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
25 import com.badlogic.gdx.utils.Array;
26
27 /** {@link AssetLoader} to load {@link ParticleEffect} instances. Passing a {@link ParticleEffectParameter} to
28  * {@link AssetManager#load(String, Class, AssetLoaderParameters)} allows to specify an atlas file or an image directory to be
29  * used for the effect's images. Per default images are loaded from the directory in which the effect file is found. */
30 public class ParticleEffectLoader extends SynchronousAssetLoader<ParticleEffect, ParticleEffectLoader.ParticleEffectParameter> {
31         public ParticleEffectLoader (FileHandleResolver resolver) {
32                 super(resolver);
33         }
34
35         @Override
36         public ParticleEffect load (AssetManager am, String fileName, FileHandle file, ParticleEffectParameter param) {
37                 ParticleEffect effect = new ParticleEffect();
38                 if (param != null && param.atlasFile != null)
39                         effect.load(file, am.get(param.atlasFile, TextureAtlas.class));
40                 else if (param != null && param.imagesDir != null)
41                         effect.load(file, param.imagesDir);
42                 else
43                         effect.load(file, file.parent());
44                 return effect;
45         }
46
47         @Override
48         public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectParameter param) {
49                 Array<AssetDescriptor> deps = null;
50                 if (param != null && param.atlasFile != null) {
51                         deps = new Array<AssetDescriptor>();
52                         deps.add(new AssetDescriptor<TextureAtlas>(param.atlasFile, TextureAtlas.class));
53                 }
54                 return deps;
55         }
56
57         /** Parameter to be passed to {@link AssetManager#load(String, Class, AssetLoaderParameters)} if additional configuration is
58          * necessary for the {@link ParticleEffect}. */
59         public static class ParticleEffectParameter extends AssetLoaderParameters<ParticleEffect> {
60                 /** Atlas file name. */
61                 public String atlasFile;
62                 /** Image directory. */
63                 public FileHandle imagesDir;
64         }
65 }