Search in sources :

Example 6 with XmlReader

use of com.badlogic.gdx.utils.XmlReader in project talos by rockbite.

the class UIKit method create.

@Override
public void create() {
    super.create();
    TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("skin/uiskin.atlas"));
    skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
    skin.addRegions(atlas);
    table = new Table();
    AbstractShaderNode shaderNode = new AbstractShaderNode() {

        @Override
        public void prepareDeclarations(ShaderBuilder shaderBuilder) {
        }

        @Override
        public String writeOutputCode(String slotId) {
            return null;
        }
    };
    shaderNode.init(skin, null);
    XmlReader reader = new XmlReader();
    XmlReader.Element root = reader.parse(Gdx.files.internal("addons/shader/nodes.xml"));
    shaderNode.constructNode(root.getChild(0).getChild(0));
    table.add(shaderNode);
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    table.setFillParent(true);
    stage.addActor(table);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ShaderBuilder(com.talosvfx.talos.runtime.shaders.ShaderBuilder) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) XmlReader(com.badlogic.gdx.utils.XmlReader) AbstractShaderNode(com.talosvfx.talos.editor.addons.shader.nodes.AbstractShaderNode)

Example 7 with XmlReader

use of com.badlogic.gdx.utils.XmlReader in project talos by rockbite.

the class ExternalShaderNode method addUniformInput.

private void addUniformInput(String uniformName, String method, String[] args) {
    String xml = "<value port=\"input\" name=\"" + uniformName + "\" type=\"float\">" + uniformName + "</value>";
    XmlReader reader = new XmlReader();
    XmlReader.Element elem = reader.parse(xml);
    addRow(elem, 0, 0, false, customContainer, true);
    String moduleName = "FloatUniform";
    // todo: check this cast
    ShaderNodeStage nodeStage = (ShaderNodeStage) TalosMain.Instance().getNodeStage();
    NodeWidget node = nodeStage.createNode(moduleName, this.getX() - 200, this.getY());
    UniformNode uniformNode = (UniformNode) node;
    node.constructNode(nodeStage.getNodeListPopup().getModuleByName(moduleName));
    Notifications.fireEvent(Notifications.obtainEvent(NodeCreatedEvent.class).set(node));
    nodeStage.getNodeBoard().makeConnection(node, this, "out", uniformName);
    ((UniformNode) node).setValue(0.5f);
    uniformNode.setUniformName(uniformName);
}
Also used : ShaderNodeStage(com.talosvfx.talos.editor.addons.shader.workspace.ShaderNodeStage) NodeWidget(com.talosvfx.talos.editor.nodes.NodeWidget) XmlReader(com.badlogic.gdx.utils.XmlReader)

Example 8 with XmlReader

use of com.badlogic.gdx.utils.XmlReader in project TooCruelPixelDungeon by juh9870.

the class ShatteredNews method checkForArticles.

@Override
public void checkForArticles(boolean useMetered, boolean preferHTTPS, NewsResultCallback callback) {
    if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()) {
        callback.onConnectionFailed();
        return;
    }
    Net.HttpRequest httpGet = new Net.HttpRequest(Net.HttpMethods.GET);
    if (preferHTTPS) {
        httpGet.setUrl("https://shatteredpixel.com/feed_by_tag/SHPD_INGAME.xml");
    } else {
        httpGet.setUrl("http://shatteredpixel.com/feed_by_tag/SHPD_INGAME.xml");
    }
    Gdx.net.sendHttpRequest(httpGet, new Net.HttpResponseListener() {

        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            ArrayList<NewsArticle> articles = new ArrayList<>();
            XmlReader reader = new XmlReader();
            XmlReader.Element xmlDoc = reader.parse(httpResponse.getResultAsStream());
            SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
            for (XmlReader.Element xmlArticle : xmlDoc.getChildrenByName("entry")) {
                NewsArticle article = new NewsArticle();
                article.title = xmlArticle.get("title");
                try {
                    article.date = dateParser.parse(xmlArticle.get("published"));
                } catch (ParseException e) {
                    Game.reportException(e);
                }
                article.summary = xmlArticle.get("summary");
                article.URL = xmlArticle.getChildByName("link").getAttribute("href");
                if (!preferHTTPS) {
                    article.URL = article.URL.replace("https://", "http://");
                }
                Pattern versionCodeMatcher = Pattern.compile("v[0-9]+");
                try {
                    Array<XmlReader.Element> properties = xmlArticle.getChildrenByName("category");
                    for (XmlReader.Element prop : properties) {
                        String propVal = prop.getAttribute("term");
                        if (propVal.startsWith("SHPD_ICON")) {
                            Matcher m = versionCodeMatcher.matcher(propVal);
                            if (m.find()) {
                                int iconGameVer = Integer.parseInt(m.group().substring(1));
                                if (iconGameVer <= Game.versionCode) {
                                    article.icon = propVal.substring(propVal.indexOf(": ") + 2);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    article.icon = null;
                }
                articles.add(article);
            }
            callback.onArticlesFound(articles);
        }

        @Override
        public void failed(Throwable t) {
            callback.onConnectionFailed();
        }

        @Override
        public void cancelled() {
            callback.onConnectionFailed();
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) XmlReader(com.badlogic.gdx.utils.XmlReader) ParseException(java.text.ParseException) Array(com.badlogic.gdx.utils.Array) ParseException(java.text.ParseException) Net(com.badlogic.gdx.Net) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with XmlReader

use of com.badlogic.gdx.utils.XmlReader in project visit-bayanaul by nextgenprog.

the class MainScreen method initLocs.

private void initLocs() {
    XmlReader reader = new XmlReader();
    XmlReader.Element root = reader.parse(Gdx.files.getFileHandle("locations.xml", Files.FileType.Internal));
    for (int i = 0; i < root.getChildCount(); i++) {
        XmlReader.Element child = root.getChild(i);
        if (child.getName().equalsIgnoreCase("location")) {
            try {
                String name = child.getAttribute("name");
                try {
                    String url = child.getAttribute("mapUrl");
                    try {
                        String image = child.getAttribute("image");
                        try {
                            String icon = child.getAttribute("icon");
                            // String icon = "pin";
                            try {
                                String content = child.getAttribute("content");
                                try {
                                    float x = child.getFloatAttribute("x");
                                    try {
                                        float y = child.getFloatAttribute("y");
                                        LocationData locData = new LocationData(name, new Texture(image), new Texture(icon + ".png"), content, new Vector2(x, y), url);
                                        locations.add(locData);
                                    } catch (Exception e) {
                                    }
                                } catch (Exception e) {
                                }
                            } catch (Exception e) {
                            }
                        } catch (Exception e) {
                        }
                    } catch (Exception e) {
                    }
                } catch (Exception e) {
                }
            } catch (Exception e) {
            }
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) XmlReader(com.badlogic.gdx.utils.XmlReader) Texture(com.badlogic.gdx.graphics.Texture)

Example 10 with XmlReader

use of com.badlogic.gdx.utils.XmlReader in project gaiasky by langurmonkey.

the class AttitudeXmlParser method parseFile.

private static AttitudeIntervalBean parseFile(FileHandle fh, Duration duration, Instant activationTime) {
    BaseAttitudeDataServer<?> result = null;
    XmlReader reader = new XmlReader();
    XmlReader.Element element = reader.parse(fh);
    XmlReader.Element model = element.getChildByName("model");
    /**
     * MODEL ELEMENT *
     */
    String name = model.get("name");
    String className = model.get("classname").replace("gaia.cu9.ari.gaiaorbit", "gaiasky");
    long startTimeNsSince2010 = (long) ((AstroUtils.getJulianDate(activationTime) - AstroUtils.JD_J2010) * Nature.D_TO_NS);
    /**
     * SCAN LAW ELEMENT *
     */
    XmlReader.Element scanlaw = model.getChildByName("scanlaw");
    String epochRef = scanlaw.getAttribute("epochref");
    Instant refEpochDate = getDate(epochRef);
    long refEpochJ2010 = (long) ((AstroUtils.getJulianDate(refEpochDate) - AstroUtils.JD_J2010) * Nature.D_TO_NS);
    // Spin phase
    XmlReader.Element spinphase = scanlaw.getChildByName("spinphase");
    Quantity.Angle spinPhase = new Quantity.Angle(getDouble(spinphase, "value"), spinphase.get("unit"));
    // Precession pahse
    XmlReader.Element precessphase = scanlaw.getChildByName("precessphase");
    Quantity.Angle precessionPhase = new Quantity.Angle(getDouble(precessphase, "value"), precessphase.get("unit"));
    // Precession rate - always in rev/yr
    XmlReader.Element precessrate = scanlaw.getChildByName("precessrate");
    Double precessionRate = getDouble(precessrate, "value");
    // Scan rate
    XmlReader.Element scanrate = scanlaw.getChildByName("scanrate");
    Quantity.Angle scanRate = new Quantity.Angle(getDouble(scanrate, "value"), scanrate.get("unit").split("_")[0]);
    // Solar aspect angle
    XmlReader.Element saa = scanlaw.getChildByName("solaraspectangle");
    Quantity.Angle solarAspectAngle = new Quantity.Angle(getDouble(saa, "value"), saa.get("unit"));
    if (className.contains("MslAttitudeDataServer")) {
        // We need to pass the startTime, duration and MSL to the constructor
        ModifiedScanningLaw msl = new ModifiedScanningLaw(startTimeNsSince2010);
        msl.setRefEpoch(refEpochJ2010);
        msl.setRefNu(precessionPhase.get(Quantity.Angle.AngleUnit.RAD));
        msl.setRefOmega(spinPhase.get(Quantity.Angle.AngleUnit.RAD));
        msl.setPrecRate(precessionRate);
        msl.setScanRate(scanRate.get(Quantity.Angle.AngleUnit.ARCSEC));
        msl.setRefXi(solarAspectAngle.get(Quantity.Angle.AngleUnit.RAD));
        msl.setTypicalHighDensityArea();
        msl.initialize();
        MslAttitudeDataServer mslDatServ = new MslAttitudeDataServer(startTimeNsSince2010, duration, msl);
        mslDatServ.initialize();
        result = mslDatServ;
    } else if (className.contains("Epsl")) {
        Epsl.Mode mode = name.equals("EPSL_F") ? Epsl.Mode.FOLLOWING : Epsl.Mode.PRECEDING;
        Epsl epsl = new Epsl(mode);
        epsl.setRefTime((long) refEpochJ2010);
        epsl.setNuRef(precessionPhase.get(Quantity.Angle.AngleUnit.RAD));
        epsl.setOmegaRef(spinPhase.get(Quantity.Angle.AngleUnit.RAD));
        epsl.setXiRef(solarAspectAngle.get(Quantity.Angle.AngleUnit.RAD));
        epsl.setTargetScanRate(scanRate.get(Quantity.Angle.AngleUnit.ARCSEC));
        epsl.setTargetPrecessionRate(precessionRate);
        result = epsl;
    }
    return new AttitudeIntervalBean(name, new Date(activationTime.toEpochMilli()), result, fh.name());
}
Also used : Instant(java.time.Instant) Quantity(gaiasky.util.units.Quantity) XmlReader(com.badlogic.gdx.utils.XmlReader)

Aggregations

XmlReader (com.badlogic.gdx.utils.XmlReader)10 FileHandle (com.badlogic.gdx.files.FileHandle)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 Net (com.badlogic.gdx.Net)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Vector2 (com.badlogic.gdx.math.Vector2)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 Array (com.badlogic.gdx.utils.Array)1 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)1 ColorPicker (com.kotcrab.vis.ui.widget.color.ColorPicker)1 AbstractShaderNode (com.talosvfx.talos.editor.addons.shader.nodes.AbstractShaderNode)1 ShaderNodeStage (com.talosvfx.talos.editor.addons.shader.workspace.ShaderNodeStage)1 BatchConvertDialog (com.talosvfx.talos.editor.dialogs.BatchConvertDialog)1 NewProjectDialog (com.talosvfx.talos.editor.dialogs.NewProjectDialog)1 SettingsDialog (com.talosvfx.talos.editor.dialogs.SettingsDialog)1 NodeWidget (com.talosvfx.talos.editor.nodes.NodeWidget)1