Toyed with the idea of XML help pages
Its a very good idea but a bit harder than i though. I'm going to have to get very creative with what i can pull from the game. Including how i want to handle textures as they need to be loaded in a way both the mod can use and later a website design. Though i want to avoid having the xml file be packaged with textures inorder to work.
This commit is contained in:
parent
e60a78b9e0
commit
7a2675ac22
3 changed files with 125 additions and 0 deletions
15
src/dark/modhelppage/common/HelpPageInfo.java
Normal file
15
src/dark/modhelppage/common/HelpPageInfo.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package dark.modhelppage.common;
|
||||
|
||||
import cpw.mods.fml.common.registry.ItemData;
|
||||
|
||||
public class HelpPageInfo
|
||||
{
|
||||
private final ItemData data;
|
||||
private String name;
|
||||
private String body;
|
||||
|
||||
public HelpPageInfo(ItemData data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
43
src/dark/modhelppage/common/ModHelpPage.java
Normal file
43
src/dark/modhelppage/common/ModHelpPage.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package dark.modhelppage.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.common.registry.ItemData;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class ModHelpPage
|
||||
{
|
||||
private static HashMap<String, HelpPageInfo> itemMap = new HashMap();
|
||||
private static boolean init = false;
|
||||
|
||||
/** Call this to setup mod page helper for the mod
|
||||
*
|
||||
* @param modID - mod's id used to track it, and register all xmls too
|
||||
* @param configFolder - location of the mods config folder for storing player crated xmls */
|
||||
public static void init(String modID, String configFolder)
|
||||
{
|
||||
if (!init)
|
||||
{
|
||||
Map<Integer, ItemData> idMap = ReflectionHelper.getPrivateValue(GameData.class, new GameData(), "idMap");
|
||||
if (idMap != null)
|
||||
{
|
||||
for (Entry<Integer, ItemData> entry : idMap.entrySet())
|
||||
{
|
||||
itemMap.put(entry.getValue().getItemType(), new HelpPageInfo(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Call this to load an xmlFile from within the mod package
|
||||
*
|
||||
* @param modID - mod's id used to track it, and register all xmls too
|
||||
* @param xmlFile - path to the file */
|
||||
public static void load(String modID, String xmlFile)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
67
src/dark/modhelppage/common/XMLHelpFileReader.java
Normal file
67
src/dark/modhelppage/common/XMLHelpFileReader.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
package dark.modhelppage.common;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class XMLHelpFileReader
|
||||
{
|
||||
|
||||
public void loadFromFile(File file)
|
||||
{
|
||||
if (file != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(file);
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
|
||||
|
||||
NodeList nList = doc.getElementsByTagName("Object");
|
||||
|
||||
System.out.println("----------------------------");
|
||||
|
||||
for (int temp = 0; temp < nList.getLength(); temp++)
|
||||
{
|
||||
|
||||
Node nNode = nList.item(temp);
|
||||
|
||||
System.out.println("\nCurrent Element :" + nNode.getNodeName());
|
||||
|
||||
if (nNode.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
Element eElement = (Element) nNode;
|
||||
|
||||
String version = eElement.getAttribute("version");
|
||||
String type = eElement.getElementsByTagName("type").item(0).getTextContent();
|
||||
String name = eElement.getElementsByTagName("itemName").item(0).getTextContent();
|
||||
String desciption = eElement.getElementsByTagName("description").item(0).getTextContent();
|
||||
String uses = eElement.getElementsByTagName("uses").item(0).getTextContent();
|
||||
String tips = eElement.getElementsByTagName("tips").item(0).getTextContent();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectHelpInformation
|
||||
{
|
||||
String name;
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue