package com.mygdx.game.Dimension;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
import com.mygdx.game.Character.InputController;
import com.mygdx.game.Character.Mouse;
import com.mygdx.game.Restrictions;

import static com.mygdx.game.Main.cam;

public class WorldRenderer implements Restrictions {
    private Mouse mouse;
    private InputController inputController;

    public WorldRenderer(Mouse mouse, InputController inputController) {
        this.mouse = mouse;
        this.inputController = inputController;
    }

    public void drawWorld(Batch batch, int layer) {
        for (Triple<Integer, Integer, Integer> chunkpair : Chunks.blocks.keySet()) {
            if(chunkpair.getThird() == layer) {
                batch.draw(
                        Chunks.blocks.get(chunkpair).getTexture(),
                        chunkpair.getFirst() << TILE_SHIFT,
                        chunkpair.getSecond() << TILE_SHIFT
                );
            }
        }
    }

    public void render(SpriteBatch batch) {
        inputController.handleInput();
        drawWorld(batch,0);
        drawWorld(batch,1);
        batch.setProjectionMatrix(cam.combined);
        cam.update();
        mouse.render(batch);
    }
}
