Skip to content

Commit cfc1ee8

Browse files
Added the ability to process coordinates before drawing. This will make as little requests to the api as possible to not overload the API or your computer
1 parent 88e46f5 commit cfc1ee8

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

src/main/java/com/codingpupper3033/codebtekml/gui/screens/GuiDrawKML.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codingpupper3033.codebtekml.gui.widgets.BlockPreview;
66
import com.codingpupper3033.codebtekml.helpers.block.BlockNameConverter;
77
import com.codingpupper3033.codebtekml.helpers.kmlfile.KMLParser;
8+
import com.codingpupper3033.codebtekml.helpers.map.Placemark;
89
import com.codingpupper3033.codebtekml.helpers.map.altitude.AltitudeProcessor;
910
import com.codingpupper3033.codebtekml.helpers.map.placemark.PlacemarkFactory;
1011
import net.minecraft.client.gui.GuiButton;
@@ -266,25 +267,29 @@ protected void actionPerformed(GuiButton button) throws IOException {
266267
* Using the values from the text boxes, try parsing and building the file.
267268
*/
268269
public void build() {
269-
Document[] documents;
270-
try {
271-
documents = KMLParser.parse(new File(fileNameTextBox.getText())); // TODO Add loading/parsing text (maybe below build button) to the screen to signify it is doing stuff even if it looks frozen
272-
} catch (IOException e) {
273-
errorFileText = ERROR_FINDING_FILE_TEXT;
274-
return;
275-
} catch (ParserConfigurationException e) {
276-
errorFileText = ERROR_READING_FILE_TEXT;
277-
return;
278-
} catch (SAXException e) {
279-
errorFileText = ERROR_READING_FILE_TEXT;
280-
return;
281-
}
270+
new Thread(() -> { // New thread as to allow for loading screen TODO Make loading screen
271+
Document[] documents;
272+
273+
try {
274+
documents = KMLParser.parse(new File(fileNameTextBox.getText())); // TODO Add loading/parsing text (maybe below build button) to the screen to signify it is doing stuff even if it looks frozen
275+
} catch (IOException e) {
276+
errorFileText = ERROR_FINDING_FILE_TEXT;
277+
return;
278+
} catch (ParserConfigurationException e) {
279+
errorFileText = ERROR_READING_FILE_TEXT;
280+
return;
281+
} catch (SAXException e) {
282+
errorFileText = ERROR_READING_FILE_TEXT;
283+
return;
284+
}
285+
286+
Placemark[] placemarks = PlacemarkFactory.getPlacemarks(documents);
282287

283-
close(); // Should have successfully processed the file, gui is not needed now
288+
// Process Altitudes
289+
PlacemarkFactory.proccessPlacemarks(placemarks);
284290

285-
// Draw! (new thread, so you can see it doing its thing)
286-
new Thread(() -> {
287-
PlacemarkFactory.drawPlacemarks(documents, blockNameTextBox.getText());
291+
close(); // Should have successfully processed the file, gui is not needed now
292+
PlacemarkFactory.drawPlacemarks(placemarks, blockNameTextBox.getText()); // Draw!
288293
}).start();
289294
}
290295

src/main/java/com/codingpupper3033/codebtekml/helpers/map/altitude/AltitudeProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.codingpupper3033.codebtekml.helpers.map.Coordinate;
44

55
import java.io.IOException;
6+
import java.util.Arrays;
67
import java.util.LinkedList;
78
import java.util.Queue;
89

@@ -58,6 +59,10 @@ public void addCoordinateToProcessQueue(Coordinate coordinate) {
5859
coordinateProcessorQueue.add(coordinate);
5960
}
6061

62+
public void addCoordinatesToProcessQueue(Coordinate[] coordinates) {
63+
coordinateProcessorQueue.addAll(Arrays.asList(coordinates));
64+
}
65+
6166
public Queue<Coordinate> getCoordinateProcessorQueue() {
6267
return coordinateProcessorQueue;
6368
}

src/main/java/com/codingpupper3033/codebtekml/helpers/map/placemark/PlacemarkFactory.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingpupper3033.codebtekml.helpers.kmlfile.KMLParser;
44
import com.codingpupper3033.codebtekml.helpers.map.Placemark;
5+
import com.codingpupper3033.codebtekml.helpers.map.altitude.AltitudeProcessor;
56
import org.w3c.dom.Document;
67
import org.w3c.dom.Element;
78
import org.w3c.dom.Node;
@@ -89,15 +90,24 @@ public static Placemark[] getPlacemarks(File f) throws ParserConfigurationExcept
8990
return getPlacemarks(KMLParser.parse(f));
9091
}
9192

93+
/**
94+
* Draws all placemarks from the array
95+
* @param placemarks Placemarks to draw
96+
* @param blockName block name to draw with
97+
*/
98+
public static void drawPlacemarks(Placemark[] placemarks, String blockName) {
99+
for (Placemark placemark : placemarks) {
100+
placemark.draw(blockName);
101+
}
102+
}
103+
92104
/**
93105
* Draw all placemarks in the document with specified block name
94106
* @param documents documents to draw
95107
* @param blockName block name to draw with
96108
*/
97109
public static void drawPlacemarks(Document[] documents, String blockName) {
98-
for (Placemark placemark : getPlacemarks(documents)) {
99-
placemark.draw(blockName);
100-
}
110+
drawPlacemarks(getPlacemarks(documents), blockName);
101111
}
102112

103113
/**
@@ -111,4 +121,11 @@ public static void drawPlacemarks(Document[] documents, String blockName) {
111121
public static void drawPlacemarks(File f, String blockName) throws ParserConfigurationException, IOException, SAXException {
112122
drawPlacemarks(KMLParser.parse(f), blockName);
113123
}
124+
125+
public static void proccessPlacemarks(Placemark[] placemarks) {
126+
for (Placemark placemark: placemarks) {
127+
AltitudeProcessor.defaultProcessor.addCoordinatesToProcessQueue(placemark.getCoordinates());
128+
}
129+
AltitudeProcessor.defaultProcessor.processCoordinateQueue();
130+
}
114131
}

0 commit comments

Comments
 (0)