Class JsonLoader
java.lang.Object
gaiasky.data.AbstractSceneLoader
gaiasky.data.JsonLoader
- All Implemented Interfaces:
ISceneLoader
Main JSON loader. Loads Gaia Sky dataset definition files written in JSON.
-
Field Summary
Fields inherited from class AbstractSceneLoader
datasetDirectory, dataSource, filePaths, index, loggedArchetypes, parentName, scene -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with an empty index.JsonLoader(Map<String, com.badlogic.ashley.core.Entity> index) Creates a new instance with the given index. -
Method Summary
Modifier and TypeMethodDescriptionconvertJsonToMap(com.badlogic.gdx.utils.JsonValue json) intdepth(com.badlogic.gdx.utils.JsonValue attribute) voidfillEntity(com.badlogic.gdx.utils.JsonValue json, com.badlogic.ashley.core.Entity entity, String className, boolean update) findAttribute(String attributeName, String className) com.badlogic.gdx.utils.Array<com.badlogic.ashley.core.Entity> loadData()Performs the loading and returns an array with the entities loaded.voidprocessJson(com.badlogic.gdx.utils.JsonValue json, Functions.Function3<Class<?>, Object, com.badlogic.gdx.utils.JsonValue, Boolean> function) Processes the given JSON tree, extracting and converting the class and value of each attribute, and runs the given function on it.booleanvoidsetDescription(String description) voidvoidto1DoubleArray(com.badlogic.gdx.utils.JsonValue attribute) to2DoubleArray(com.badlogic.gdx.utils.JsonValue attribute) to3DoubleArray(com.badlogic.gdx.utils.JsonValue attribute) toMultidimDoubleArray(com.badlogic.gdx.utils.JsonValue attribute) Methods inherited from class AbstractSceneLoader
initialize, initialize, initialize, setIndex, setParentNameModifier and TypeMethodDescriptionvoidinitialize(String[] files, Scene scene) voidinitialize(String[] files, String dsLocation, Scene scene) voidinitialize(uk.ac.starlink.util.DataSource dataSource, Scene scene) voidvoidsetParentName(String parentName)
-
Constructor Details
-
JsonLoader
-
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 FileNotFoundExceptionDescription copied from interface:ISceneLoaderPerforms 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
-
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
-
to1DoubleArray
-
to2DoubleArray
-
to3DoubleArray
-
convertJsonToMap
-
setName
-
setDescription
-
setParams
-