use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.
the class DOMInputCapsule method readStringSavableMap.
public Map<String, ? extends Savable> readStringSavableMap(String name, Map<String, ? extends Savable> defVal) throws IOException {
Map<String, Savable> ret = null;
Element tempEl;
if (name != null) {
tempEl = findChildElement(currentElem, name);
} else {
tempEl = currentElem;
}
if (tempEl != null) {
ret = new HashMap<String, Savable>();
NodeList nodes = tempEl.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
if (n instanceof Element && n.getNodeName().equals("MapEntry")) {
Element elem = (Element) n;
currentElem = elem;
String key = currentElem.getAttribute("key");
Savable val = readSavable("Savable", null);
ret.put(key, val);
}
}
} else {
return defVal;
}
currentElem = (Element) tempEl.getParentNode();
return ret;
}
use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.
the class SavableSerializer method writeObject.
@Override
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
Savable s = (Savable) object;
BufferOutputStream out = new BufferOutputStream(buffer);
exporter.save(s, out);
out.close();
}
use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.
the class SavableSerializer method readObject.
@Override
@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
BufferInputStream in = new BufferInputStream(data);
Savable s = importer.load(in);
in.close();
return (T) s;
}
use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.
the class Spatial method read.
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
name = ic.readString("name", null);
worldBound = (BoundingVolume) ic.readSavable("world_bound", null);
cullHint = ic.readEnum("cull_mode", CullHint.class, CullHint.Inherit);
batchHint = ic.readEnum("batch_hint", BatchHint.class, BatchHint.Inherit);
queueBucket = ic.readEnum("queue", RenderQueue.Bucket.class, RenderQueue.Bucket.Inherit);
shadowMode = ic.readEnum("shadow_mode", ShadowMode.class, ShadowMode.Inherit);
localTransform = (Transform) ic.readSavable("transform", Transform.IDENTITY);
localLights = (LightList) ic.readSavable("lights", null);
localLights.setOwner(this);
ArrayList<MatParamOverride> localOverridesList = ic.readSavableArrayList("overrides", null);
if (localOverridesList == null) {
localOverrides = new SafeArrayList<>(MatParamOverride.class);
} else {
localOverrides = new SafeArrayList(MatParamOverride.class, localOverridesList);
}
worldOverrides = new SafeArrayList<>(MatParamOverride.class);
//changed for backward compatibility with j3o files generated before the AnimControl/SkeletonControl split
//the AnimControl creates the SkeletonControl for old files and add it to the spatial.
//The SkeletonControl must be the last in the stack so we add the list of all other control before it.
//When backward compatibility won't be needed anymore this can be replaced by :
//controls = ic.readSavableArrayList("controlsList", null));
controls.addAll(0, ic.readSavableArrayList("controlsList", null));
userData = (HashMap<String, Savable>) ic.readStringSavableMap("user_data", null);
}
use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.
the class TestSaveGame method simpleInitApp.
public void simpleInitApp() {
//node that is used to store player data
Node myPlayer = new Node();
myPlayer.setName("PlayerNode");
myPlayer.setUserData("name", "Mario");
myPlayer.setUserData("health", 100.0f);
myPlayer.setUserData("points", 0);
//the actual model would be attached to this node
Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
myPlayer.attachChild(model);
//before saving the game, the model should be detached so its not saved along with the node
myPlayer.detachAllChildren();
SaveGame.saveGame("mycompany/mygame", "savegame_001", myPlayer);
//later the game is loaded again
Node player = (Node) SaveGame.loadGame("mycompany/mygame", "savegame_001");
player.attachChild(model);
rootNode.attachChild(player);
//and the data is available
System.out.println("Name: " + player.getUserData("name"));
System.out.println("Health: " + player.getUserData("health"));
System.out.println("Points: " + player.getUserData("points"));
AmbientLight al = new AmbientLight();
rootNode.addLight(al);
//note you can also implement your own classes that implement the Savable interface.
}
Aggregations