Can now use -g to set a goal.
This commit is contained in:
		
							parent
							
								
									3d4ddde96e
								
							
						
					
					
						commit
						210b0e4d21
					
				
					 7 changed files with 40 additions and 13 deletions
				
			
		|  | @ -1,8 +1,8 @@ | |||
| { | ||||
|   "sounds": { | ||||
|     "you_died": "./assets/you_died.mp3", | ||||
|     "build_success": "./assets/build_success.mp3", | ||||
|     "build_failed": "./assets/build_failed.mp3", | ||||
|     "build_success": "./assets/nothing.mp3", | ||||
|     "build_failed": "./assets/nothing.mp3", | ||||
|     "building": "./mysounds/building.mp3" | ||||
|   }, | ||||
|   "sprites": { | ||||
|  |  | |||
							
								
								
									
										13
									
								
								builder.cpp
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								builder.cpp
									
										
									
									
									
								
							|  | @ -93,9 +93,16 @@ void Builder::BUILDING(BuildEvent) { | |||
|     auto m = parse_line(line); | ||||
| 
 | ||||
|     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); | ||||
|     } else { | ||||
|       gui.update_status(game, line.size(), false); | ||||
|  | @ -180,6 +187,8 @@ void Builder::DONE(BuildEvent) { | |||
|     gui.you_died(); | ||||
|   } | ||||
| 
 | ||||
|   $hit_line_stats.clear(); | ||||
| 
 | ||||
|   game.event(GameEvent::BUILD_DONE); | ||||
|   listener->reset_state(); | ||||
|   gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^"); | ||||
|  |  | |||
|  | @ -29,7 +29,6 @@ enum BuildEvent { | |||
| }; | ||||
| 
 | ||||
| class Builder : DeadSimpleFSM<BuildState, BuildEvent> { | ||||
|   // FOUND BUG: this was interesting, it got copied but the gui kept working until the refactor
 | ||||
|   GUI &gui; | ||||
|   GameEngine &game; | ||||
|   string git_path = "NOT SET"; | ||||
|  | @ -44,6 +43,7 @@ class Builder : DeadSimpleFSM<BuildState, BuildEvent> { | |||
|   std::future<string> read_fut; | ||||
|   std::mutex fsm_mutex; | ||||
|   git_repository* repo = nullptr; | ||||
|   std::unordered_map<string, int> $hit_line_stats; | ||||
| 
 | ||||
|   public: | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										19
									
								
								gui.cpp
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								gui.cpp
									
										
									
									
									
								
							|  | @ -16,8 +16,9 @@ | |||
| 
 | ||||
| using std::string, std::vector; | ||||
| 
 | ||||
| GUI::GUI(int timer_seconds) : | ||||
| GUI::GUI(int timer_seconds, const std::wstring &g) : | ||||
|   $timer_seconds(timer_seconds), | ||||
|   $goal(g), | ||||
|   $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Turing's Tarpit") | ||||
| { | ||||
|   using namespace guecs; | ||||
|  | @ -26,11 +27,11 @@ GUI::GUI(int timer_seconds) : | |||
| 
 | ||||
|   $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); | ||||
|   $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]"); | ||||
| 
 | ||||
|   $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"}); | ||||
| 
 | ||||
|   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"); | ||||
|   $gui.set<Meter>($hp_bar, {1.0f, {10, ColorValue::LIGHT_DARK}}); | ||||
|  |  | |||
							
								
								
									
										3
									
								
								gui.hpp
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								gui.hpp
									
										
									
									
									
								
							|  | @ -10,6 +10,7 @@ class Builder; | |||
| 
 | ||||
| class GUI { | ||||
|   int $timer_seconds; | ||||
|   std::wstring $goal; | ||||
|   sf::RenderWindow $window; | ||||
|   guecs::UI $gui; | ||||
|   std::wstring $status; | ||||
|  | @ -20,7 +21,7 @@ class GUI { | |||
| 
 | ||||
|   public: | ||||
| 
 | ||||
|   GUI(int timer_seconds); | ||||
|   GUI(int timer_seconds, const std::wstring &goal); | ||||
| 
 | ||||
|   void output(const string msg); | ||||
|   void update_status(GameEngine &game, size_t line_length, bool is_error); | ||||
|  |  | |||
							
								
								
									
										10
									
								
								main.cpp
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								main.cpp
									
										
									
									
									
								
							|  | @ -6,13 +6,15 @@ | |||
| #include "textures.hpp" | ||||
| #include "shaders.hpp" | ||||
| #include <unistd.h> | ||||
| #include <codecvt> | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|   int opt = 0; | ||||
|   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) { | ||||
|       case 't': | ||||
|         timer_seconds = atoi(optarg) * 60; | ||||
|  | @ -21,6 +23,10 @@ int main(int argc, char *argv[]) | |||
|       case 'c': | ||||
|         Config::set_base_dir(optarg); | ||||
|         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(); | ||||
| 
 | ||||
|   GameEngine game{100}; | ||||
|   GUI gui(timer_seconds); | ||||
|   GUI gui(timer_seconds, goal); | ||||
|   auto builder = Builder(gui, game); | ||||
| 
 | ||||
|   gui.startup(); | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| #include <filesystem> | ||||
| #include <algorithm> | ||||
| #include <cassert> | ||||
| #include <fmt/core.h> | ||||
| 
 | ||||
| using std::string; | ||||
| 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"); | ||||
| 
 | ||||
|   if(!ignored) { | ||||
|     fmt::println("~~~ CHANGED: {}", the_path.string()); | ||||
|     changes = changes || !ignored; | ||||
|   } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw