Android Open Source - RubeLoader Rube Scene Loader






From Project

Back to project page RubeLoader.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project RubeLoader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gushikustudios.rube.loader;
/*from  w  w w  .j  av a 2  s  . c om*/
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.SerializationException;
import com.gushikustudios.rube.RubeScene;
import com.gushikustudios.rube.loader.serializers.RubeWorldSerializer;

/**
 * Loads a json file and returns a {@link RubeScene}.
 * 
 * @author clement.vayer
 * 
 */
public class RubeSceneLoader
{
   private final Json json;
   private final RubeWorldSerializer mRubeWorldSerializer;
   private final World mWorld;

   public RubeSceneLoader()
   {
      this(null);
   }

   /**
    * This constructor accepts a predefined Box2D world. If it is non-null, scene objects will
    * be added to that rather than creating a world from scratch.
    * 
    * @param world
    */
   public RubeSceneLoader(World world)
   {
      this(world,new Json());

   }
   
   public RubeSceneLoader(World world, Json gameJson)
   {
      json = gameJson;
      json.setTypeName(null);
      json.setUsePrototypes(false);
      json.setSerializer(RubeScene.class, mRubeWorldSerializer = new RubeWorldSerializer(json));
      mWorld = world;
   }

   /**
    * Use this to load in an individual .json scene. Any previously loaded scene
    * data will be lost (including Box2D objects!)
    * 
    * @param _file
    *           File to read.
    * @return The scene represented by the RUBE JSON file.
    */
   public RubeScene loadScene(FileHandle _file)
   {
      if (mRubeWorldSerializer != null)
      {
         mRubeWorldSerializer.resetScene();
      }
      if (mWorld != null)
      {
         mRubeWorldSerializer.usePreexistingWorld(mWorld);
      }
      RubeScene scene = null;
      try
      {
         scene = json.fromJson(RubeScene.class, _file);
      }
      catch (SerializationException ex)
      {
         throw new SerializationException("Error reading file: " + _file, ex);
      }
      return scene;
   }

   /**
    * This method accumulates objects defined in a scene, allowing several separate
    * RUBE .json files to be combined. Objects are added to the scene's data, as
    * well as within the Box2D world that is ultimately returned.
    * 
    * @param _file
    *           The JSON file to parse
    * @return The cumulative scene
    */
   public RubeScene addScene(FileHandle _file)
   {
      RubeScene scene = null;

      if ((mRubeWorldSerializer != null) && (mWorld != null))
      {
         mRubeWorldSerializer.usePreexistingWorld(mWorld);
      }
      try
      {
         scene = json.fromJson(RubeScene.class, _file);
      }
      catch (SerializationException ex)
      {
         throw new SerializationException("Error reading file: " + _file, ex);
      }
      return scene;
   }
}




Java Source Code List

com.gushikustudios.rube.MainActivity.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.RubeDefaults.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeScene.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.loader.RubeSceneAsyncLoader.java
com.gushikustudios.rube.loader.RubeSceneLoader.java
com.gushikustudios.rube.loader.RubeSceneSyncLoader.java
com.gushikustudios.rube.loader.serializers.BodySerializer.java
com.gushikustudios.rube.loader.serializers.FixtureSerializer.java
com.gushikustudios.rube.loader.serializers.ImageSerializer.java
com.gushikustudios.rube.loader.serializers.JointSerializer.java
com.gushikustudios.rube.loader.serializers.RubeWorldSerializer.java
com.gushikustudios.rube.loader.serializers.Vector2Serializer.java
com.gushikustudios.rube.loader.serializers.WorldSerializer.java
com.gushikustudios.rube.loader.serializers.utils.RubeImage.java
com.gushikustudios.rube.loader.serializers.utils.RubeVertexArray.java