refactored so manager is entrypoint

This commit is contained in:
Joshua Perry 2023-02-01 14:45:52 +00:00
parent c53c3ed173
commit 3129206188
3 changed files with 36 additions and 51 deletions

View File

@ -1,33 +0,0 @@
package com.r0r5chach;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Stage;
import javafx.scene.Scene;
public class Main extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("main"), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}
public static void main(String[] args) {
launch();
}
}

View File

@ -81,6 +81,10 @@ public class MainController implements Initializable {
loadView(); loadView();
} }
public void setCompetitors(CompetitorList list) {
this.competitors = list;
}
@FXML @FXML
private void getCompetitor() { private void getCompetitor() {
Competitor player = this.competitors.getCompetitors().get(this.competitorIds.indexOf(this.competitorsList.getSelectionModel().getSelectedItem())); Competitor player = this.competitors.getCompetitors().get(this.competitorIds.indexOf(this.competitorsList.getSelectionModel().getSelectedItem()));
@ -98,7 +102,6 @@ public class MainController implements Initializable {
} }
private void loadCompetitors(){ private void loadCompetitors(){
this.competitors = new Manager().getCompetitors();
this.competitorIds = new ArrayList<Integer>(); this.competitorIds = new ArrayList<Integer>();
for (Competitor player : this.competitors.getCompetitors()) { for (Competitor player : this.competitors.getCompetitors()) {
this.competitorIds.add(player.getPlayerNumber()); this.competitorIds.add(player.getPlayerNumber());

View File

@ -1,34 +1,48 @@
package com.r0r5chach; package com.r0r5chach;
import java.io.File; import java.io.File;
import javafx.application.Application;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Stage;
import javafx.scene.Scene;
import static com.r0r5chach.CompetitorList.createErrorLog; import static com.r0r5chach.CompetitorList.createErrorLog;
public class Manager { public class Manager extends Application {
private CompetitorList competitors; private static Scene scene;
@Override
public Manager() { public void start(Stage stage) throws IOException {
init(); scene = new Scene(loadFXML("main"), 640, 480);
stage.setScene(scene);
stage.show();
} }
public CompetitorList getCompetitors() { public static void setRoot(String fxml) throws IOException {
return competitors; scene.setRoot(loadFXML(fxml));
} }
private static Parent loadFXML(String fxml) throws IOException {
public File getReport() { FXMLLoader fxmlLoader = new FXMLLoader(Manager.class.getResource(fxml + ".fxml"));
File report; Parent root = fxmlLoader.load();
try { switch(fxml) {
report = competitors.createReportFile(); case "main":
MainController controller = fxmlLoader.<MainController>getController();
controller.setCompetitors(createList());
break;
} }
catch (Exception e) {
report = new File(createErrorLog(e, "src/main/resource/com/r0r5chach/log.txt")); return root;
}
return report;
} }
private void init() { public static void main(String[] args) {
launch();
}
private static CompetitorList createList() {
CompetitorList competitors = null;
File valorantPlayers = new File("src/main/resources/com/r0r5chach/valorantPlayers.txt"); File valorantPlayers = new File("src/main/resources/com/r0r5chach/valorantPlayers.txt");
File r6Players = new File("src/main/resources/com/r0r5chach/r6Players.txt"); File r6Players = new File("src/main/resources/com/r0r5chach/r6Players.txt");
try { try {
@ -39,5 +53,6 @@ public class Manager {
catch (Exception e) { catch (Exception e) {
createErrorLog(e, "src/main/resources/log.txt"); createErrorLog(e, "src/main/resources/log.txt");
} }
return competitors;
} }
} }