package com.pesets.resources;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class ResourceManager {
	public static final String textureFolder = "data/textures/";
	public static final String soundFolder = "data/sound/";
	
	private static ResourceManager instance = null;
	
	private AssetManager manager = new AssetManager();
	private Skin skin;
	private static boolean sound = true;
	

	private ResourceManager(){
		manager.load(textureFolder + "cityBG.png", Texture.class);
		manager.load(textureFolder + "equip.png", Texture.class);
		manager.load(textureFolder + "skills.png", Texture.class);
		manager.load(textureFolder + "tiles.png", Texture.class);
		manager.load(textureFolder + "player.png", Texture.class);
		manager.load(textureFolder + "enemy1.png", Texture.class);
		manager.load(textureFolder + "enemy2.png", Texture.class);
		manager.load(textureFolder + "enemy3.png", Texture.class);
		manager.load(textureFolder + "enemy4.png", Texture.class);
		manager.load(textureFolder + "enemy5.png", Texture.class);
		manager.load(textureFolder + "enemy6.png", Texture.class);
		manager.load(textureFolder + "enemy7.png", Texture.class);
		manager.load(textureFolder + "enemy8.png", Texture.class);
		
		for (int i = 0; i < 4; i++)
			manager.load(soundFolder + "hit_0" + i + ".ogg", Sound.class);
		manager.load(soundFolder + "twinkle.mp3", Sound.class);
		manager.load(soundFolder + "sword.mp3", Sound.class);
		
		manager.finishLoading();
		
		skin = new Skin(Gdx.files.internal("data/uiskin.json"), 
				Gdx.files.internal("data/uiskin.png"));
	}
	
	public static void init()
	{
		instance = new ResourceManager();
	}
	
	public static ResourceManager getInstance()
	{
		if (instance == null)
			init();
		return instance;
	}
	
	public static AssetManager getAssetManager()
	{
		return getInstance().manager;
	}
	
	public static Skin getSkin()
	{
		return getInstance().skin;
	}
	
	public void playSound(String name)
	{
		if (sound)
			getAssetManager().get(soundFolder + name, Sound.class).play();
	}
	
	public boolean isSound()
	{
		return sound;
	}
	
	public void setSound(boolean sound)
	{
		ResourceManager.sound = sound;
	}
}
