Working config file also configures the build and git dir.

master
Zed A. Shaw 3 months ago
parent 90f4f727ba
commit eb6c7b0e33
  1. 1
      .tarpit.json
  2. 23
      builder.cpp
  3. 9
      builder.hpp
  4. 10
      escape_turings_tarpit.cpp
  5. 4
      gui.cpp
  6. 2
      gui.hpp

@ -5,5 +5,6 @@
"build_failed": "./assets/build_failed.wav", "build_failed": "./assets/build_failed.wav",
"building": "./assets/building.wav" "building": "./assets/building.wav"
}, },
"git_path": ".\\",
"build_cmd": "meson compile -C builddir" "build_cmd": "meson compile -C builddir"
} }

@ -19,13 +19,24 @@
#include <thread> // for sleep_for #include <thread> // for sleep_for
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
#include <nlohmann/json.hpp>
#include <fstream>
using namespace std; using namespace std;
using namespace fmt; using namespace fmt;
using namespace nlohmann;
#define BUF_MAX 1024 #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<string>(git_path);
config["build_cmd"].template get_to<string>(build_cmd);
}
void Builder::run_build() {
regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"); regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
char buffer[BUF_MAX]; // BUF_MAX is a define already? 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(); }); dbc::pre("simple test", [&]() { return stats_out.good(); });
// need to catch the error message when the command is bad // 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."); dbc::check(build_out != nullptr, "Failed to run command.");
game.start_round(); game.start_round();
@ -77,14 +88,14 @@ void Builder::run_build(GameEngine &game, const char* command) {
if(rc == 0) { if(rc == 0) {
gui.build_works(); gui.build_works();
} else { } else {
gui.build_failed(command); gui.build_failed(build_cmd);
} }
stats_out.close(); stats_out.close();
dbc::post("a post test", [&]() { return !stats_out.is_open(); }); 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; git_repository* repo = nullptr;
try { try {
@ -94,7 +105,7 @@ void Builder::run(const char *git_path, const char *build_cmd) {
git_libgit2_init(); 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); dbc::check(err == 0, git_error_last()->message);
UpdateListener* listener = new UpdateListener(repo); UpdateListener* listener = new UpdateListener(repo);
@ -110,7 +121,7 @@ void Builder::run(const char *git_path, const char *build_cmd) {
gui.building(); gui.building();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
gui.output(format("CHANGES! Running build {}", build_cmd)); gui.output(format("CHANGES! Running build {}", build_cmd));
run_build(game, build_cmd); run_build();
if(game.is_dead()) { if(game.is_dead()) {
gui.output("!!!! YOU DIED! !!!! Learn to code luser."); gui.output("!!!! YOU DIED! !!!! Learn to code luser.");

@ -5,13 +5,14 @@
class Builder { class Builder {
GUI gui; GUI gui;
GameEngine game; GameEngine game;
string git_path = "NOT SET";
string build_cmd = "NOT SET";
public: 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_build();
void run(const char *git_path, const char *build_cmd);
void run();
}; };

@ -3,19 +3,11 @@
int main(int argc, char *argv[]) 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; GUI gui;
GameEngine game{100}; GameEngine game{100};
auto builder = Builder(gui, game); auto builder = Builder(gui, game);
builder.run(git_path, build_cmd); builder.run();
return 1; return 1;
}
} }

@ -23,10 +23,6 @@ using namespace fmt;
using namespace nlohmann; using namespace nlohmann;
namespace fs = std::filesystem; namespace fs = std::filesystem;
SoundQuip::SoundQuip() {
};
void SoundQuip::load(json &data, const char *file_key) { void SoundQuip::load(json &data, const char *file_key) {
auto audio = data["audio"]; auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<std::string>(); json::string_t file_name = audio[file_key].template get<std::string>();

@ -13,7 +13,7 @@ public:
sf::SoundBuffer buffer; sf::SoundBuffer buffer;
bool initialized; bool initialized;
SoundQuip(); SoundQuip() {};
void load(nlohmann::json &data, const char *in_file); void load(nlohmann::json &data, const char *in_file);
void play(); void play();

Loading…
Cancel
Save