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

implemented command line application for launching advanced wars

parent 674c64d3
No related branches found
No related tags found
1 merge request!43Command Line Application for launching advanced_wars
......@@ -78,6 +78,8 @@ add_executable(advanced_wars ${ADVANCED_WARS_SOURCES})
set(CMAKE_MODULE_PATH ${ADVANCED_WARS_SOURCE_DIR}/cmake/ ${CMAKE_MODULE_PATH})
find_package(Qt6 REQUIRED COMPONENTS Widgets)
# Plattform-spezifische Konfiguration
if(APPLE)
# SDL2 Frameworks für macOS
......@@ -96,6 +98,7 @@ if(APPLE)
${SDL2_PATH}/SDL2.framework/SDL2
${SDL2_PATH}/SDL2_image.framework/SDL2_image
${SDL2_PATH}/SDL2_ttf.framework/SDL2_ttf
Qt6::Core
Boost::graph
box2d
)
......@@ -127,6 +130,7 @@ else()
target_link_libraries(advanced_wars
${HDF5_LIBRARIES}
Qt6::Core
-lSDL2
-lSDL2_image
-lSDL2_ttf
......@@ -138,7 +142,6 @@ endif()
# leveleditor
# Find Qt
find_package(Qt6 REQUIRED COMPONENTS Widgets)
file(GLOB_RECURSE LEVELEDITOR_SOURCES
"${PROJECT_SOURCE_DIR}/src/editor/*.cpp"
......
......@@ -6,20 +6,49 @@
#include <SDL2/SDL.h>
#include <SDL_image.h>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <vector>
#include <string>
#include <optional>
#include <filesystem>
using namespace advanced_wars;
std::optional<std::string> get_level_filepath(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationVersion("1.0.0");
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.setApplicationDescription("Advanced Wars is a multi player strategy game.\nCapture citys, build units and defeat your opponents. No mercy!");
parser.addPositionalArgument("path", "The path to the HDF5 level file from which the level should be loaded.", "<path>");
parser.process(app);
if (parser.positionalArguments().size() != 1)
{
std::cerr << "Command not recognized." << std::endl;
parser.showHelp();
return std::nullopt;
}
std::string filepath = parser.positionalArguments()[0].toStdString();
if (!std::filesystem::exists(filepath))
{
std::cerr << "The hdf5 level file path: '" << filepath <<"' does not exist." << std::endl;
return std::nullopt;
}
return parser.positionalArguments()[0].toStdString();
}
int main(int argc, char* argv[])
{
if (argc <= 1)
std::optional<std::string> level_filepath = get_level_filepath(argc, argv);
if (!level_filepath.has_value())
{
std::cerr << "Please provide the path to the level that you want to play as a command line "
"argument."
<< std::endl;
return 1;
}
......@@ -43,7 +72,7 @@ int main(int argc, char* argv[])
engine.setSpritesheet(spritesheet);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0, argv[1]);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0, level_filepath.value());
std::shared_ptr<ContextMenu> context_menu = std::make_shared<ContextMenu>();
context_menu->setOptions({"Move", "Info", "Wait"});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment