-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjsonentityloader.hpp
More file actions
98 lines (96 loc) · 3.91 KB
/
jsonentityloader.hpp
File metadata and controls
98 lines (96 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include <fea/config.hpp>
#include <vector>
#include <string>
#include <fea/entity/filenotfoundexception.hpp>
#include <fea/entity/entityfactory.hpp>
namespace Json
{
class Value;
}
namespace fea
{
class FEA_API JsonEntityLoader
{
public:
std::vector<std::pair<std::string, EntityTemplate>> loadEntityTemplates(const std::string& path);
std::unordered_map<std::string, std::string> loadEntityAttributes(const std::string& path);
private:
std::unordered_map<std::string, std::string> jsonObjToStringMap(const Json::Value&);
};
/** @addtogroup EntitySystem
*@{
* @class JsonEntityLoader
*@}
***
* @class JsonEntityLoader
* @brief This class is for loading json files describing entity templates and entity attributes.
*
* The content of the returned maps can directly be passed to the EntityFactory to register the attributes and entity templates.
*
* Here is an example of how an entity attribute file should be formatted:
* @code
* {
* "position":"vec2",
* "velocity":"vec2",
* "acceleration":"vec2",
* "maxvelocity":"float",
* "maxacceleration":"float",
* }
* @endcode
*
* Here is an example of how an entity template file should be formatted:
* @code
* {
* "entities":[
* {
* "name" : "physics_entity",
*
* "attributes":
* {
* "position":"0.0f,0.0f", "velocity":"0.0f,0.0f", "acceleration":"0.0f,0.0f"
* }
* },
* {
* "name" : "enemy",
*
* "inherits" : ["physics_entity"],
*
* "attributes":
* {
* "health":""
* }
* },
* {
* "name" : "player",
*
* "inherits" : ["physics_entity"],
*
* "attributes":
* {
* "health":"100", "jump_strength":"1.0f", "position":"50.0f, 60.0f"
* }
* }]
* }
* @endcode
* The file is divided into entity template definitions. The three entities defined in this files are "physics_entity", "enemy" and "player". Every entity template internally defines a sequence of attributes that they should have and/or which other entity templates they inherit. The attributes might come with default values. For instance, the first attribute of the entity template "player" is "health" with a default value of "100".
*
* If a template inherits another template, it means that the inheriting template will obtain all attributes and default values from the inherited templates. Inheriting templates can override default values by restating the attributes like the template "player" does in the above example with the "position" attribute.
***
* @fn std::vector<std::pair<std::string, EntityTemplate> > JsonEntityLoader::loadEntityTemplates(const std::string& path)
* @brief Load a json file defining entity templates.
*
* Use this function to load an entity template file. The content of the return value can be given to the EntityFactory::addTemplate function.
* Throws FileNotFoundException when the file does not exist.
* @param path File to open.
* @return A map with the entity templates.
***
* @fn std::unordered_map<std::string, std::string> JsonEntityLoader::loadEntityAttributes(const std::string& path)
* @brief Load a json file defining entity attributes.
*
* Use this function to load an entity attribute file. The content of the return value can be given to the EntityFactory::registerAttribute function.
* Throws FileNotFoundException when the file does not exist.
* @param path File to open.
* @return A map with the entity attributes.
**/
}