Entity Factory - HopsonCommunity/Community-Game GitHub Wiki

Entity factory can load entity from .JSON file using static function:

EntityFactory::createEntity("filePath")

It returns an unique pointer to entity with all components defined in .JSON file.

JSON structure

{
    "name" : "(name of our entity)",
    "components" : [
        {
            "componentType" : "componentType1",
            "componentArgName11" : "componentValue11",
            ...
            "componentArgName1n" : "componentValue1n"
        },
        ...
        {
            "componentType" : "componentType2",
            "componentArgName21" : "componentValue21",
            ...
            "componentArgName2n" : "componentValue2n"
        }
    ]
}

Each JSON file should describe one entity. It stores its name and list of components. Component segment should look like that:

{
    "componentType" : "componentType1",
    "componentArgName11" : "componentValue11",
    ...
    "componentArgName1n" : "componentValue1n"
},

Those are passed to components constructor, and every constructor have it's own requirements to that segment as nlohmann::json. Remember that componentArg can be another JSON structure.