package brickbreaker;

import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.paint.*;

/**
 * @author Pavel Porvatov
 */

// Instance of the MainFrame class
public var mainFrame: MainFrame;

def IS_MOBILE = FX.getProperty("javafx.me.profiles") != null;

function run(__ARGS__ : String[]) {
    // Initialization should be the first
    Config.initialize(IS_MOBILE);

    mainFrame = MainFrame {
        title: "Brick Breaker"
        resizable: false

        scene: Scene {
            fill: Color.BLACK
            width: Config.screenWidth
            height: Config.screenHeight
        }
    }
}

public class MainFrame extends Stage {
    // Instance of splash (if exists)
    var splash: Splash;

    // Instance of level (if exists)
    var level: Level;

    // Number of lifes
    public var lifeCount: Integer;

    // Current score
    public var score: Integer;

    // Initializes game (lifes, scores etc)
    public function startGame() {
        lifeCount = 3;
        score = 0;
        state = 1;
    }

    // Current state of the game. The next values are available
    // 0 - Splash
    // 1..Level.LEVEL_COUNT - Level
    public var state: Integer = 0 on replace {
        if (state < 1 or state > LevelData.getLevelsCount()) {
            splash.stop();
            level.stop();
            
            level = null;
            splash = Splash {};

            scene.content = [
                splash
            ];

            splash.start();
        } else {
            splash.stop();
            level.stop();
            
            splash = null;
            level = Level {
                levelNumber: state
            }

            scene.content = [
                level
            ];
            
            level.start();
        }
    };
}