package cz.jzitnik.game;

import cz.jzitnik.game.objects.GameObject;
import cz.jzitnik.ui.pixels.Empty;
import cz.jzitnik.ui.pixels.Pixel;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public class GameRoom {
    private GameRoom left;
    private GameRoom right;
    private GameRoom up;
    private GameRoom down;
    private final Pixel[][] overrideBuffer;
    private final ResourceManager.Resource texture;

    public GameRoom(ResourceManager.Resource texture) {
        this.texture = texture;

        // Size of a room
        int height = 225;
        int width = 225 * 2;

        Pixel[][] overrideBuffer = new Pixel[height][width];
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                overrideBuffer[y][x] = new Empty();
                overrideBuffer[y][x] = new Empty();
            }
        }

        this.overrideBuffer = overrideBuffer;
    }

    private final List<GameObject> objects = new ArrayList<>();

    public void addObject(GameObject gameObject) {
        objects.addFirst(gameObject);
    }

    public void setLeft(GameRoom left) {
        setLeft(left, true);
    }
    public void setLeft(GameRoom left, boolean addReference) {
        this.left = left;
        if (addReference) {
            left.setRight(this, false);
        }
    }
    public void setRight(GameRoom right) {
        setRight(right, true);
    }
    public void setRight(GameRoom right, boolean addReference) {
        this.right = right;
        if (addReference) {
            right.setLeft(this, false);
        }
    }
    public void setUp(GameRoom up) {
        setUp(up, true);
    }
    public void setUp(GameRoom up, boolean addReference) {
        this.up = up;
        if (addReference) {
            up.setDown(this, false);
        }
    }
    public void setDown(GameRoom down) {
        setDown(down, true);
    }
    public void setDown(GameRoom down, boolean addReference) {
        this.down = down;
        if (addReference) {
            down.setUp(this, false);
        }
    }
}
