Package gaiasky.data
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 gaiasky.data.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) int
depth
(com.badlogic.gdx.utils.JsonValue attribute) void
fillEntity
(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.void
processJson
(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.boolean
void
setDescription
(String description) void
void
to1DoubleArray
(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 gaiasky.data.AbstractSceneLoader
initialize, initialize, initialize, setIndex, setParentName
-
Constructor Details
-
JsonLoader
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 FileNotFoundExceptionDescription 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, throws com.badlogic.gdx.utils.reflect.ReflectionExceptioncom.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.- 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
-