2015-06-15 23:27:00 +02:00
|
|
|
package fr.evolving.assets;
|
|
|
|
|
2016-01-04 19:10:38 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.Gdx;
|
|
|
|
import com.badlogic.gdx.Preferences;
|
2015-06-20 17:04:11 +02:00
|
|
|
import com.badlogic.gdx.assets.AssetManager;
|
|
|
|
import com.badlogic.gdx.assets.loaders.SkinLoader;
|
2016-01-05 18:40:35 +01:00
|
|
|
import com.badlogic.gdx.assets.loaders.TextureLoader;
|
2015-06-20 17:04:11 +02:00
|
|
|
import com.badlogic.gdx.audio.Music;
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.audio.Sound;
|
2016-01-04 19:10:38 +01:00
|
|
|
import com.badlogic.gdx.files.FileHandle;
|
2015-06-18 00:27:52 +02:00
|
|
|
import com.badlogic.gdx.graphics.Camera;
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.graphics.Color;
|
2015-06-18 00:27:52 +02:00
|
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
|
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.graphics.Pixmap;
|
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
|
|
|
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
|
|
|
import com.badlogic.gdx.graphics.TextureData;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.Animation;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
2015-06-20 17:04:11 +02:00
|
|
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|
|
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
2015-06-30 23:44:27 +02:00
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMap;
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
|
2015-12-27 20:21:22 +01:00
|
|
|
import com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile;
|
2015-06-30 23:44:27 +02:00
|
|
|
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
|
2015-08-08 13:19:29 +02:00
|
|
|
import com.badlogic.gdx.math.Vector2;
|
2015-06-15 23:27:00 +02:00
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
2016-01-04 19:10:38 +01:00
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.TooltipManager;
|
2015-12-27 20:21:22 +01:00
|
|
|
import com.badlogic.gdx.utils.Array;
|
2016-01-04 19:10:38 +01:00
|
|
|
import com.badlogic.gdx.utils.I18NBundle;
|
|
|
|
import com.badlogic.gdx.utils.ObjectMap.Values;
|
2015-06-18 00:27:52 +02:00
|
|
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
|
|
import com.badlogic.gdx.utils.viewport.ScalingViewport;
|
|
|
|
import com.badlogic.gdx.utils.viewport.StretchViewport;
|
2015-06-15 23:27:00 +02:00
|
|
|
|
2016-01-04 19:10:38 +01:00
|
|
|
import fr.evolving.automata.Inverter_I;
|
|
|
|
import fr.evolving.automata.Inverter_II;
|
|
|
|
import fr.evolving.automata.Negativer;
|
|
|
|
import fr.evolving.automata.Negativer_I;
|
|
|
|
import fr.evolving.automata.Negativer_II;
|
|
|
|
import fr.evolving.automata.Negativer_III;
|
|
|
|
import fr.evolving.automata.Neutraliser_I;
|
|
|
|
import fr.evolving.automata.Neutraliser_II;
|
|
|
|
import fr.evolving.automata.Positiver;
|
2015-08-05 12:03:53 +02:00
|
|
|
import fr.evolving.automata.Positiver_I;
|
|
|
|
import fr.evolving.automata.Positiver_II;
|
|
|
|
import fr.evolving.automata.Positiver_III;
|
|
|
|
import fr.evolving.automata.Transmuter;
|
2016-01-11 20:42:55 +01:00
|
|
|
import fr.evolving.database.DatabaseManager;
|
2016-01-10 23:39:29 +01:00
|
|
|
import fr.evolving.database.LocalBase;
|
2016-01-11 20:42:55 +01:00
|
|
|
import fr.evolving.database.SqlBase;
|
|
|
|
import fr.evolving.database.Base.datatype;
|
2016-01-05 18:40:35 +01:00
|
|
|
import fr.evolving.screens.GameScreen;
|
2015-08-05 12:03:53 +02:00
|
|
|
|
2015-06-15 23:27:00 +02:00
|
|
|
public class AssetLoader {
|
2016-01-05 18:40:35 +01:00
|
|
|
public static Skin Skin_level,Skin_ui;
|
2015-06-17 01:13:15 +02:00
|
|
|
public static TextureAtlas Atlas_level;
|
2015-06-15 23:27:00 +02:00
|
|
|
public static Texture Texture_fond;
|
|
|
|
public static Texture Texture_fond2;
|
|
|
|
public static Texture Texture_logo;
|
2015-06-20 17:04:11 +02:00
|
|
|
public static Music intro;
|
2015-06-18 00:27:52 +02:00
|
|
|
public static int width;
|
2015-06-19 03:08:07 +02:00
|
|
|
public static Color[] Levelcolors;
|
|
|
|
public static Color[] Typecolors;
|
|
|
|
public static String[] Typenames;
|
2015-06-18 00:27:52 +02:00
|
|
|
public static int height;
|
|
|
|
public static float ratio;
|
|
|
|
public static ScalingViewport viewport;
|
2015-06-18 01:48:19 +02:00
|
|
|
public static OrthographicCamera Camera;
|
2015-06-20 17:04:11 +02:00
|
|
|
private static Texture emptyT;
|
|
|
|
private static Texture fullT;
|
|
|
|
public static NinePatch empty;
|
|
|
|
public static NinePatch full;
|
|
|
|
public static AssetManager manager;
|
2015-06-30 23:44:27 +02:00
|
|
|
public static TiledMapTileSet tileSet;
|
2016-01-04 19:10:38 +01:00
|
|
|
public static Array<Transmuter> allTransmuter;
|
|
|
|
public static TooltipManager Tooltipmanager;
|
|
|
|
public static I18NBundle french,usa,language;
|
2016-01-05 18:40:35 +01:00
|
|
|
public static TextureFilter quality;
|
2016-01-11 20:42:55 +01:00
|
|
|
public static DatabaseManager Datahandler;
|
2015-06-15 23:27:00 +02:00
|
|
|
|
|
|
|
public static void loadall() {
|
2016-01-05 18:40:35 +01:00
|
|
|
TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
|
|
|
|
params.minFilter = quality;
|
|
|
|
params.magFilter = quality;
|
|
|
|
params.genMipMaps=(quality==TextureFilter.MipMap);
|
2015-06-20 17:04:11 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Initialisation du asset manager");
|
|
|
|
manager = new AssetManager();
|
|
|
|
Gdx.app.debug("AssetLoader","Initialisation du chargement des éléments multimédia");
|
|
|
|
manager.load("textures/level.pack", TextureAtlas.class);
|
2016-01-05 18:40:35 +01:00
|
|
|
manager.load("textures/ui.pack", TextureAtlas.class);
|
|
|
|
manager.load("pictures/fond.png", Texture.class,params);
|
|
|
|
manager.load("pictures/fond2.png", Texture.class,params);
|
2015-06-20 17:04:11 +02:00
|
|
|
manager.load("musics/intro.mp3", Music.class);
|
2016-01-05 18:40:35 +01:00
|
|
|
manager.load("textures/level.json", Skin.class, new SkinLoader.SkinParameter("textures/level.pack"));
|
|
|
|
manager.load("textures/ui.json", Skin.class, new SkinLoader.SkinParameter("textures/ui.pack"));
|
2015-06-20 17:04:11 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 19:10:38 +01:00
|
|
|
public static void finishall() {
|
2016-01-05 18:40:35 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Attente fin chargement...");
|
2015-06-20 17:04:11 +02:00
|
|
|
manager.finishLoading();
|
|
|
|
Gdx.app.debug("AssetLoader","Affectation des éléments multimédia");
|
2016-01-05 18:40:35 +01:00
|
|
|
Atlas_level = manager.get("textures/level.pack");
|
2015-06-20 17:04:11 +02:00
|
|
|
intro = manager.get("musics/intro.mp3");
|
|
|
|
Texture_fond = manager.get("pictures/fond.png");
|
|
|
|
Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
2016-01-05 18:40:35 +01:00
|
|
|
Texture_fond.setFilter(quality, quality);
|
2015-06-20 17:04:11 +02:00
|
|
|
Texture_fond2 = manager.get("pictures/fond2.png");
|
|
|
|
Texture_fond2.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
2016-01-05 18:40:35 +01:00
|
|
|
Texture_fond2.setFilter(quality, quality);
|
2015-06-20 17:04:11 +02:00
|
|
|
Skin_level = manager.get("textures/level.json");
|
2016-01-05 18:40:35 +01:00
|
|
|
Skin_ui = manager.get("textures/ui.json");
|
2015-06-20 17:04:11 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Definition des constantes");
|
2015-06-19 03:08:07 +02:00
|
|
|
Levelcolors=new Color[5];
|
2016-01-05 18:40:35 +01:00
|
|
|
Levelcolors=new Color[]{AssetLoader.Skin_level.getColor("world0"),AssetLoader.Skin_level.getColor("world1"),AssetLoader.Skin_level.getColor("world2"),AssetLoader.Skin_level.getColor("world3"),AssetLoader.Skin_level.getColor("world4")};
|
2015-06-19 03:08:07 +02:00
|
|
|
Typecolors=new Color[13];
|
|
|
|
Typecolors=new Color[]{new Color(0,0,1f,1),new Color(0,0.6f,0,1),new Color(0.196f,0.803f,0.196f,1),new Color(0.5f,0.5f,0.5f,1),new Color(0.8f,0.8f,0.8f,1),new Color(0.6f,0,0,1),new Color(1f,0,0,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0.294f,0.466f,0.615f,1),new Color(0.478f,0.192f,0.098f,1)};
|
|
|
|
Typenames=new String[13];
|
|
|
|
Typenames=new String[]{"E-","e-","Ph","e0","E0","e+","E+","K","L","M","N","n","p"};
|
2016-01-05 18:40:35 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Création des tiles...");
|
2015-06-30 23:44:27 +02:00
|
|
|
tileSet = new TiledMapTileSet();
|
2015-12-27 20:21:22 +01:00
|
|
|
Array<TextureAtlas.AtlasRegion> allregions=Atlas_level.getRegions();
|
2016-01-05 18:40:35 +01:00
|
|
|
Gdx.app.debug("AssetLoader",allregions.size+" régions disponibles");
|
2015-12-27 20:21:22 +01:00
|
|
|
for (int i=0;i<allregions.size;i++) {
|
2016-01-05 18:40:35 +01:00
|
|
|
allregions.get(i).getTexture().setFilter(quality, quality);
|
2015-12-27 20:21:22 +01:00
|
|
|
if (allregions.get(i).name.startsWith("sprite")) {
|
|
|
|
if (allregions.get(i).name.contains("#"))
|
|
|
|
{
|
|
|
|
String[] name=allregions.get(i).name.split("_");
|
2015-12-30 12:10:02 +01:00
|
|
|
String[] type=name[0].split("-");
|
2015-12-27 20:21:22 +01:00
|
|
|
if (name[0].contains("sprite"))
|
|
|
|
{
|
|
|
|
int id=Integer.parseInt(name[1].split("#")[0]);
|
|
|
|
if (tileSet.getTile(1000+id)==null) {
|
|
|
|
Gdx.app.debug("AssetLoader","Animated Tiles N°:"+String.valueOf(id+1000));
|
|
|
|
int maxid=0;
|
2015-12-30 12:10:02 +01:00
|
|
|
for(int j=1;Atlas_level.findRegion("sprite-"+type[1]+"_"+id+"#"+j)!=null;j++)
|
2015-12-27 20:21:22 +01:00
|
|
|
maxid=j;
|
|
|
|
Array<StaticTiledMapTile> frameTiles=new Array<StaticTiledMapTile>(maxid);
|
|
|
|
for(int j=1;j<=maxid;j++)
|
2015-12-30 12:10:02 +01:00
|
|
|
frameTiles.add(new StaticTiledMapTile((Atlas_level.findRegion("sprite-"+type[1]+"_"+id+"#"+j))));
|
2015-12-27 20:21:22 +01:00
|
|
|
AnimatedTiledMapTile atile=new AnimatedTiledMapTile(0.15f,frameTiles);
|
|
|
|
Gdx.app.debug("AssetLoader","Taille:"+String.valueOf(frameTiles.size));
|
|
|
|
atile.setId(1000+id);
|
2015-12-30 12:10:02 +01:00
|
|
|
atile.getProperties().put("type", type[1]);
|
2015-12-27 20:21:22 +01:00
|
|
|
tileSet.putTile(1000+id, atile);
|
2015-12-30 12:10:02 +01:00
|
|
|
|
2015-12-27 20:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-30 12:10:02 +01:00
|
|
|
String[] type=allregions.get(i).name.split("-");
|
2015-12-27 20:21:22 +01:00
|
|
|
StaticTiledMapTile atile= new StaticTiledMapTile(allregions.get(i));
|
|
|
|
atile.setId(allregions.get(i).index);
|
2015-12-30 12:10:02 +01:00
|
|
|
atile.getProperties().put("type", type[1]);
|
2015-12-27 20:21:22 +01:00
|
|
|
tileSet.putTile(allregions.get(i).index, atile);
|
2015-12-30 12:10:02 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Type:"+type[1]+" Tiles N°:"+String.valueOf(allregions.get(i).index));
|
2015-12-27 20:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-30 23:44:27 +02:00
|
|
|
}
|
2016-01-04 19:10:38 +01:00
|
|
|
allTransmuter=new Array<Transmuter>();
|
|
|
|
allTransmuter.add(new Positiver(null));
|
|
|
|
allTransmuter.add(new Positiver_I(null));
|
|
|
|
allTransmuter.add(new Positiver_II(null));
|
|
|
|
allTransmuter.add(new Positiver_III(null));
|
|
|
|
allTransmuter.add(new Negativer(null));
|
|
|
|
allTransmuter.add(new Negativer_I(null));
|
|
|
|
allTransmuter.add(new Negativer_II(null));
|
|
|
|
allTransmuter.add(new Negativer_III(null));
|
|
|
|
allTransmuter.add(new Inverter_I(null));
|
|
|
|
allTransmuter.add(new Inverter_II(null));
|
|
|
|
allTransmuter.add(new Neutraliser_I(null));
|
|
|
|
allTransmuter.add(new Neutraliser_II(null));
|
|
|
|
for(Transmuter transmuter:allTransmuter) {
|
|
|
|
Values<Integer> allTiles=transmuter.getTilesid().iterator();
|
|
|
|
while(allTiles.hasNext()) {
|
|
|
|
Integer atile=allTiles.next();
|
|
|
|
Gdx.app.debug("AssetLoader","Ajustement données Tiles N°:"+String.valueOf(atile)+" Nom:"+transmuter.getName());
|
|
|
|
AssetLoader.tileSet.getTile(atile).getProperties().put("transmuter", transmuter);
|
|
|
|
AssetLoader.tileSet.getTile(atile).getProperties().put("name", transmuter.getName());
|
2015-12-30 12:10:02 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-04 19:10:38 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Ajout de la gestion des tooltips");
|
|
|
|
Tooltipmanager= new TooltipManager();
|
|
|
|
Gdx.app.debug("AssetLoader","Ajout de la gestion des locales");
|
|
|
|
FileHandle baseFileHandle = Gdx.files.internal("i18n/messages/messages");
|
|
|
|
usa = I18NBundle.createBundle(baseFileHandle, new Locale("en"));
|
|
|
|
french = I18NBundle.createBundle(baseFileHandle, new Locale("fr"));
|
2016-01-05 18:40:35 +01:00
|
|
|
if (Preference.prefs.getBoolean("Language"))
|
|
|
|
language=french;
|
|
|
|
else
|
|
|
|
language=usa;
|
2016-01-04 19:10:38 +01:00
|
|
|
I18NBundle.setExceptionOnMissingKey(true);
|
2016-01-11 20:42:55 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Mise en place de la base de donnée");
|
|
|
|
Datahandler= new DatabaseManager();
|
|
|
|
Datahandler.RegisterBackend(LocalBase.class);
|
|
|
|
Datahandler.RegisterBackend(SqlBase.class);
|
|
|
|
Datahandler.Attach(datatype.userdata, "local:test.db");
|
|
|
|
Datahandler.Attach(datatype.statdata, "local:test.db");
|
|
|
|
Datahandler.Attach(datatype.gamedata, "local:test.db");
|
2016-01-12 01:02:29 +01:00
|
|
|
|
2015-12-30 12:10:02 +01:00
|
|
|
}
|
2015-06-18 00:27:52 +02:00
|
|
|
|
2015-08-08 15:09:17 +02:00
|
|
|
public static Transmuter getTransmuter(String Name) {
|
|
|
|
for(Transmuter transmuter:allTransmuter) {
|
|
|
|
if (transmuter.isTransmuter(Name))
|
|
|
|
return transmuter;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-06-18 00:27:52 +02:00
|
|
|
public static void init() {
|
|
|
|
Gdx.app.debug("AssetLoader","Initialisation de la résolution virtuelle...");
|
|
|
|
int realWidth=Gdx.graphics.getWidth();
|
|
|
|
int realHeight=Gdx.graphics.getHeight();
|
|
|
|
float realRatio=realWidth/(float)realHeight;
|
|
|
|
Gdx.app.debug("AssetLoader","Résolution de "+realWidth+"x"+realHeight+" ratio de "+String.format("%.2f", realRatio)+".");
|
|
|
|
ratio=1;
|
|
|
|
width=1920;
|
|
|
|
height=1080;
|
|
|
|
if (Math.abs(16f/9f-realRatio)>Math.abs(4f/3f-realRatio)) {
|
2015-06-18 02:58:50 +02:00
|
|
|
ratio=1.44f;
|
2015-06-18 00:27:52 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Ratio 4/3, résolution virtuelle : 1920x1440.");
|
|
|
|
height=1440;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Gdx.app.debug("AssetLoader","Ratio 16/9, résolution virtuelle : 1920x1080.");
|
2015-06-18 01:48:19 +02:00
|
|
|
Camera = new OrthographicCamera(width,height);
|
|
|
|
Camera.position.set(width/2, height/2, 0);
|
|
|
|
Camera.update();
|
2016-01-05 18:40:35 +01:00
|
|
|
if (Preference.prefs.getInteger("Adaptation")==1) {
|
2015-06-18 01:48:19 +02:00
|
|
|
viewport = new StretchViewport(width,height);
|
2015-06-18 00:27:52 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Adaptation d'écran maximale, 'Aspect-Ratio' non conservé.");
|
2015-06-15 23:27:00 +02:00
|
|
|
}
|
2015-06-18 00:27:52 +02:00
|
|
|
else {
|
2015-06-18 01:48:19 +02:00
|
|
|
viewport = new FitViewport(width,height);
|
2015-06-18 00:27:52 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Adaptation d'écran totale, 'Aspect-Ratio' conservé.");
|
|
|
|
}
|
|
|
|
viewport.apply();
|
2015-06-15 23:27:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void load() {
|
2016-01-05 18:40:35 +01:00
|
|
|
Gdx.app.debug("AssetLoader","Réglage de la qualité des textures");
|
|
|
|
quality=GameScreen.quality.values()[Preference.prefs.getInteger("Quality")].getQuality();
|
2015-06-18 00:27:52 +02:00
|
|
|
Gdx.app.debug("AssetLoader","Chargements des éléments minimalistes");
|
2016-01-05 18:40:35 +01:00
|
|
|
Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png"),quality==TextureFilter.MipMap);
|
|
|
|
Texture_logo.setFilter(quality,quality);
|
|
|
|
emptyT=new Texture(Gdx.files.internal("pictures/empty.png"),quality==TextureFilter.MipMap);
|
|
|
|
emptyT.setFilter(quality,quality);
|
|
|
|
fullT=new Texture(Gdx.files.internal("pictures/full.png"),quality==TextureFilter.MipMap);
|
|
|
|
fullT.setFilter(quality,quality);
|
|
|
|
empty=new NinePatch(new TextureRegion(emptyT,24,24),8,8,8,8);
|
2015-06-20 17:04:11 +02:00
|
|
|
full=new NinePatch(new TextureRegion(fullT,24,24),8,8,8,8);
|
2015-06-15 23:27:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void dispose() {
|
|
|
|
Texture_logo.dispose();
|
|
|
|
Texture_fond.dispose();
|
|
|
|
Skin_level.dispose();
|
|
|
|
Atlas_level.dispose();
|
|
|
|
intro.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|