R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
map::MapLoader Class Reference

Utility class for loading map configurations from JSON files. More...

#include <MapLoader.hpp>

Collaboration diagram for map::MapLoader:
Collaboration graph

Static Public Member Functions

static std::optional< ecs::MapDataloadFromFile (const std::string &filePath)
 Load a map from a JSON file.
 
static std::optional< ecs::MapDataloadFromString (const std::string &jsonString)
 Load a map from a JSON string.
 
static std::optional< ecs::MapDataparseJson (const nlohmann::json &jsonObj)
 Parse JSON object into MapData.
 

Detailed Description

Utility class for loading map configurations from JSON files.

Parses JSON map configuration files and creates MapData components.

JSON format example: { "mapId": "level_1", "name": "Zone Alpha", "scrollSpeed": 50.0, "background": "backgrounds/space_1.png", "spawnScript": "maps/level_1_spawn.lua", "duration": 120.0, "nextMap": "level_2" }

Definition at line 36 of file MapLoader.hpp.

Member Function Documentation

◆ loadFromFile()

std::optional< ecs::MapData > map::MapLoader::loadFromFile ( const std::string &  filePath)
static

Load a map from a JSON file.

Parameters
filePathPath to the JSON file (relative or absolute)
Returns
Optional containing MapData if successful, nullopt otherwise

Definition at line 13 of file MapLoader.cpp.

References LOG_ERROR, LOG_INFO, and parseJson().

Referenced by server::GameLogic::loadMap().

Here is the call graph for this function:

◆ loadFromString()

std::optional< ecs::MapData > map::MapLoader::loadFromString ( const std::string &  jsonString)
static

Load a map from a JSON string.

Parameters
jsonStringJSON configuration string
Returns
Optional containing MapData if successful, nullopt otherwise

Definition at line 37 of file MapLoader.cpp.

References LOG_ERROR, and parseJson().

Here is the call graph for this function:

◆ parseJson()

std::optional< ecs::MapData > map::MapLoader::parseJson ( const nlohmann::json &  jsonObj)
static

Parse JSON object into MapData.

Parameters
jsonObjnlohmann::json object
Returns
Optional containing MapData if successful, nullopt otherwise

Definition at line 51 of file MapLoader.cpp.

References LOG_DEBUG, LOG_ERROR, and LOG_INFO.

Referenced by loadFromFile(), and loadFromString().


The documentation for this class was generated from the following files: