holesome/src/game/level/level_loader.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

#include "level_loader.hpp"
#include "../game.h"
2023-06-11 15:54:05 +02:00
#include "../physics/map/map_simulation.hpp"
#include "../../debug/grid_debug_layer.h"
#include "../player/player_spawner.hpp"
#include "../../levels.hpp"
void LevelLoader::loadLevel(LevelConfig levelConfig)
{
Game::getInstance()->clearGameObjects();
LOG(INFO) << "Loading level '" << levelConfig.name << "' ...";
Game::getInstance()->setLevel(levelConfig);
MapSimulation::getInstance()->resetMap(levelConfig.worldMapSize);
// Add basic game objects
if (DEVELOPER_MODE)
{
Game::getInstance()->addGameObject(new GridDebugLayer(0, 50, 0, 50));
}
Game::getInstance()->addGameObject(new TrackingView());
Game::getInstance()->addGameObject(new PlayerSpawner(levelConfig.playerSpawnPoints));
LOG(INFO) << "Finished loading level '" << levelConfig.name << "'.";
}
void LevelLoader::loadLevel(const std::string &levelName)
{
// Does level exist?
if (!LEVELS.contains(levelName))
{
LOG(ERROR) << "Level '" << levelName << "' not found. Could not load it.";
throw std::invalid_argument("Could not load level.");
}
LevelLoader::loadLevel(LEVELS.at(levelName));
}