I have a XML parser (JDOM) and a pretty simple game engine. I was wondering if there was a way to load XML tags in a type of “resource”. Resource being game assets, like levels, entities, and textures. I need to figure this out for a game engine I’m creating with a ‘Game Design Environment’. (As pretentious as that sounds ;))
How I need to use it is that there is a game resource XML file like this:
(Keep in mind this is an example, I don’t think XML files are laid out like this…)
EDIT: Used java comments because the syntax highlighting was weird…
<project>
// <!-- The game's configuration -->
<config>
<displaymode width=800 height=600></displaymode>
</config>
// <!-- The game's resources -->
<resources>
<resource type="texture" path="./assets/textures/tex.png">Name-of-texture</resource>
<resource type="level" path="./assets/levels/level.xml">Name-of-level</resource>
</resources>
</project>
And the class to use in code:
//... Initialization
ResourceLoader loader = new ResourceLoader(new File("./assets/project.xml"), new SomeLogger("./assets/project.log"));
loader.parseXML();
//...
//... Use inside of game's class
Texture myTex = loader.getTexture("Name-of-texture");
Level myLevel = loader.getLevel("Name-of-level");
//...
But my problem is, how do I setup the resource loader class? Should I make HashMaps for different resources like textures, and such? Or to I make a “Resource” object that Textures, and Levels extend off of. Then have one hashmap for String resourceName, and Resource resource?
I may be doing this completely wrong, if there’s a better way to have applications like a ‘Game design environment’ interface with game resources, let me know!