Skip to content

Commit 7f8b709

Browse files
committed
simple checks for existance of properties in SimulationDescriptors
1 parent 0131692 commit 7f8b709

File tree

214 files changed

+596
-34997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+596
-34997
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
import javafx.scene.Parent;
66
import javafx.scene.Scene;
77
import javafx.stage.Stage;
8-
98
import java.io.IOException;
109

1110
public class App extends Application {
1211

1312
private static Scene scene;
14-
13+
private static Stage stage;
1514
@Override
1615
public void start(Stage stage) throws IOException {
17-
scene = new Scene(loadFXML("primary"), 640, 480);
16+
scene = new Scene(loadFXML("initial"), 640, 480);
1817
stage.setScene(scene);
1918
stage.show();
19+
App.stage = stage;
2020
}
21-
22-
static void setRoot(String fxml) throws IOException {
23-
scene.setRoot(loadFXML(fxml));
21+
public static void toPrimary() throws IOException {
22+
scene = new Scene(loadFXML("primary"), 640, 480);
23+
stage.setScene(scene);
24+
stage.show();
2425
}
2526

2627
private static Parent loadFXML(String fxml) throws IOException {
@@ -31,5 +32,4 @@ private static Parent loadFXML(String fxml) throws IOException {
3132
public static void main(String[] args) {
3233
launch();
3334
}
34-
3535
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package de.idrinth.endlessspace2.modvalidator;
2+
3+
import java.io.File;
4+
5+
class Data {
6+
private static XMLIterator iterator;
7+
private static SimulationDescriptors rootList;
8+
private static File workshopDir;
9+
10+
public static void setIterator(XMLIterator iterator) {
11+
Data.iterator = iterator;
12+
}
13+
14+
public static void setRootList(SimulationDescriptors rootList) {
15+
Data.rootList = rootList;
16+
}
17+
18+
public static void setWorkshopDir(File workshopDir) {
19+
Data.workshopDir = workshopDir;
20+
}
21+
22+
public static XMLIterator iterator() {
23+
return iterator;
24+
}
25+
public static SimulationDescriptors rootList() {
26+
return rootList;
27+
}
28+
public static File workshopDir() {
29+
return workshopDir;
30+
}
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.idrinth.endlessspace2.modvalidator;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import javafx.fxml.FXML;
6+
import javafx.scene.control.TextArea;
7+
import javafx.scene.control.TextField;
8+
9+
public class InitialController {
10+
@FXML
11+
private TextArea output;
12+
@FXML
13+
private TextField endlessSpaceFolder;
14+
@FXML
15+
private void start() throws IOException {
16+
var logger = new TextOutputLogger(endlessSpaceFolder.getText(), output);
17+
if (null == endlessSpaceFolder.getText() || endlessSpaceFolder.getText().isEmpty()) {
18+
logger.info("You need to provide the folder of endless space 2.");
19+
return;
20+
}
21+
var list = new SimulationDescriptors();
22+
var iterator = new SimpleXMLIterator();
23+
var simFolder = new File(endlessSpaceFolder.getText()+"/Public/Simulation");
24+
var schemaFolder = new File(endlessSpaceFolder.getText()+"/Public/Schemas/");
25+
if (!simFolder.isDirectory()) {
26+
logger.info("Can't find Simulation folder at the place you pointed to.");
27+
return;
28+
}
29+
if (!schemaFolder.isDirectory()) {
30+
logger.info("Can't find Schema folder at the place you pointed to.");
31+
return;
32+
}
33+
iterator.run(simFolder, logger, list);
34+
logger.info("done");
35+
Data.setIterator(new XMLIterator(schemaFolder.getParentFile()));
36+
Data.setRootList(list);
37+
Data.setWorkshopDir(new File(endlessSpaceFolder.getText()+"/../../workshop/content/392110"));
38+
App.toPrimary();
39+
}
40+
}

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

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,135 @@
22

33
import java.io.File;
44
import java.io.FileFilter;
5+
import java.io.FilenameFilter;
6+
import java.io.IOException;
57
import java.net.URL;
68
import java.util.ArrayList;
79
import java.util.Arrays;
10+
import java.util.HashMap;
11+
import java.util.HashSet;
12+
import java.util.Objects;
813
import java.util.ResourceBundle;
914
import javafx.collections.ObservableListBase;
1015
import javafx.fxml.FXML;
1116
import javafx.fxml.Initializable;
1217
import javafx.scene.control.ChoiceBox;
1318
import javafx.scene.control.TextArea;
19+
import javafx.util.StringConverter;
1420

1521
public class PrimaryController implements Initializable {
1622

1723
@FXML
1824
private TextArea output;
1925
@FXML
2026
private ChoiceBox<File> modfolder;
21-
/*@FXML
22-
private ChoiceBox<String> schema;*/
23-
private final XMLIterator iterator = new XMLIterator();
27+
private XMLIterator iterator;
28+
private SimulationDescriptors rootList;
2429
@FXML
2530
private void validate() {
2631
var logger = new TextOutputLogger(modfolder.getValue(), output);
2732
if (null == modfolder.getValue()) {
28-
logger.info("Need to choose a mod to check.");
33+
logger.info("You need to choose a mod to check.");
2934
return;
3035
}
31-
iterator.run(modfolder.getValue(), logger);
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+
});
3243
logger.info("done");
3344
}
3445

3546
@Override
3647
public void initialize(URL url, ResourceBundle rb) {
48+
iterator = Data.iterator();
49+
rootList = Data.rootList();
3750
var files = new Observed<File>();
3851
var folder = new File(System.getProperty("user.home") + "/Documents/Endless space 2/Community");
39-
System.out.println(folder.getAbsoluteFile());
4052
if (folder.isDirectory()) {
4153
files.addAll(Arrays.asList(folder.listFiles(new FolderFilter())));
4254
}
55+
var workshop = Data.workshopDir();
56+
if (workshop.isDirectory()) {
57+
files.addAll(Arrays.asList(workshop.listFiles(new FolderFilter())));
58+
}
59+
modfolder.setConverter(new FileConverter());
4360
modfolder.setItems(files);
44-
/*var schemata = new Observed<String>();
45-
schemata.add("@internal");
46-
schema.setItems(schemata);*/
61+
}
62+
private class FileConverter extends StringConverter<File> {
63+
private HashSet<Identifier> ids = new HashSet<>();
64+
@Override
65+
public String toString(File file) {
66+
for (var id : ids) {
67+
if (id.file == file) {
68+
return id.path;
69+
}
70+
}
71+
try {
72+
var id = new Identifier(file);
73+
ids.add(id);
74+
return id.id();
75+
} catch (IOException ex) {
76+
ex.printStackTrace();
77+
}
78+
return "";
79+
}
80+
81+
@Override
82+
public File fromString(String ident) {
83+
for (var id : ids) {
84+
if (id.id().equals(ident)) {
85+
return id.file;
86+
}
87+
}
88+
return null;
89+
}
90+
private class Identifier {
91+
private final String path;
92+
private final String full;
93+
private final String name;
94+
private final File file;
95+
96+
public Identifier(File file) throws IOException {
97+
full = file.getCanonicalPath();
98+
if (full.contains("workshop")) {
99+
path = "workshop://"+full.substring(full.lastIndexOf("workshop")+24);
100+
} else {
101+
path = "local://"+full.substring(full.lastIndexOf("Community")+10);
102+
}
103+
name = file.listFiles(new XMLNotRegistry())[0].getName().replace(".xml", "");
104+
this.file = file;
105+
}
106+
public String id() {
107+
return String.format("%s%s%s", path, "@", name);
108+
}
109+
110+
@Override
111+
public int hashCode() {
112+
return 41 * 7 + Objects.hashCode(this.full);
113+
}
114+
115+
@Override
116+
public boolean equals(Object obj) {
117+
if (this == obj) {
118+
return true;
119+
}
120+
if (obj == null || getClass() != obj.getClass()) {
121+
return false;
122+
}
123+
final Identifier other = (Identifier) obj;
124+
return Objects.equals(this.full, other.full);
125+
}
126+
}
127+
}
128+
class XMLNotRegistry implements FilenameFilter {
129+
130+
@Override
131+
public boolean accept(File dir, String name) {
132+
return name.endsWith(".xml") && !name.equalsIgnoreCase("Registry.xml");
133+
}
47134
}
48135
private class FolderFilter implements FileFilter {
49136

0 commit comments

Comments
 (0)