use of gaiasky.scenegraph.Constellation in project gaiasky by langurmonkey.
the class ConstellationsLoader method loadData.
@Override
public Array<? extends SceneGraphNode> loadData() {
Array<SceneGraphNode> constellations = new Array<>();
for (String f : files) {
try {
// Add fade node
FadeNode constellationsFadeNode = new FadeNode();
constellationsFadeNode.setPosition(new double[] { 0, 0, 0 });
constellationsFadeNode.setCt(new String[] { "Constellations" });
constellationsFadeNode.setFadeout(new double[] { 1.0e2, 2.0e4 });
constellationsFadeNode.setParent(SceneGraphNode.ROOT_NAME);
constellationsFadeNode.setName("Constellations");
constellations.add(constellationsFadeNode);
// load constellations
FileHandle file = Settings.settings.data.dataFileHandle(f);
BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
try {
// Skip first line
String lastName = "";
Array<int[]> partial = null;
int lastid = -1;
String line;
String name = null;
ComponentTypes ct = new ComponentTypes(ComponentType.Constellations);
while ((line = br.readLine()) != null) {
if (!line.startsWith("#")) {
String[] tokens = line.split(separator);
name = tokens[0].trim();
if (!lastName.isEmpty() && !name.equals("JUMP") && !name.equals(lastName)) {
// We finished a constellation object
Constellation cons = new Constellation(lastName, "Constellations");
cons.ct = ct;
cons.ids = partial;
constellations.add(cons);
partial = null;
lastid = -1;
}
if (partial == null) {
partial = new Array<>();
}
// Break point sequence
if (name.equals("JUMP") && tokens[1].trim().equals("JUMP")) {
lastid = -1;
} else {
int newid = Parser.parseInt(tokens[1].trim());
if (lastid > 0) {
partial.add(new int[] { lastid, newid });
}
lastid = newid;
lastName = name;
}
}
}
// Add last
if (!lastName.isEmpty() && !name.equals("JUMP")) {
// We finished a constellation object
Constellation cons = new Constellation(lastName, "Constellations");
cons.ct = ct;
cons.ids = partial;
constellations.add(cons);
}
} catch (IOException e) {
Logger.getLogger(this.getClass()).error(e);
}
} catch (Exception e) {
Logger.getLogger(this.getClass()).error(e);
}
}
Logger.getLogger(this.getClass()).info(I18n.txt("notif.constellations.init", constellations.size));
return constellations;
}
Aggregations