I now have the kernel of the game prototyped.

master
Zed A. Shaw 2 months ago
parent f1ee5e82f4
commit 83b6aa7cd0
  1. 44
      watchgit.cpp

@ -20,6 +20,31 @@ using namespace fmt;
#define BUF_MAX 1024
class GameEngine {
int hit_points = 0;
public:
GameEngine(int hp) : hit_points(hp) {};
bool hit(unsigned int damage) {
hit_points -= damage;
if(is_dead()) {
println("YOU DIED!");
} else {
println("DAMAGE {}, HP: {}", damage, hit_points);
}
// super dumb but I'll clean it up later
return is_dead();
}
bool is_dead() {
return hit_points <= 0;
}
};
/*
* No idea what the semantics of this are. Will need
* to research git's dumb terminology to figure out why
@ -109,7 +134,7 @@ class UpdateListener : public efsw::FileWatchListener {
}
};
void run_build(const char* command) {
void run_build(GameEngine &game, const char* command) {
regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
char buffer[BUF_MAX]; // BUF_MAX is a define already?
@ -141,7 +166,14 @@ void run_build(const char* command) {
lnumber, col, type, message);
stats_out << result;
cout << "MATCHED: " << quoted(result);
println("{} @ {}:{}:{} {}", type, file_name, lnumber, col, message);
if(type == "error") {
game.hit(4);
} else {
game.hit(1);
}
}
}
@ -149,7 +181,6 @@ void run_build(const char* command) {
dbc::post("a post test", [&]() { return !stats_out.is_open(); });
}
int main(int argc, char *argv[])
{
git_repository* repo = nullptr;
@ -174,6 +205,8 @@ int main(int argc, char *argv[])
print("Watching directory {} for changes...\n", git_path);
efsw::WatchID wid = fileWatcher->addWatch(git_path, listener, true);
GameEngine game{100};
while(true) {
print("WAITING...\r");
fileWatcher->watch();
@ -181,7 +214,7 @@ int main(int argc, char *argv[])
if(listener->changes) {
sleep(1);
println("CHANGES! Running build {}", build_cmd);
run_build(build_cmd);
run_build(game, build_cmd);
listener->reset_state();
}
sleep(1);
@ -191,8 +224,7 @@ int main(int argc, char *argv[])
} catch(dbc::Error &err) {
print("ERROR: {}\n", err.message);
if(repo != nullptr) git_repository_free(repo);
git_libgit2_shutdown();
return 1;
}
git_libgit2_shutdown();
}

Loading…
Cancel
Save