Skip to content

Commit

Permalink
Command line args
Browse files Browse the repository at this point in the history
  • Loading branch information
curzel-it committed Jun 23, 2024
1 parent 5ecb066 commit b2fbae5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
8 changes: 6 additions & 2 deletions Sources/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ find_package(Qt6 COMPONENTS Widgets REQUIRED)
# Json
find_package(nlohmann_json 3.2.0 REQUIRED)

# Boost
find_package(Boost 1.65 REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})

# App executable
add_executable(Main ${MAIN_SOURCES} ${CAPABILITIES_SOURCES} ${GAME_SOURCES} ${SPECIES_SOURCES} ${SPRITES_SOURCES} ${UTILS_SOURCES})
target_link_libraries(Main PRIVATE nlohmann_json::nlohmann_json Qt6::Widgets)
target_link_libraries(Main PRIVATE nlohmann_json::nlohmann_json Qt6::Widgets ${Boost_LIBRARIES})

# Google Test
enable_testing()
Expand All @@ -65,7 +69,7 @@ file(GLOB TEST_UTILS_SOURCES "src/utils/*.cpp")

# Test executable
add_executable(Test ${TEST_SOURCES} ${TEST_CAPABILITIES_SOURCES} ${TEST_GAME_SOURCES} ${TEST_SPECIES_SOURCES} ${TEST_SPRITES_SOURCES} ${TEST_UTILS_SOURCES})
target_link_libraries(Test GTest::GTest GTest::Main Qt6::Widgets)
target_link_libraries(Test GTest::GTest GTest::Main Qt6::Widgets ${Boost_LIBRARIES})

# Test discovery
gtest_discover_tests(Test)
39 changes: 34 additions & 5 deletions Sources/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>
#include <memory>
#include <thread>
#include <boost/program_options.hpp>

#include "app_window.h"
#include "game/game.h"
Expand All @@ -18,16 +19,28 @@ const double ANIMATIONS_FPS = 10.0;
const std::string SPECIES_PATH = "/Users/curzel/dev/bit-therapy/Species";
const std::string ASSETS_PATH = "/Users/curzel/dev/bit-therapy/PetsAssets";

void setupGame(Game * game, SpriteSetBuilder& builder);
namespace po = boost::program_options;

void setupGame(Game * game, SpriteSetBuilder& builder, std::string selectedSpecies);
std::thread startGameLoop(Game * game);
po::variables_map parseArgs(int argc, char *argv[]);

int main(int argc, char *argv[]) {
auto args = parseArgs(argc, argv);
std::string selectedSpecies = "ape";

if (args.count("species")) {
selectedSpecies = args["species"].as<std::string>();
} else {
std::cout << "No species specified.\n";
}

std::cout << "Starting..." << std::endl;

SpriteSetBuilder builder = SpriteSetBuilder({});

Game game(GAME_FPS);
setupGame(&game, builder);
setupGame(&game, builder, selectedSpecies);
auto gameLoop = startGameLoop(&game);
// gameLoop.join();

Expand All @@ -45,14 +58,30 @@ int main(int argc, char *argv[]) {
return app.exec();
}

void setupGame(Game * game, SpriteSetBuilder& builder) {
po::variables_map parseArgs(int argc, char *argv[]) {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("species", po::value<std::string>(), "enter species name");

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);

if (vm.count("help")) {
std::cout << desc << "\n";
}
return vm;
}

void setupGame(Game * game, SpriteSetBuilder& builder, std::string selectedSpecies) {
auto assetPaths = listFiles(ASSETS_PATH, ".png");
auto spriteSets = builder.spriteSets(assetPaths);
auto apeSprites = spriteSets["ape"];
auto apeSprites = spriteSets[selectedSpecies];

auto frame = Rect(0.0, 0.0, 50.0, 50.0);

Species apeSpecies("ape", 1.0, 1.0);
Species apeSpecies(selectedSpecies, 1.0, 1.0);
Entity ape(ANIMATIONS_FPS, 50.0, 1.0, apeSpecies, apeSprites, frame);

game->add(ape);
Expand Down

0 comments on commit b2fbae5

Please sign in to comment.