From 1ba527c9968a2fa8ec022a64ac2dcce6574ee8dd Mon Sep 17 00:00:00 2001 From: Thomas Creutzenberg Date: Sun, 3 Nov 2024 22:45:40 +0100 Subject: [PATCH] XmlReader.getChildren() + XmlReader.replaceChild() (#7499) * XmlReader.replaceChild * Update XmlReader.rl * Apply formatter --------- Co-authored-by: GitHub Action --- CHANGES | 1 + gdx/res/com/badlogic/gdx/utils/XmlReader.rl | 11 +++++++++++ gdx/src/com/badlogic/gdx/utils/XmlReader.java | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGES b/CHANGES index 6ccb7c38b65..428dadeffc9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ [1.13.1] - iOS: Update to MobiVM 2.3.22 - Change visibility of PolygonSpriteBatch.switchTexture() to protected +- Added XmlReader.getChildren() and XmlReader.replaceChild() [1.13.0] - [BREAKING CHANGE] GWT: Updated to 2.11.0. `com.google.jsinterop:jsinterop-annotations:2.0.2:sources` must be added as a dependency to your html project dependencies. diff --git a/gdx/res/com/badlogic/gdx/utils/XmlReader.rl b/gdx/res/com/badlogic/gdx/utils/XmlReader.rl index eb1837d69fd..4568f740ef8 100644 --- a/gdx/res/com/badlogic/gdx/utils/XmlReader.rl +++ b/gdx/res/com/badlogic/gdx/utils/XmlReader.rl @@ -294,6 +294,10 @@ public class XmlReader { if (children == null) return 0; return children.size; } + + public Array getChildren () { + return children; + } /** @throws GdxRuntimeException if the element has no children. */ public Element getChild (int index) { @@ -325,6 +329,13 @@ public class XmlReader { public void remove () { parent.removeChild(this); } + + public void replaceChild (Element child, Element replacement) { + if (children == null) throw new GdxRuntimeException("Element has no children: " + name); + final int index = children.indexOf(child, true); + if (index == -1) throw new GdxRuntimeException("Element does not contain child: " + child); + children.set(index, replacement); + } public Element getParent () { return parent; diff --git a/gdx/src/com/badlogic/gdx/utils/XmlReader.java b/gdx/src/com/badlogic/gdx/utils/XmlReader.java index 3b3ca170d1c..f1c8f3d6628 100644 --- a/gdx/src/com/badlogic/gdx/utils/XmlReader.java +++ b/gdx/src/com/badlogic/gdx/utils/XmlReader.java @@ -507,6 +507,10 @@ public int getChildCount () { return children.size; } + public Array getChildren () { + return children; + } + /** @throws GdxRuntimeException if the element has no children. */ public Element getChild (int index) { if (children == null) throw new GdxRuntimeException("Element has no children: " + name); @@ -538,6 +542,13 @@ public void remove () { parent.removeChild(this); } + public void replaceChild (Element child, Element replacement) { + if (children == null) throw new GdxRuntimeException("Element has no children: " + name); + final int index = children.indexOf(child, true); + if (index == -1) throw new GdxRuntimeException("Element does not contain child: " + child); + children.set(index, replacement); + } + public Element getParent () { return parent; }