diff dep/animia/src/player.cc @ 156:cdf79282d647

dep/animia: add VERY early x11 window stuff
author Paper <mrpapersonic@gmail.com>
date Wed, 15 Nov 2023 18:04:04 -0500
parents d8a61e7e2a36
children
line wrap: on
line diff
--- a/dep/animia/src/player.cc	Wed Nov 15 15:24:39 2023 -0500
+++ b/dep/animia/src/player.cc	Wed Nov 15 18:04:04 2023 -0500
@@ -1,11 +1,11 @@
+#include "animia/player.h"
+#include "animia/util.h"
+
 #include <map>
 #include <sstream>
 #include <string>
 #include <vector>
 
-#include "animia/player.h"
-#include "animia/util.h"
-
 namespace animia {
 
 namespace internal::parser {
@@ -24,34 +24,26 @@
 	return line.find_first_not_of('\t');
 }
 
-bool HandleIndentation(const size_t current,
-                       const std::vector<Player>& players,
-                       State& state) {
+bool HandleIndentation(const size_t current, const std::vector<Player>& players, State& state) {
 	// Each state has a definitive expected indentation
 	const auto expected = [&state]() -> size_t {
 		switch (state) {
 			default:
-			case State::ExpectPlayerName:
-				return 0;
-			case State::ExpectSection:
-				return 1;
+			case State::ExpectPlayerName: return 0;
+			case State::ExpectSection: return 1;
 			case State::ExpectWindow:
 			case State::ExpectExecutable:
 			case State::ExpectStrategy:
-			case State::ExpectType:
-				return 2;
-			case State::ExpectWindowTitle:
-				return 3;
+			case State::ExpectType: return 2;
+			case State::ExpectWindowTitle: return 3;
 		}
 	}();
 
 	if (current > expected)
-		return false;  // Disallow excessive indentation
+		return false; // Disallow excessive indentation
 
 	if (current < expected) {
-		auto fix_state = [&]() {
-			state = !current ? State::ExpectPlayerName : State::ExpectSection;
-		};
+		auto fix_state = [&]() { state = !current ? State::ExpectPlayerName : State::ExpectSection; };
 		switch (state) {
 			case State::ExpectWindow:
 				if (players.back().windows.empty())
@@ -68,11 +60,8 @@
 					return false;
 				fix_state();
 				break;
-			case State::ExpectType:
-				fix_state();
-				break;
-			case State::ExpectWindowTitle:
-				return false;
+			case State::ExpectType: fix_state(); break;
+			case State::ExpectWindowTitle: return false;
 		}
 	}
 
@@ -89,10 +78,10 @@
 
 		case State::ExpectSection: {
 			static const std::map<std::string, State> sections = {
-				{"windows", State::ExpectWindow},
-				{"executables", State::ExpectExecutable},
-				{"strategies", State::ExpectStrategy},
-				{"type", State::ExpectType},
+			    {"windows",     State::ExpectWindow    },
+			    {"executables", State::ExpectExecutable},
+			    {"strategies",  State::ExpectStrategy  },
+			    {"type",        State::ExpectType      },
 			};
 			util::TrimRight(line, ":");
 			const auto it = sections.find(line);
@@ -102,19 +91,15 @@
 			break;
 		}
 
-		case State::ExpectWindow:
-			players.back().windows.push_back(line);
-			break;
+		case State::ExpectWindow: players.back().windows.push_back(line); break;
 
-		case State::ExpectExecutable:
-			players.back().executables.push_back(line);
-			break;
+		case State::ExpectExecutable: players.back().executables.push_back(line); break;
 
 		case State::ExpectStrategy: {
 			static const std::map<std::string, Strategy> strategies = {
-				{"window_title", Strategy::WindowTitle},
-				{"open_files", Strategy::OpenFiles},
-				{"ui_automation", Strategy::UiAutomation},
+			    {"window_title",  Strategy::WindowTitle },
+			    {"open_files",    Strategy::OpenFiles   },
+			    {"ui_automation", Strategy::UiAutomation},
 			};
 			util::TrimRight(line, ":");
 			const auto it = strategies.find(line);
@@ -123,17 +108,15 @@
 			const auto strategy = it->second;
 			players.back().strategies.push_back(strategy);
 			switch (strategy) {
-				case Strategy::WindowTitle:
-					state = State::ExpectWindowTitle;
-					break;
+				case Strategy::WindowTitle: state = State::ExpectWindowTitle; break;
 			}
 			break;
 		}
 
 		case State::ExpectType: {
 			static const std::map<std::string, PlayerType> types = {
-				{"default", PlayerType::Default},
-				{"web_browser", PlayerType::WebBrowser},
+			    {"default",     PlayerType::Default   },
+			    {"web_browser", PlayerType::WebBrowser},
 			};
 			const auto it = types.find(line);
 			if (it == types.end())
@@ -151,7 +134,7 @@
 	return true;
 }
 
-}  // namespace internal::parser
+} // namespace internal::parser
 
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -166,7 +149,7 @@
 
 	while (std::getline(stream, line, '\n')) {
 		if (line.empty())
-			continue;  // Ignore empty lines
+			continue; // Ignore empty lines
 
 		indentation = internal::parser::GetIndentation(line);
 
@@ -174,7 +157,7 @@
 		internal::util::TrimRight(line, "\n\r");
 
 		if (line.empty() || line.front() == '#')
-			continue;  // Ignore empty lines and comments
+			continue; // Ignore empty lines and comments
 
 		if (!internal::parser::HandleIndentation(indentation, players, state))
 			return false;
@@ -195,4 +178,4 @@
 	return ParsePlayersData(data, players);
 }
 
-}  // namespace animia
+} // namespace animia