package net.minecraft.src;

import net.lax1dude.eaglercraft.EaglerImage;
import net.lax1dude.eaglercraft.EaglerInputStream;
import net.lax1dude.eaglercraft.TextureLocation;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import javax.imageio.ImageIO;

public class DefaultResourcePack implements ResourcePack
{
    public static final Set defaultResourceDomains = new HashSet<>(Arrays.asList("minecraft"));
    private final Map mapResourceFiles = new HashMap<>();
    private final File fileAssets;

    public DefaultResourcePack(File par1File)
    {
        this.fileAssets = par1File;
        this.readAssetsDir(this.fileAssets);
    }

    public InputStream getInputStream(TextureLocation par1TextureLocation) throws IOException
    {
        InputStream var2 = this.getResourceStream(par1TextureLocation);

        if (var2 != null)
        {
            return var2;
        }
        else
        {
            File var3 = (File)this.mapResourceFiles.get(par1TextureLocation.toString());

            if (var3 != null)
            {
                return new FileInputStream(var3);
            }
            else
            {
                throw new FileNotFoundException("Something is fuck: " + par1TextureLocation.toString() + "I have no idea what the hell this is"); // FIX THIS SHIT
            }
        }
    }

    private InputStream getResourceStream(TextureLocation par1TextureLocation)
    {
        return DefaultResourcePack.class.getResourceAsStream("/assets/minecraft/" + par1TextureLocation);
    }

    public void addResourceFile(String par1Str, File par2File)
    {
        this.mapResourceFiles.put((new TextureLocation(par1Str)).toString(), par2File);
    }

    public boolean resourceExists(TextureLocation par1TextureLocation)
    {
        return this.getResourceStream(par1TextureLocation) != null || this.mapResourceFiles.containsKey(par1TextureLocation.toString());
    }

    public Set getResourceDomains()
    {
        return defaultResourceDomains;
    }

    public void readAssetsDir(File par1File)
    {
        if (par1File.isDirectory())
        {
            File[] var2 = par1File.listFiles();
            int var3 = var2.length;

            for (int var4 = 0; var4 < var3; ++var4)
            {
                File var5 = var2[var4];
                this.readAssetsDir(var5);
            }
        }
        else
        {
            //this.addResourceFile(AbstractResourcePack.getRelativeName(this.fileAssets, par1File), par1File);
        }
    }


    public EaglerImage getPackImage() throws IOException
    {
        //return ImageIO.read(DefaultResourcePack.class.getResourceAsStream("/" + (new TextureLocation("pack.png"))));
        return null; // FIX THIS SHIT
    }

    public String getPackName()
    {
        return "Default";
    }
}
