Skip to content

Commit 9f21593

Browse files
committed
Adding a bunch of reading/writing methods for customisation of planetary events
1 parent 2adef23 commit 9f21593

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

MekHQ/src/mekhq/campaign/universe/Planet.java

+1
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ public String toString() {
906906
}
907907

908908
/** A class representing some event, possibly changing planetary information */
909+
@XmlRootElement(name="event")
909910
public static final class PlanetaryEvent {
910911
@XmlJavaTypeAdapter(DateAdapter.class)
911912
public DateTime date;

MekHQ/src/mekhq/campaign/universe/Planets.java

+50
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.io.OutputStream;
8+
import java.io.Writer;
89
import java.text.ParseException;
910
import java.util.ArrayList;
1011
import java.util.Collection;
@@ -30,6 +31,7 @@
3031

3132
import org.joda.time.DateTime;
3233
import org.w3c.dom.DOMException;
34+
import org.w3c.dom.Node;
3335

3436
import mekhq.FileParser;
3537
import mekhq.MekHQ;
@@ -73,6 +75,20 @@ public void run() {
7375
}
7476
return planets;
7577
}
78+
79+
public static void reload(boolean waitForFinish) {
80+
planets = null;
81+
getInstance();
82+
if(waitForFinish) {
83+
try {
84+
while(!planets.isInitialized()) {
85+
Thread.sleep(10);
86+
}
87+
} catch(InterruptedException iex) {
88+
MekHQ.logError(iex);
89+
}
90+
}
91+
}
7692

7793
private ConcurrentMap<String, Planet> planetList = new ConcurrentHashMap<>();
7894
/* organizes systems into a grid of 30lyx30ly squares so we can find
@@ -200,6 +216,40 @@ public void writePlanet(OutputStream out, Planet planet) {
200216
}
201217
}
202218

219+
public void writePlanet(Writer out, Planet planet) {
220+
try {
221+
marshaller.marshal(planet, out);
222+
} catch (Exception e) {
223+
MekHQ.logError(e);
224+
}
225+
}
226+
227+
228+
public void writePlanetaryEvent(OutputStream out, Planet.PlanetaryEvent event) {
229+
try {
230+
marshaller.marshal(event, out);
231+
} catch (Exception e) {
232+
MekHQ.logError(e);
233+
}
234+
}
235+
236+
public void writePlanetaryEvent(Writer out, Planet.PlanetaryEvent event) {
237+
try {
238+
marshaller.marshal(event, out);
239+
} catch (Exception e) {
240+
MekHQ.logError(e);
241+
}
242+
}
243+
244+
public Planet.PlanetaryEvent readPlanetaryEvent(Node node) {
245+
try {
246+
return (Planet.PlanetaryEvent) unmarshaller.unmarshal(node);
247+
} catch (JAXBException e) {
248+
MekHQ.logError(e);
249+
}
250+
return null;
251+
}
252+
203253
public void writePlanets(OutputStream out, List<Planet> planets) {
204254
LocalPlanetList temp = new LocalPlanetList();
205255
temp.list = planets;

0 commit comments

Comments
 (0)