Game data

Hi guys,



how do you manage your game assets which aren’t art asserts, like item definitions or other information about in-game objects?



I thought of using xml files, maybe.



Or is there a more common, better way to do this?



It should be possible for non-devs (like writers) to add new items and stuff.



Kind regards,



Khaos

Many ways. Check out this one for example: http://hub.jmonkeyengine.org/groups/free-announcements/forum/topic/powermonkey/#post-159693

if you mean object data, you have “user data” fields in every Spatial :wink: can be added from code or SceneComposer too(SceneComposer - so every NON-WRITER can add item data).



or



if i good understand you want to use xml, then:



im not sure if it will work, but something like this:



initializing loader:

[java]assetManager.registerLoader(AssetXMLLoader.class, “xml”);[/java]



loading:

[java]Document doc = (Document) assetManager.loadAsset(new AssetKey<Document>(“folder/file.xml”));[/java]



loader class:

[java]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package oxplay.assets.loader;



    import com.jme3.asset.AssetInfo;

    import com.jme3.asset.AssetLoader;

    import java.io.IOException;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import org.w3c.dom.Document;

    import javax.xml.parsers.DocumentBuilder;

    import javax.xml.parsers.DocumentBuilderFactory;

    import org.xml.sax.SAXException;

    import org.xml.sax.SAXParseException;



    /**

    *
  • @author oxplay

    /

    public class AssetXMLLoader implements AssetLoader {



    private final static Logger logger = Logger.getLogger(AssetXMLLoader.class.getName());



    @Override

    public Object load(AssetInfo assetInfo) throws IOException {

    try {

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

    Document doc = docBuilder.parse(assetInfo.openStream());

    return doc;

    } catch (SAXParseException err) {

    logger.log(Level.SEVERE, "
    * Parsing error" + ", line {0}, uri {1}", new Object[]{err.getLineNumber(), err.getSystemId()});

    } catch (SAXException err) {

    logger.log(Level.SEVERE, " {0}", err);

    } catch (Throwable t) {

    logger.log(Level.SEVERE, " {0}", t);

    }

    return null;

    }

    }

    [/java]



    and xml are very clear for non writers i think :wink:



    you just need to set a convention of xml files and give them scheme how to write xml for objects/etc.



    BUT: myself i store special object/equipment/etc informations on server, so non writers can change them from game panel, or DB panel.(but its only for online games)

Thank you guys :slight_smile:



Let’s think of items like swords and bows.

They have different types (melee vs. distance) and other user data.

Also they have different models and inventory gui icons.



Just to be sure: Using the SceneComposer this would be done by creating an “items”-Scene with all items as spatials.

After loading the scene i can extract the right items from this scene and use them in the actual game scene, right?!



This could work…

if you mean extract, by creating different j3o file for each weapon, then yes. If not, then yes too, but its a bad way to do it.

remember that item need to be in 0,0,0 position in SceneComposer, to avoid problems.



with equipment you make it different. First of all you should have player Node, so if you move/rotate node, you move/rotate player + equipment.



you have character and bones/armature for it. Then you load for example sword model(sword.j3o file) and apply it to hand bone.

with armor / legs / arms armor is harder, becouse it need to have animation too, then you just need to add it into player Node in good location vector.



about meele / ranged / etc. you can just set this information in Spatial “user data”, by SceneComposer or code.

then you check in code if meele then something else if ranged then something.

To be honest you have lots of choices of how to do that.



You can store it in “data” form (can be as simple as serialized java objects) and write an editor.



You can store it as text (xml is a reasonable option, not the only one).



You can attach it as data to objects using the SDK as described above.



Really its down to you and what you want to do and how you want to use it. Personally I’d prefer to keep object “gameplay” data separate from it’s model etc as it makes it easier to do things like multiple objects for the same stats (i.e. variants on items that look different but behave the same…or vice versa).

@khaos666 said:
Hi guys,

how do you manage your game assets which aren't art asserts, like item definitions or other information about in-game objects?

I thought of using xml files, maybe.

Or is there a more common, better way to do this?

It should be possible for non-devs (like writers) to add new items and stuff.

Kind regards,

Khaos


An important question:
How many different items and other stuff are you planning on having? Is this a small game with only a handful of items or is it like an RPG of some kind that may have hundreds of different items and various things?

Tying your game data to the spatial is ok when you only have a certain number of spatials. When you start to get to the point where you want to keep data that isn't associated with something currently in the scene (ie: the player can't see it yet so it doesn't have a spatial) then the tight coupling can become an issue.

Well, I’ll start with just a few items, but I’m sure the amount and variance will rise soon enough:



This engine provides such a lot of comfort in nearly every part of game development i crossed (until now). But it doesn’t when it comes to non art assets. Or I’m too blind to see it :smiley:



One idea I have is to build a database for these game assets and provide access to my co-designers. But i don’t want to use the database within the final game, so I plan to export all the information into some format i can easily handle.



All of this is for capability research and prototyping only, until now.

…thats what the SDK is for?

@khaos666 said:
This engine provides such a lot of comfort in nearly every part of game development i crossed (until now). But it doesn't when it comes to non art assets. Or I'm too blind to see it :D


There are only a few ways to get a model to OpenGL. There are an infinite number of ways to store data.

I use a combination of json, hsqldb, and scripts. Someone else is bound to do it differently.

The engine provides basic data capabilities by letting you store data right on the spatials. Beyond that, it's not really possible to properly handle an infinite number of data storage methods.
1 Like

Ok. Your Point :wink: