diff --git a/.tarpit.json b/.tarpit.json index afbdd5e..c672727 100644 --- a/.tarpit.json +++ b/.tarpit.json @@ -5,5 +5,6 @@ "build_failed": "./assets/build_failed.wav", "building": "./assets/building.wav" }, + "git_path": ".\\", "build_cmd": "meson compile -C builddir" } diff --git a/builder.cpp b/builder.cpp index 27d927a..151846b 100644 --- a/builder.cpp +++ b/builder.cpp @@ -19,13 +19,24 @@ #include // for sleep_for #include #include +#include +#include using namespace std; using namespace fmt; +using namespace nlohmann; #define BUF_MAX 1024 -void Builder::run_build(GameEngine &game, const char* command) { +Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) { + ifstream infile(".tarpit.json"); + json config = json::parse(infile); + + config["git_path"].template get_to(git_path); + config["build_cmd"].template get_to(build_cmd); +} + +void Builder::run_build() { regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"); char buffer[BUF_MAX]; // BUF_MAX is a define already? @@ -37,7 +48,7 @@ void Builder::run_build(GameEngine &game, const char* command) { dbc::pre("simple test", [&]() { return stats_out.good(); }); // need to catch the error message when the command is bad - FILE *build_out = popen(command, "r"); + FILE *build_out = popen(build_cmd.c_str(), "r"); dbc::check(build_out != nullptr, "Failed to run command."); game.start_round(); @@ -77,14 +88,14 @@ void Builder::run_build(GameEngine &game, const char* command) { if(rc == 0) { gui.build_works(); } else { - gui.build_failed(command); + gui.build_failed(build_cmd); } stats_out.close(); dbc::post("a post test", [&]() { return !stats_out.is_open(); }); } -void Builder::run(const char *git_path, const char *build_cmd) { +void Builder::run() { git_repository* repo = nullptr; try { @@ -94,7 +105,7 @@ void Builder::run(const char *git_path, const char *build_cmd) { git_libgit2_init(); - int err = git_repository_open(&repo, git_path); + int err = git_repository_open(&repo, git_path.c_str()); dbc::check(err == 0, git_error_last()->message); UpdateListener* listener = new UpdateListener(repo); @@ -110,7 +121,7 @@ void Builder::run(const char *git_path, const char *build_cmd) { gui.building(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); gui.output(format("CHANGES! Running build {}", build_cmd)); - run_build(game, build_cmd); + run_build(); if(game.is_dead()) { gui.output("!!!! YOU DIED! !!!! Learn to code luser."); diff --git a/builder.hpp b/builder.hpp index 4c170ff..1df588d 100644 --- a/builder.hpp +++ b/builder.hpp @@ -5,13 +5,14 @@ class Builder { GUI gui; GameEngine game; + string git_path = "NOT SET"; + string build_cmd = "NOT SET"; public: - Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {}; + Builder(GUI &g, GameEngine &engine); - void run_build(GameEngine &game, const char* command); - - void run(const char *git_path, const char *build_cmd); + void run_build(); + void run(); }; diff --git a/escape_turings_tarpit.cpp b/escape_turings_tarpit.cpp index 2c5b56a..14d7568 100644 --- a/escape_turings_tarpit.cpp +++ b/escape_turings_tarpit.cpp @@ -3,19 +3,11 @@ int main(int argc, char *argv[]) { - if(argc != 3) { - fmt::println("USAGE: escape_turings_tarpit PATH BUILD_CMD"); - return 1; - } else { - const char *git_path = argv[1]; - const char *build_cmd = argv[2]; + GUI gui; + GameEngine game{100}; - GUI gui; - GameEngine game{100}; + auto builder = Builder(gui, game); + builder.run(); - auto builder = Builder(gui, game); - builder.run(git_path, build_cmd); - - return 1; - } + return 1; } diff --git a/gui.cpp b/gui.cpp index fa7b8a7..56f5c46 100644 --- a/gui.cpp +++ b/gui.cpp @@ -23,10 +23,6 @@ using namespace fmt; using namespace nlohmann; namespace fs = std::filesystem; -SoundQuip::SoundQuip() { - -}; - void SoundQuip::load(json &data, const char *file_key) { auto audio = data["audio"]; json::string_t file_name = audio[file_key].template get(); diff --git a/gui.hpp b/gui.hpp index aba7cc0..95f0af2 100644 --- a/gui.hpp +++ b/gui.hpp @@ -13,7 +13,7 @@ public: sf::SoundBuffer buffer; bool initialized; - SoundQuip(); + SoundQuip() {}; void load(nlohmann::json &data, const char *in_file); void play();