package school_project;

import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;

import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.stage.Screen;
import javafx.stage.Stage;
import school_project.Menu.MenuAccueil;
import school_project.Parsers.FileParserFactory;

import java.io.File;
import java.io.IOException;


public class Controller extends Application {
    private static Stage stage;
    Parent root;
    public static Vec2 screen_size;

    @Override
    public void start(Stage primaryStage) throws IOException {
        new File("save.slevel");
        stage = primaryStage;
        screen_size = new Vec2(
            (int) Screen.getPrimary().getBounds().getWidth(),
            (int) Screen.getPrimary().getBounds().getHeight()
        );

        stage.setTitle("ROAD TO MASTER YOU");

        // Full Screen mode

        root = new MenuAccueil();

        switchRoot(root);
        stage.show();
    }


    public static void switchRoot(Parent root){
        Scene scene = new Scene(root);
        if(root instanceof GameUI){
            scene.setOnKeyPressed(event ->{
                GameUI game = (GameUI) root;
                if(event.getCode() == KeyCode.ESCAPE){
                    try {
                        FileParserFactory.saveFileFromMap(new File("save.slevel"), game.getLevel());
                        switchRoot(new MenuAccueil());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
        stage.setScene(scene);

        stage.setFullScreen(true);
        stage.setFullScreenExitHint("");
        stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
    }
    public static void main(String[] args) {
        launch();
    }
}


