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.Pair;
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) {
        this.mouse = mouse;
        inputController = new InputController();
    }

    public void drawWorld(Batch batch) {
        for (Pair<Integer, Integer> chunkpair : Chunks.blocks.keySet()) {
            String name = Chunks.blocks.get(chunkpair).getName();
            batch.draw(
                    BlockMaterials.getTexture(name),
                    chunkpair.getFirst() << TILE_SHIFT,
                    chunkpair.getSecond() << TILE_SHIFT
            );
        }
    }

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