Package gaiasky.data

Class JsonLoader

All Implemented Interfaces:
ISceneLoader

public class JsonLoader extends AbstractSceneLoader
Main JSON loader. Loads Gaia Sky dataset definition files written in JSON.
  • Constructor Details

    • JsonLoader

      public JsonLoader(Map<String,com.badlogic.ashley.core.Entity> index)
      Creates a new instance with the given index.
    • JsonLoader

      public JsonLoader()
      Creates a new instance with an empty index.
  • Method Details

    • loadData

      public com.badlogic.gdx.utils.Array<com.badlogic.ashley.core.Entity> loadData() throws FileNotFoundException
      Description copied from interface: ISceneLoader
      Performs the loading and returns an array with the entities loaded.
      Returns:
      The loaded entities.
      Throws:
      FileNotFoundException
    • processJson

      public void processJson(com.badlogic.gdx.utils.JsonValue json, Functions.Function3<Class<?>,Object,com.badlogic.gdx.utils.JsonValue,Boolean> function) throws com.badlogic.gdx.utils.reflect.ReflectionException
      Processes the given JSON tree, extracting and converting the class and value of each attribute, and runs the given function on it.
      Parameters:
      json - The JSON object.
      function - The function to run for each attribute. The parameters of the function are the value class, the value object and the JSON attribute. It returns a boolean.
      Throws:
      com.badlogic.gdx.utils.reflect.ReflectionException
    • fillEntity

      public void fillEntity(com.badlogic.gdx.utils.JsonValue json, com.badlogic.ashley.core.Entity entity, String className, boolean update) throws com.badlogic.gdx.utils.reflect.ReflectionException
      Throws:
      com.badlogic.gdx.utils.reflect.ReflectionException
    • findAttribute

      public String findAttribute(String attributeName, String className)
    • set

      public boolean set(Object instance, String fieldName, Object fieldValue) throws IllegalStateException
      Throws:
      IllegalStateException
    • depth

      public int depth(com.badlogic.gdx.utils.JsonValue attribute)
    • toMultidimDoubleArray

      public Pair<Object,Class> toMultidimDoubleArray(com.badlogic.gdx.utils.JsonValue attribute)
    • to1DoubleArray

      public Pair<Object,Class> to1DoubleArray(com.badlogic.gdx.utils.JsonValue attribute)
    • to2DoubleArray

      public Pair<Object,Class> to2DoubleArray(com.badlogic.gdx.utils.JsonValue attribute)
    • to3DoubleArray

      public Pair<Object,Class> to3DoubleArray(com.badlogic.gdx.utils.JsonValue attribute)
    • convertJsonToMap

      public Map<String,Object> convertJsonToMap(com.badlogic.gdx.utils.JsonValue json)
    • setName

      public void setName(String name)
    • setDescription

      public void setDescription(String description)
    • setParams

      public void setParams(Map<String,Object> params)