Skip to content

Commit c047136

Browse files
committed
fixing splitting of classes
fixing scaling of output
1 parent 6983a46 commit c047136

File tree

8 files changed

+96
-46
lines changed

8 files changed

+96
-46
lines changed

src/main/java/de/idrinth/endlessspace2/modvalidator/App.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ public class App extends Application {
1313
private static Stage stage;
1414
@Override
1515
public void start(Stage stage) throws IOException {
16-
scene = new Scene(loadFXML("initial"), 640, 480);
16+
stage.setTitle("Endless Space 2 Mod Validator");
17+
scene = new Scene(loadFXML("initial"));
1718
stage.setScene(scene);
1819
stage.show();
1920
App.stage = stage;
2021
}
2122
public static void toPrimary() throws IOException {
22-
scene = new Scene(loadFXML("primary"), 640, 480);
23+
scene = new Scene(loadFXML("primary"));
2324
stage.setScene(scene);
2425
stage.show();
2526
}

src/main/java/de/idrinth/endlessspace2/modvalidator/Data.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Data {
66
private static XMLIterator iterator;
77
private static SimulationDescriptors rootList;
88
private static File workshopDir;
9+
private static File gameDir;
910

1011
public static void setIterator(XMLIterator iterator) {
1112
Data.iterator = iterator;
@@ -18,6 +19,9 @@ public static void setRootList(SimulationDescriptors rootList) {
1819
public static void setWorkshopDir(File workshopDir) {
1920
Data.workshopDir = workshopDir;
2021
}
22+
public static void setGameDir(File gameDir) {
23+
Data.gameDir = gameDir;
24+
}
2125

2226
public static XMLIterator iterator() {
2327
return iterator;
@@ -28,4 +32,7 @@ public static SimulationDescriptors rootList() {
2832
public static File workshopDir() {
2933
return workshopDir;
3034
}
35+
public static File gameDir() {
36+
return gameDir;
37+
}
3138
}

src/main/java/de/idrinth/endlessspace2/modvalidator/InitialController.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import javafx.application.Platform;
56
import javafx.fxml.FXML;
6-
import javafx.scene.control.TextArea;
77
import javafx.scene.control.TextField;
88

9-
public class InitialController {
10-
@FXML
11-
private TextArea output;
9+
public class InitialController extends ThreaddedController {
1210
@FXML
1311
private TextField endlessSpaceFolder;
1412
@FXML
15-
private void start() throws IOException {
13+
private void start() {
14+
execute();
15+
}
16+
17+
@Override
18+
public void run() {
1619
var logger = new TextOutputLogger(endlessSpaceFolder.getText(), output);
20+
logger.info("checking requirements");
1721
if (null == endlessSpaceFolder.getText() || endlessSpaceFolder.getText().isEmpty()) {
1822
logger.info("You need to provide the folder of endless space 2.");
1923
return;
@@ -30,11 +34,27 @@ private void start() throws IOException {
3034
logger.info("Can't find Schema folder at the place you pointed to.");
3135
return;
3236
}
37+
logger.info("reading in game dir");
3338
iterator.run(simFolder, logger, list);
3439
logger.info("done");
3540
Data.setIterator(new XMLIterator(schemaFolder.getParentFile()));
3641
Data.setRootList(list);
42+
Data.setGameDir(new File(endlessSpaceFolder.getText()+"/Public"));
3743
Data.setWorkshopDir(new File(endlessSpaceFolder.getText()+"/../../workshop/content/392110"));
38-
App.toPrimary();
44+
Platform.runLater(new SwitchToPrimary(logger));
45+
}
46+
private class SwitchToPrimary implements Runnable {
47+
private final TextOutputLogger logger;
48+
49+
public SwitchToPrimary(TextOutputLogger logger) {
50+
this.logger = logger;
51+
}
52+
public void run() {
53+
try {
54+
App.toPrimary();
55+
} catch (IOException ex) {
56+
logger.error(Data.gameDir(), ex);
57+
}
58+
}
3959
}
4060
}

src/main/java/de/idrinth/endlessspace2/modvalidator/PrimaryController.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.net.URL;
88
import java.util.ArrayList;
99
import java.util.Arrays;
10-
import java.util.HashMap;
1110
import java.util.HashSet;
1211
import java.util.Objects;
1312
import java.util.ResourceBundle;
@@ -18,29 +17,14 @@
1817
import javafx.scene.control.TextArea;
1918
import javafx.util.StringConverter;
2019

21-
public class PrimaryController implements Initializable {
22-
23-
@FXML
24-
private TextArea output;
20+
public class PrimaryController extends ThreaddedController implements Initializable {
2521
@FXML
2622
private ChoiceBox<File> modfolder;
2723
private XMLIterator iterator;
2824
private SimulationDescriptors rootList;
2925
@FXML
3026
private void validate() {
31-
var logger = new TextOutputLogger(modfolder.getValue(), output);
32-
if (null == modfolder.getValue()) {
33-
logger.info("You need to choose a mod to check.");
34-
return;
35-
}
36-
logger.info("xsd validation");
37-
var list = rootList.clone();
38-
iterator.run(modfolder.getValue(), logger, list);
39-
logger.info("logic validation");
40-
list.values().forEach((sd) -> {
41-
sd.check(logger, list);
42-
});
43-
logger.info("done");
27+
execute();
4428
}
4529

4630
@Override
@@ -56,11 +40,29 @@ public void initialize(URL url, ResourceBundle rb) {
5640
if (workshop.isDirectory()) {
5741
files.addAll(Arrays.asList(workshop.listFiles(new FolderFilter())));
5842
}
43+
files.add(Data.gameDir());
5944
modfolder.setConverter(new FileConverter());
6045
modfolder.setItems(files);
6146
}
47+
48+
@Override
49+
public void run() {
50+
var logger = new TextOutputLogger(modfolder.getValue(), output);
51+
if (null == modfolder.getValue()) {
52+
logger.info("You need to choose a mod to check.");
53+
return;
54+
}
55+
logger.info("xsd validation");
56+
var list = rootList.clone();
57+
iterator.run(modfolder.getValue(), logger, list);
58+
logger.info("logic validation");
59+
list.values().forEach((sd) -> {
60+
sd.check(logger, list);
61+
});
62+
logger.info("done");
63+
}
6264
private class FileConverter extends StringConverter<File> {
63-
private HashSet<Identifier> ids = new HashSet<>();
65+
private final HashSet<Identifier> ids = new HashSet<>();
6466
@Override
6567
public String toString(File file) {
6668
for (var id : ids) {
@@ -97,10 +99,16 @@ public Identifier(File file) throws IOException {
9799
full = file.getCanonicalPath();
98100
if (full.contains("workshop")) {
99101
path = "workshop://"+full.substring(full.lastIndexOf("workshop")+24);
100-
} else {
102+
name = file.listFiles(new XMLNotRegistry())[0].getName().replace(".xml", "");
103+
} else if(full.contains("Community")) {
101104
path = "local://"+full.substring(full.lastIndexOf("Community")+10);
105+
name = file.listFiles(new XMLNotRegistry())[0].getName().replace(".xml", "");
106+
} else if(full.endsWith("Public")) {
107+
path = "game://Endless Space 2";
108+
name = "Base";
109+
} else {
110+
throw new IOException(full+" can't be recognised as a folder");
102111
}
103-
name = file.listFiles(new XMLNotRegistry())[0].getName().replace(".xml", "");
104112
this.file = file;
105113
}
106114
public String id() {

src/main/java/de/idrinth/endlessspace2/modvalidator/SimpleXMLIterator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ public void startElement(String namespaceURI, String localName, String qName, At
133133
}
134134
path = path.replaceAll("!", "");
135135
while (path.contains(",")) {
136-
var path2 = path.substring(path.indexOf(",")+1).trim();
136+
var position = path.lastIndexOf(",");
137+
var path2 = path.substring(position+1).trim();
137138
sd.addReference(path2, atts.getValue("TargetProperty"));
138-
path = path.substring(0, path.lastIndexOf(","));
139+
path = path.substring(0, position);
139140
}
140141
sd.addReference(path, atts.getValue("TargetProperty"));
141142
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package de.idrinth.endlessspace2.modvalidator;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
import javafx.fxml.FXML;
6+
import javafx.scene.control.TextArea;
7+
8+
public abstract class ThreaddedController implements Runnable {
9+
@FXML
10+
protected TextArea output;
11+
private final ExecutorService te = Executors.newSingleThreadExecutor();
12+
protected final void execute() {
13+
te.submit(this);
14+
}
15+
}

src/main/resources/de/idrinth/endlessspace2/modvalidator/initial.fxml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
<?import javafx.geometry.Insets?>
1111
<?import javafx.scene.layout.AnchorPane?>
1212

13-
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.idrinth.endlessspace2.modvalidator.InitialController">
13+
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.idrinth.endlessspace2.modvalidator.InitialController">
1414
<children>
15-
<HBox alignment="CENTER">
15+
<VBox spacing="10.0" AnchorPane.topAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
1616
<children>
17-
<Label text="Endless Space 2 Folder:"/>
18-
<TextField fx:id="endlessSpaceFolder"/>
19-
<Button text="Start" onAction="#start"/>
17+
<HBox spacing="20.0" AnchorPane.topAnchor="0.0">
18+
<children>
19+
<Label text="Endless Space 2 Folder:"/>
20+
<TextField fx:id="endlessSpaceFolder"/>
21+
<Button text="Start" onAction="#start"/>
22+
</children>
23+
</HBox>
24+
<TextArea VBox.vgrow="ALWAYS" AnchorPane.bottomAnchor="0.0" maxHeight="Infinity" maxWidth="Infinity" editable="false" fx:id="output"/>
2025
</children>
21-
</HBox>
22-
<VBox alignment="CENTER" spacing="20.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="20.0">
23-
<Label text="Output:" />
24-
<TextArea maxHeight="Infinity" editable="false" fx:id="output"/>
2526
</VBox>
2627
</children>
2728
</AnchorPane>

src/main/resources/de/idrinth/endlessspace2/modvalidator/primary.fxml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212

1313
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.idrinth.endlessspace2.modvalidator.PrimaryController">
1414
<children>
15-
<VBox alignment="CENTER" spacing="20.0">
15+
<VBox spacing="10.0" AnchorPane.topAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
1616
<children>
17-
<HBox alignment="CENTER">
17+
<HBox alignment="CENTER" spacing="20.0">
1818
<children>
1919
<Button text="Validate" onAction="#validate"/>
2020
<Label text="Modfolder" />
2121
<ChoiceBox fx:id="modfolder"/>
2222
<Label text="against game folder Schema." />
2323
</children>
2424
</HBox>
25-
<VBox alignment="CENTER" spacing="20.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="20.0">
26-
<Label text="Output:" />
27-
<TextArea maxHeight="Infinity" editable="false" fx:id="output"/>
28-
</VBox>
25+
<TextArea VBox.vgrow="ALWAYS" HBox.hgrow="ALWAYS" maxHeight="Infinity" maxWidth="Infinity" editable="false" fx:id="output"/>
2926
</children>
3027
</VBox>
3128
</children>

0 commit comments

Comments
 (0)