Skip to content
Snippets Groups Projects
Commit c3cc85d1 authored by TheUltimateOptimist's avatar TheUltimateOptimist
Browse files

implemented loading level from provided commandline arg

parent fc8dbffb
No related branches found
No related tags found
2 merge requests!30implemented loading level from provided commandline arg,!29Merge main into box2d to implement physics
......@@ -57,7 +57,7 @@ Level::Level(
m_selectedUnit = -1;
};
std::shared_ptr<Level> Level::loadLevel(std::string path, Engine& engine)
std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
{
HighFive::File file(path, HighFive::File::ReadOnly);
......
......@@ -80,7 +80,7 @@ class Level : public Scene
std::vector<Building> buildings, std::vector<Unit> units, std::vector<Effect> effects,
std::queue<Player> turnQ);
static std::shared_ptr<Level> loadLevel(std::string path, Engine& engine);
static std::shared_ptr<Level> loadLevel(const std::string& path, Engine& engine);
void render(Engine& engine);
......
......@@ -11,8 +11,13 @@
using namespace advanced_wars;
int main()
int main(int argc, char* argv[])
{
if (argc <= 1)
{
std::cerr << "Please provide the path to the level that you want to play as a command line argument." << std::endl;
return 1;
}
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
......@@ -34,7 +39,7 @@ int main()
engine.setSpritesheet(spritesheet);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0, argv[1]);
std::shared_ptr<ContextMenu> context_menu = std::make_shared<ContextMenu>();
context_menu->setOptions({"Move", "Info", "Wait"});
......
#include "Menu.hpp"
#include "../Level.hpp"
#include "../Building.hpp"
#include "../Config.hpp"
#include "../Level.hpp"
#include "../Spritesheet.hpp"
#include "../Tile.hpp"
#include "../Unit.hpp"
......@@ -14,8 +14,9 @@
namespace advanced_wars
{
Menu::Menu(int selectedOption)
: m_selectedOption(selectedOption), m_options({"Start Game", "Options", "Exit"}),
Menu::Menu(int selectedOption, const std::string& level_filepath)
: m_selectedOption(selectedOption), m_level_filepath(level_filepath),
m_options({"Start Game", "Options", "Exit"}),
m_backgroundTexture(nullptr)
{
}
......@@ -202,7 +203,7 @@ void Menu::handleEvent(Engine& engine, SDL_Event& event)
// std::make_shared<Level>("Osnabrück", 20, 20, tiles, buildings, units,
// effects, std::queue<Player>{});
engine.pushScene(Level::loadLevel("../res/level.h5", engine));
engine.pushScene(Level::loadLevel(m_level_filepath, engine));
}
else if (m_options[m_selectedOption] == "Options")
{
......
......@@ -23,6 +23,7 @@ class Menu : public Scene
{
private:
size_t m_selectedOption; ///< Index of the currently selected menu option.
std::string m_level_filepath; ///< The path from which the level will be loaded.
std::array<std::string, 3> m_options; ///< The available menu options.
SDL_Texture* m_backgroundTexture; ///< Pointer to the background texture (if any).
......@@ -34,8 +35,9 @@ class Menu : public Scene
* selected option based on the given index.
*
* @param selectedOption The index of the initially selected menu option.
* @param level_filepath The path from which the level will be loaded.
*/
Menu(int selectedOption);
Menu(int selectedOption, const std::string& level_filepath);
/**
* @brief Renders the menu on the screen.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment