Working config file also configures the build and git dir.

master
Zed A. Shaw 1 month 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",
"building": "./assets/building.wav"
},
"git_path": ".\\",
"build_cmd": "meson compile -C builddir"
}

@ -19,13 +19,24 @@
#include <thread> // for sleep_for
#include <unistd.h>
#include <vector>
#include <nlohmann/json.hpp>
#include <fstream>
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<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*");
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.");

@ -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();
};

@ -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};
auto builder = Builder(gui, game);
builder.run(git_path, build_cmd);
builder.run();
return 1;
}
}

@ -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<std::string>();

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

Loading…
Cancel
Save