Refactoring XI

This commit is contained in:
Robert Vokac 2024-08-16 19:52:13 +02:00
parent 9ec104f518
commit 438fbfaeeb
No known key found for this signature in database
GPG Key ID: C459E1E4B4A986BB
7 changed files with 119 additions and 15 deletions

View File

@ -24,5 +24,5 @@ package com.openeggbert.core.fbox.api;
* @author robertvokac
*/
public interface FBoxUtilsInterface {
XmlElement parseXml(String xmlString);
}

View File

@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
// <https://www.gnu.org/licenses/> or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.fbox.api;
/**
*
* @author robertvokac
*/
public interface XmlElement {
XmlElement getChildByName(String name);
String get(String elementName);
int getChildCount();
XmlElement getChild(int i);
String getText();
}

View File

@ -0,0 +1,62 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
// <https://www.gnu.org/licenses/> or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.fbox.impl.libgdx;
import com.badlogic.gdx.utils.XmlReader;
import com.openeggbert.core.fbox.api.XmlElement;
/**
*
* @author robertvokac
*/
public class ElementLibGDXImpl implements XmlElement {
private final XmlReader.Element element;
public ElementLibGDXImpl(com.badlogic.gdx.utils.XmlReader.Element element) {
this.element = element;
}
@Override
public XmlElement getChildByName(String name) {
XmlReader.Element child = element.getChildByName(name);
return child == null ? null : new ElementLibGDXImpl(child);
}
@Override
public String get(String elementName) {
return element.get(elementName);
}
@Override
public int getChildCount() {
return element.getChildCount();
}
@Override
public XmlElement getChild(int i) {
XmlReader.Element child = element.getChild(i);
return child == null ? null : new ElementLibGDXImpl(child); }
@Override
public String getText() {
return element.getText();
}
}

View File

@ -19,7 +19,9 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.fbox.impl.libgdx;
import com.badlogic.gdx.utils.XmlReader;
import com.openeggbert.core.fbox.api.FBoxUtilsInterface;
import com.openeggbert.core.fbox.api.XmlElement;
/**
*
@ -27,6 +29,13 @@ import com.openeggbert.core.fbox.api.FBoxUtilsInterface;
*/
public class FBoxUtilsLibGDXImpl implements FBoxUtilsInterface {
@Override
public XmlElement parseXml(String xmlString) {
XmlReader.Element root = new XmlReader().parse(xmlString);
return new ElementLibGDXImpl(root);
}
}

View File

@ -19,8 +19,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.mod;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlReader.Element;
import com.openeggbert.core.fbox.api.XmlElement;
import com.openeggbert.core.fbox.core.FBox;
import com.openeggbert.core.release.Release;
import java.util.ArrayList;
import java.util.List;
@ -34,8 +34,8 @@ import lombok.Data;
public class Mod {
public Mod(String xml) {
Element root = new XmlReader().parse(xml);
Element parentElement = root.getChildByName("parent");
XmlElement root = FBox.get().utils().parseXml(xml);
XmlElement parentElement = root.getChildByName("parent");
if (parentElement != null) {
parent = new ModIdentification(parentElement);
}
@ -48,25 +48,25 @@ public class Mod {
featureLevel = Release.valueOf(root.get("featureLevel"));
name = root.get("name");
description = root.get("description");
Element imports = root.getChildByName("imports");
XmlElement imports = root.getChildByName("imports");
if (imports != null) {
for (int i = 0; i < imports.getChildCount(); i++) {
Element import_ = imports.getChild(i);
XmlElement import_ = imports.getChild(i);
importedMods.add(new ModIdentification(import_));
}
}
Element files_ = root.getChildByName("files");
XmlElement files_ = root.getChildByName("files");
if (files_ != null) {
for (int i = 0; i < files_.getChildCount(); i++) {
Element file = files_.getChild(i);
XmlElement file = files_.getChild(i);
files.add(file.getText());
}
}
Element stores_ = root.getChildByName("stores");
XmlElement stores_ = root.getChildByName("stores");
if (stores_ != null) {
for (int i = 0; i < stores_.getChildCount(); i++) {
Element store = stores_.getChild(i);
XmlElement store = stores_.getChild(i);
stores.add(new Store(store));
}
}

View File

@ -19,7 +19,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.mod;
import com.badlogic.gdx.utils.XmlReader.Element;
import com.openeggbert.core.fbox.api.XmlElement;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -35,7 +35,7 @@ public class ModIdentification {
private final String modId;
private final String version;
public ModIdentification(Element element) {
public ModIdentification(XmlElement element) {
groupId = element.get("groupId");
modId = element.get("modId");
version = element.get("version");

View File

@ -19,7 +19,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.mod;
import com.badlogic.gdx.utils.XmlReader;
import com.openeggbert.core.fbox.api.XmlElement;
/**
*
@ -31,7 +31,7 @@ public class Store {
String name;
String url;
Store(XmlReader.Element store) {
Store(XmlElement store) {
id = store.get("id");
name = store.get("name");
url = store.get("url");