package cicaprojekt;

import java.awt.Graphics;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

public class Display extends JPanel{
    private List<Drawer> visuals;
    
    public Display() {
        visuals = new ArrayList<>();
        setVisible(false);
    }
    
    public void addVisual(Drawer visual) {
        visuals.add(visual);
    }
    
    public void drawVisuals() throws IOException {
        for(Drawer visual : visuals)
            visual.draw();
        repaint();
        setVisible(true);
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        for(Drawer visual : visuals)
            g.drawImage(visual.getImage(), visual.getTileX() * 64, visual.getTileY() * 64, null);
    }

    public void gapMagic(Gap gap, Field field, int mapwidth) {
        try {
            visuals.set((gap.getY()*mapwidth)+gap.getX(), new FieldDrawer(field));
        }
        catch (IOException e) {
            Control.ioErrorMessage();
        }
    }
}