package de.frajul.endlessroll.main.tutorial;

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

import de.frajul.endlessroll.main.GameActivity;

/**
 * Created by Julian on 14.03.2017.
 */

public class Tutorial {

    private GameActivity gameActivity;
    private List<BreakPoint> breakPoints;
    protected List<BreakPoint> currentBreakPoints = new ArrayList<>();

    public Tutorial(GameActivity gameActivity, BreakPoint... breakPoints) {
        this.gameActivity = gameActivity;
        this.breakPoints = Arrays.asList(breakPoints);
    }

    public void reset() {
        for (BreakPoint breakPoint : breakPoints)
            breakPoint.setAlreadyShown(false);
        currentBreakPoints.clear();
    }

    public void update(float playerProgress) {
        playerProgress *= 2f;
        currentBreakPoints.clear();

        boolean newBreakPoints = false;
        for (BreakPoint breakPoint : breakPoints) {
            if (!breakPoint.isAlreadyShown() && playerProgress >= breakPoint.getX() && breakPoint
                    .getX() != BreakPoint.NONE_X) {
                breakPoint.setAlreadyShown(true);
                currentBreakPoints.add(breakPoint);
                newBreakPoints = true;
            }
        }
        if (newBreakPoints)
            showCurrentBreakPoints();
    }

    private void showCurrentBreakPoints() {
        gameActivity.showTutorial(currentBreakPoints);
    }

    public void showAllBreakPoints() {
        gameActivity.showTutorial(breakPoints);
    }

}