Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Generating eAdventure Schema

Ángel del Blanco Aguado edited this page Feb 3, 2014 · 4 revisions

Although create an entire eAdventure game with a text editor is possible, we really recommend some kind of editor wrapping around all the eAdventure Schema.

Reading/Writing schema

Editor IO (@FIXME BROKEN LINK) offers methods for reading json files and convert theme in Java objects, and it also allows write Java objects into json files.

io = new EditorIO();
// Read
FileHandle fh = fileResolver.resolve("scenes/scene1.json");
Scene scene = io.fromJson(Scene.class, fh);
// Modify the scene (remove all the children)
scene.getChildren().clear()
// Save the scene again
io.toJson(scene, fh)
// And the new scene is stored in "scenes/scene1.json"

Using templates

To create new schema elements to be added to the game, templates can be quite useful. For example, you want to create a new scene element from an image in position 100, 100. The Java way would be:

ImageRenderer image = new ImageRenderer();
image.setUri("images/myimage.png");
Transformation t = new Transformation();
t.setX(100);
t.setY(100);
SceneElement sceneElement = new SceneElement();
sceneElement.setRenderer(image);
sceneElement.setTransformation(t);

scene.getChildren().add(sceneElement);

We can use a template to simplify this process: templates/imageactor.json (@FIXME the templates/imageactor.json has changed!!):

{
  transformation:{
    x:${x},
    y:${y}
  },
  renderer:{
    class:image,
    uri:"${uri}"
  }
}

You can create scene elements for the template like this:

// sceneManager = new EditorSceneManager()

// Load the template in the scene manager
sceneManager.loadTemplate("templates/imageactor.json");
// Build the object
SceneElement sceneElement = sceneManager.buildFromTemplate(SceneElement.class, "imageactor.json", "uri", "images/myimage.png", "x", "100", "y", "100");

scene.getChildren().add(sceneElement);

Clone this wiki locally