package de.frajul.endlessroll.levels;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

import java.util.List;

/**
 * Created by Julian on 07.12.2015.
 */
public class Level {

    @Attribute
    private int packId;
    @Attribute
    private int id;
    @Attribute
    private float goalX;
    @Attribute
    private float startSpeed;
    @Attribute
    private float endSpeed;
    @Attribute
    private float terrainEdge;
    @Attribute
    private float ceilingEdge;
    @ElementList
    private List<TileData> terrainTiles;
    @ElementList
    private List<TileData> ceilingTiles;
    @ElementList
    private List<ObstacleData> obstacles;
    @ElementList
    private List<PositionData> stars;
    @Element(required = false)
    private PositionData energy;

    private boolean finished = false;
    private boolean locked = true;
    private boolean[] collectedStars = {false, false, false};
    private boolean energyCollected = false;

    public int getPackId() {
        return packId;
    }

    public int getId() {
        return id;
    }

    public float getGoalX() {
        return goalX;
    }

    public float getStartSpeed() {
        return startSpeed;
    }

    public float getEndSpeed() {
        return endSpeed;
    }

    public float getTerrainEdge() {
        return terrainEdge;
    }

    public float getCeilingEdge() {
        return ceilingEdge;
    }

    public List<TileData> getTerrainTiles() {
        return terrainTiles;
    }

    public List<TileData> getCeilingTiles() {
        return ceilingTiles;
    }

    public List<ObstacleData> getObstacles() {
        return obstacles;
    }

    public List<PositionData> getStars() {
        return stars;
    }

    public PositionData getEnergyData() {
        return energy;
    }

    public boolean isLocked() {
        return locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    public boolean isFinished() {
        return finished;
    }

    public void setFinished(boolean finished) {
        this.finished = finished;
    }

    public boolean isStarCollected(int index) {
        return collectedStars[index];
    }

    public void setStarCollected(int index, boolean collected) {
        collectedStars[index] = collected;
    }

    public String getCollectedStarCodeForSQL() {
        String code = "";
        for (int i = 0; i < 3; i++)
            code += collectedStars[i] ? (i + 1) + "" : "";
        return code;
    }

    public void setCollectedStarsFromSQL(String code) {
        for (int i = 0; i < 3; i++)
            collectedStars[i] = code.contains((i + 1) + "");
    }

    public boolean[] getCollectedStars() {
        return collectedStars;
    }

    public boolean isEnergyCollected() {
        return energyCollected;
    }

    public void setEnergyCollected(boolean collected) {
        this.energyCollected = collected;
    }

    public void reset() {
        finished = false;
        locked = true;
        collectedStars = new boolean[]{false, false, false};
        energyCollected = false;
    }

}
