Programming With The Variant Manager API

 

For questions about this document or this project contact Thomas Seufert at seufet@users.sourceforge.net.

 

Overview.. 1

Accessing a Project 1

Node Types and View Types. 2

Finding Nodes. 2

Retrieving Data. 3

 

 

Overview

 

The Variant Manager API consists mainly of two classes in the rle.core.vm package – InfoView and InfoGroupView.  These classes provide neat, read-only access to the information contained in a Variant Manager project.

 

The two main areas of functionality provided are searching and data retrieval.  Searching refers to finding individual nodes or groups of nodes in the project; Data Retrieval refers to obtaining the values of various attributes set for a particular InfoNode.

 

Accessing a Project

 

The first step in using these API’s is to load a project to operate on. 

 

VariantMgr vm = new VariantMgr();

DataStoreBean ds = new DataStoreBean();

ds.setName("SimpleGame");

vm.openDataStore(ds);

 

InfoNode node = (InfoNode)vm.getTree().getModel().getRoot();

InfoView variantRoot = new InfoView(node,this);

 

This code loads the project “SimpleGame” and creates a View of the “root” node, which is the path under which all project-specific information is stored.  Note that the rle.core.vm.InfoView constructor requires two arguments:

            1.  The InfoNode to create a View of

            2.  The rle.core.GameContext, for use in creating PlugIns

The above code was taken from rle.simple.SimpleGame, so using “this” for the second argument passes a SimpleGame instance, which implements GameContext.

 

The project is located by searching in the classpath for two entries:

 

  1. variants/SimpleGame/header.xml – project meta data (small file)
  2. variants/SimpleGame/data.xml – project data (big file)

 

Note that this corresponds to exactly how the graphical Variant Manager application stores and retrieves projects on the file system.

 

Node Types and View Types

 

There are two different types of nodes:

 

  1. InfoGroupNodes – Containers for a particular type of information.  May contain sub-groups and/or InfoNodes.
  2. InfoNodes – Instances of the type of information specified by the enclosing InfoGroupNode.  May contain InfoGroupNode’s, but may not contain other InfoNode’s directly.

 

Each type of node is representing by a View class in rle.core.vm – InfoGroupView and InfoView. 

Finding Nodes

 

Once that we have a view on the data hierarchy, we can search for nodes within that hierarchy.  Note that all searches are NOT case sensitive.

 

// Obtain a view of the SimpleGame root group

VariantMgr vm = new VariantMgr();

VariantBean vb = vm.findVariant("simple-game");

vm.openVariant(vb);

 

InfoGroupNode node = (InfoGroupNode)vm.getCurrentData();

InfoGroupView infoRoot = new InfoGroupView(node,this);

 

// Find the Info Node “root/info/Player/attributes/hp”

InfoView hpAttribute = info.findInfo(“Player/attributes/hp”);

 

// Find the group “root/info/Player/attributes”, and list its child InfoNode’s.

InfoGroupView playerAttributeGroup = info.findInfoGroup(“Player/attributes”);

List<InfoView> playerAttributes = playerAttributeGroup.infoList();

 

// List the InfoNode’s contained by group “root/info/Player/attributes” in one line

List<InfoView> playerAttributes = info.findInfoGroup(“Player/attributes”).infoList();

 

// List the subgroups contained by “root/info”

List<InfoGroupView> mainGroups = info.infoGroupList();

 

// Find a View’s parent or itself.  Note that these are not necessarily useful in coding, but

// does allow specification of paths from the Variant Manager relative to particular nodes.

// For instance, the Editor for dependencies in the Runtime Attribute Attribute Set relies

// on the ${parent} keyword to specify that the list of choices should be the parent

// containing the current node, rather than any particular absolute path.

InfoView hpAttribute = info.findInfo(“Player/attributes/hp”);

InfoGroupView parent = hpAttribute.findInfoGroup(“${parent}”);

InfoView self = hpAttribute.findInfo(“${self}”);

 

Retrieving Data

 

Data retrieval is done from the InfoView class.  Most methods are basically for convenient, typed access to values in a Map.

 

// Find the node

InfoView test = info.findInfo(“test/testOne”);

 

// Access to integers

int testInt = test.getInt(“testNumber”);

 

// Access to non-translated text

String testString = test.getString(“testText”);

 

// Access to internationalized text in the specified language.

String translation = test.getTranslation(“testTranslation”);

 

// Access to an instance of a PlugIn

PlugIn provider = test.createPlugIn(“testPlugIn”);

 

 

Revision Date

User

Comments

5/17/2004

Thomas Seufert

Created

5/30/2004

Thomas Seufert

Update for 0.0.7

7/8/2004

Thomas Seufert

Update for 0.0.9