Search in sources :

Example 1 with Constellation

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ComponentTypes(gaiasky.render.ComponentTypes) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Constellation(gaiasky.scenegraph.Constellation) BufferedReader(java.io.BufferedReader) FadeNode(gaiasky.scenegraph.FadeNode)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)1 Array (com.badlogic.gdx.utils.Array)1 ComponentTypes (gaiasky.render.ComponentTypes)1 Constellation (gaiasky.scenegraph.Constellation)1 FadeNode (gaiasky.scenegraph.FadeNode)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1