Can now use -g to set a goal.

master
Zed A. Shaw 12 hours ago
parent 3d4ddde96e
commit 210b0e4d21
  1. 4
      assets/config.json
  2. 11
      builder.cpp
  3. 2
      builder.hpp
  4. 19
      gui.cpp
  5. 3
      gui.hpp
  6. 10
      main.cpp
  7. 2
      watcher.cpp

@ -1,8 +1,8 @@
{ {
"sounds": { "sounds": {
"you_died": "./assets/you_died.mp3", "you_died": "./assets/you_died.mp3",
"build_success": "./assets/build_success.mp3", "build_success": "./assets/nothing.mp3",
"build_failed": "./assets/build_failed.mp3", "build_failed": "./assets/nothing.mp3",
"building": "./mysounds/building.mp3" "building": "./mysounds/building.mp3"
}, },
"sprites": { "sprites": {

@ -93,9 +93,16 @@ void Builder::BUILDING(BuildEvent) {
auto m = parse_line(line); auto m = parse_line(line);
if(m.match) { if(m.match) {
fmt::println("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message); std::string hit_line = fmt::format("{} @ {}:{}:{}",
m.type, m.file_name, m.lnumber, m.col);
fmt::println("HIT WITH {} {}", hit_line, m.message);
if(!$hit_line_stats.contains(hit_line)) {
$hit_line_stats.insert_or_assign(hit_line, 1);
game.event(GameEvent::HIT, m.type); game.event(GameEvent::HIT, m.type);
}
gui.update_status(game, line.size(), true); gui.update_status(game, line.size(), true);
} else { } else {
gui.update_status(game, line.size(), false); gui.update_status(game, line.size(), false);
@ -180,6 +187,8 @@ void Builder::DONE(BuildEvent) {
gui.you_died(); gui.you_died();
} }
$hit_line_stats.clear();
game.event(GameEvent::BUILD_DONE); game.event(GameEvent::BUILD_DONE);
listener->reset_state(); listener->reset_state();
gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^"); gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^");

@ -29,7 +29,6 @@ enum BuildEvent {
}; };
class Builder : DeadSimpleFSM<BuildState, BuildEvent> { class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
// FOUND BUG: this was interesting, it got copied but the gui kept working until the refactor
GUI &gui; GUI &gui;
GameEngine &game; GameEngine &game;
string git_path = "NOT SET"; string git_path = "NOT SET";
@ -44,6 +43,7 @@ class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
std::future<string> read_fut; std::future<string> read_fut;
std::mutex fsm_mutex; std::mutex fsm_mutex;
git_repository* repo = nullptr; git_repository* repo = nullptr;
std::unordered_map<string, int> $hit_line_stats;
public: public:

@ -16,8 +16,9 @@
using std::string, std::vector; using std::string, std::vector;
GUI::GUI(int timer_seconds) : GUI::GUI(int timer_seconds, const std::wstring &g) :
$timer_seconds(timer_seconds), $timer_seconds(timer_seconds),
$goal(g),
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Turing's Tarpit") $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Turing's Tarpit")
{ {
using namespace guecs; using namespace guecs;
@ -26,11 +27,11 @@ GUI::GUI(int timer_seconds) :
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout( $gui.layout(
"[*%(200,300)face|_|*%(100,300)status|*%(200,500)log|_]" "[*%(200,500)log|_|*%(100,300)status|*%(200,300)face|_]"
"[_|_|_|_|_]" "[_|_|_|_|_]"
"[_|_|_|_|_]" "[_|_|_|_|_]"
"[*%(300,200)clock|_|_|_|_]" "[_|_|*%(300,100)goal|_|_]"
"[_|_|_|_|_]" "[_|_|*%(300,100)clock|_|_]"
"[hp_bar]"); "[hp_bar]");
$gui.world().set_the<Background>({$gui.$parser, {0,0,0,0}}); $gui.world().set_the<Background>({$gui.$parser, {0,0,0,0}});
@ -52,7 +53,15 @@ GUI::GUI(int timer_seconds) :
$gui.set<Effect>($log, {(float)$timer_seconds, "build_status"}); $gui.set<Effect>($log, {(float)$timer_seconds, "build_status"});
auto clock = $gui.entity("clock"); auto clock = $gui.entity("clock");
$gui.set<Label>(clock, {L"00:00:00", 110}); auto& clock_rect = $gui.get<Rectangle>(clock);
clock_rect.color = ColorValue::BLACK;
$gui.set<Label>(clock, {L"00:00:00", 60});
auto goal = $gui.entity("goal");
std::wstring msg = fmt::format(L"Complete '{}' in:", $goal);
auto& goal_rect = $gui.get<Rectangle>(goal);
goal_rect.color = ColorValue::BLACK;
$gui.set<Label>(goal, {msg, 30});
$hp_bar = $gui.entity("hp_bar"); $hp_bar = $gui.entity("hp_bar");
$gui.set<Meter>($hp_bar, {1.0f, {10, ColorValue::LIGHT_DARK}}); $gui.set<Meter>($hp_bar, {1.0f, {10, ColorValue::LIGHT_DARK}});

@ -10,6 +10,7 @@ class Builder;
class GUI { class GUI {
int $timer_seconds; int $timer_seconds;
std::wstring $goal;
sf::RenderWindow $window; sf::RenderWindow $window;
guecs::UI $gui; guecs::UI $gui;
std::wstring $status; std::wstring $status;
@ -20,7 +21,7 @@ class GUI {
public: public:
GUI(int timer_seconds); GUI(int timer_seconds, const std::wstring &goal);
void output(const string msg); void output(const string msg);
void update_status(GameEngine &game, size_t line_length, bool is_error); void update_status(GameEngine &game, size_t line_length, bool is_error);

@ -6,13 +6,15 @@
#include "textures.hpp" #include "textures.hpp"
#include "shaders.hpp" #include "shaders.hpp"
#include <unistd.h> #include <unistd.h>
#include <codecvt>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt = 0; int opt = 0;
int timer_seconds = 60 * 60; int timer_seconds = 60 * 60;
std::wstring goal{L"No Goal"};
while((opt = getopt(argc, argv, "t:c:")) != -1) { while((opt = getopt(argc, argv, "t:c:g:")) != -1) {
switch(opt) { switch(opt) {
case 't': case 't':
timer_seconds = atoi(optarg) * 60; timer_seconds = atoi(optarg) * 60;
@ -21,6 +23,10 @@ int main(int argc, char *argv[])
case 'c': case 'c':
Config::set_base_dir(optarg); Config::set_base_dir(optarg);
break; break;
case 'g':
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
goal = converter.from_bytes(optarg);
break;
} }
} }
@ -29,7 +35,7 @@ int main(int argc, char *argv[])
textures::init(); textures::init();
GameEngine game{100}; GameEngine game{100};
GUI gui(timer_seconds); GUI gui(timer_seconds, goal);
auto builder = Builder(gui, game); auto builder = Builder(gui, game);
gui.startup(); gui.startup();

@ -2,6 +2,7 @@
#include <filesystem> #include <filesystem>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <fmt/core.h>
using std::string; using std::string;
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -29,6 +30,7 @@ void UpdateListener::handleFileAction(efsw::WatchID watchid,
assert(rc == 0 && "libgit2 says it can't check the ignored file"); assert(rc == 0 && "libgit2 says it can't check the ignored file");
if(!ignored) { if(!ignored) {
fmt::println("~~~ CHANGED: {}", the_path.string());
changes = changes || !ignored; changes = changes || !ignored;
} }
} }

Loading…
Cancel
Save