package view;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Observable;
import java.util.stream.Collectors;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.GridPane;

/**
 * 
 * @author Jonathan
 * @author Nishad
 * @author Joshua
 *
 */


public class SplashScreen extends GUIScene implements GUIController {

    @FXML private GridPane splash;
    @FXML private Button launchEditorButton;
    @FXML private Button launchRunnerButton;
    @FXML private ComboBox myGames;
    private static final String LAUNCH_EDITOR = "Launch Editor";
    private static final String LAUNCH_RUNNER = "Launch Runner";

    @Override
    @FXML
    public void initialize () {
        launchEditorButton.setText(LAUNCH_EDITOR);
        launchRunnerButton.setText(LAUNCH_RUNNER);
        
        File folder = new File("./myGames/");
        List<File> files = Arrays.asList(folder.listFiles());
        List<String> gameNames = files
        		.stream()
        		.filter(f -> f.isDirectory())
        		.map(f -> f.getName())
        		.collect(Collectors.toList());   
        myGames.setItems(FXCollections.observableArrayList(gameNames));
        
        launchEditorButton.setOnAction(e -> switchScene(ViewScreen.EDITOR, ""));
        //TODO Change to ViewScreen.RUNNER, also fill in String game (2nd argument)
        launchRunnerButton.setOnAction(e -> switchScene(ViewScreen.EDITOR, ""));
    }


    @Override
    public String[] getCSS () {
        return new String[] { "/view/stylesheets/splash.css" };
    }

    @Override
    public Node getRoot () {
        return splash;
    }

    @Override
    public void update (Observable o, Object arg) {
        // TODO Auto-generated method stub
        
    }

}

@@ -684,16 +684,24 @@
 ComboBox
+%3CString%3E
  myGames
@@ -702,16 +702,16 @@
 yGames;%0A
-
     priv
@@ -831,16 +831,80 @@
 Runner%22;
+%0A    private static final String GAMES_DIRECTORY = %22./myGames/%22;
 %0A%0A    @O
@@ -1095,28 +1095,31 @@
 ew File(
-%22./myGames/%22
+GAMES_DIRECTORY
 );%0A     

Make games directory an instance variable of the splash controller