-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'file-parsing-2' into main
- Loading branch information
Showing
13 changed files
with
325 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "efsw"] | ||
path = efsw | ||
url = https://github.com/SpartanJ/efsw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,79 @@ | ||
{ | ||
"files.associations": { | ||
"map.h": "cpp" | ||
}, | ||
"C_Cpp.formatting": "clangFormat", | ||
"C_Cpp.clang_format_style": "file" | ||
"files.associations": { | ||
"map.h": "cpp", | ||
"optional": "cpp", | ||
"fstream": "cpp", | ||
"cctype": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"bitset": "cpp", | ||
"charconv": "cpp", | ||
"chrono": "cpp", | ||
"codecvt": "cpp", | ||
"compare": "cpp", | ||
"concepts": "cpp", | ||
"condition_variable": "cpp", | ||
"cstdint": "cpp", | ||
"deque": "cpp", | ||
"map": "cpp", | ||
"set": "cpp", | ||
"string": "cpp", | ||
"unordered_map": "cpp", | ||
"vector": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"random": "cpp", | ||
"ratio": "cpp", | ||
"regex": "cpp", | ||
"source_location": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"format": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"mutex": "cpp", | ||
"new": "cpp", | ||
"numbers": "cpp", | ||
"ostream": "cpp", | ||
"semaphore": "cpp", | ||
"span": "cpp", | ||
"sstream": "cpp", | ||
"stacktrace": "cpp", | ||
"stdexcept": "cpp", | ||
"stop_token": "cpp", | ||
"streambuf": "cpp", | ||
"thread": "cpp", | ||
"cinttypes": "cpp", | ||
"typeinfo": "cpp", | ||
"variant": "cpp", | ||
"cassert": "cpp", | ||
"list": "cpp" | ||
}, | ||
"C_Cpp.formatting": "clangFormat", | ||
"C_Cpp.clang_format_style": "file", | ||
"C_Cpp.default.includePath": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<code><span>[08:25:06] </span><span></span><span style="color: #FF5;"></span><span></span><span style="color: #AAA;">player3</span><span></span><span></span><span></span><span style="color: #FF5;"> has joined (</span><span></span><span style="color: #5FF;">7</span><span></span><span></span><span></span><span style="color: #FF5;">/</span><span></span><span style="color: #5FF;">8</span><span></span><span></span><span></span><span style="color: #FF5;">)!</span><span></span><span style="color: #FF5;"></span><span></span></code><br> | ||
<code><span>[08:26:50] </span><span></span><span style="color: #5FF;">+25 Bed Wars Experience (Time Played)</span><span></span></code><br> | ||
<code><span>[08:28:21] </span><span></span><span style="color: #F5F;">player1 </span><span></span><span style="color: #AAA;">fell into the void.</span><span></span></code><br> | ||
<code><span>[08:27:02] </span><span></span><span style="color: #000;">BED DESTRUCTION > </span><span></span><span style="color: #AAA;"></span><span></span><span style="color: #F55;">Red </span><span></span><span style="color: #F55;">Bed </span><span></span><span style="color: #AAA;">was dismantled by </span><span></span><span style="color: #55F;">player4</span><span></span><span style="color: #AAA;">!</span><span></span></code><br> | ||
<code><span>[08:28:05] </span><span></span><span style="color: #5FF;">player2 </span><span></span><span style="color: #AAA;">met their end by </span><span></span><span style="color: #000;">player5</span><span></span><span style="color: #AAA;">.</span><span></span></code><br> | ||
<code><span>[08:27:44] </span><span></span><span style="color: #5F5;">player3 </span><span></span><span style="color: #AAA;">was trampled by </span><span></span><span style="color: #FF5;">player6</span><span></span><span style="color: #AAA;">.</span><span></span></code><br> | ||
<code><span>[08:27:02] </span><span></span><span style="color: #55F;">player4 </span><span></span><span style="color: #AAA;">was killed by </span><span></span><span style="color: #F55;">player7</span><span></span><span style="color: #AAA;">.</span><span></span></code><br> | ||
<code><span>[08:27:43] </span><span></span><span style="color: #F55;">player7 </span><span></span><span style="color: #AAA;">was given the cold shoulder by </span><span></span><span style="color: #55F;">player4</span><span></span><span style="color: #AAA;">. </span><span></span><span style="color: #5FF;">FINAL KILL!</span><span></span></code><br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
#include "game/sim.h" | ||
#include "models/v1.h" | ||
#include "util/logger.h" | ||
#include "chat/parseline.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "parseline.h" | ||
#include <regex> | ||
#include <algorithm> | ||
#include "game/player.h" | ||
|
||
namespace bwmodel { | ||
// TODO: incomplete/untested | ||
std::optional<PlayerColor> color_from_str(const std::string& str) { | ||
if (str == "000") return PlayerColor::BLACK; | ||
if (str == "55F") return PlayerColor::BLUE; | ||
if (str == "5F5") return PlayerColor::GREEN; | ||
if (str == "5FF") return PlayerColor::AQUA; | ||
if (str == "F55") return PlayerColor::RED; | ||
if (str == "F5F") return PlayerColor::PINK; | ||
if (str == "FF5") return PlayerColor::YELLOW; | ||
if (str == "AAA") return PlayerColor::WHITE; | ||
return {}; | ||
} | ||
|
||
std::vector<ColorSection> parse_color_sections(const std::string& line) { | ||
std::regex color_regex("<span style=\"color: #(.*?);\">(.*?)<\\/span>", | ||
std::regex_constants::ECMAScript); | ||
std::smatch matches; | ||
|
||
std::vector<ColorSection> sections; | ||
|
||
// StackOverflow Answer: https://stackoverflow.com/a/35026140 | ||
std::string::const_iterator search_start(line.cbegin()); | ||
while (std::regex_search(search_start, line.cend(), matches, | ||
color_regex)) { | ||
assert(matches.size() == 3); | ||
sections.push_back({matches[1], matches[2]}); | ||
search_start = matches.suffix().first; | ||
} | ||
|
||
return sections; | ||
} | ||
|
||
bool is_white_space(const std::string& str) { | ||
return std::all_of(str.cbegin(), str.cend(), | ||
[](char c) { return std::isspace(c); }); | ||
} | ||
|
||
bool is_game_start(const std::vector<ColorSection>& sections) { | ||
return sections.size() == 2 && sections[0].color == "000" | ||
&& is_white_space(sections[0].text) && sections[1].color == "000" | ||
&& sections[1].text == "Bed Wars"; | ||
} | ||
|
||
bool is_bed_destruction(const std::vector<ColorSection>& sections) { | ||
return sections.size() == 7 && sections[0].color == "000" | ||
&& sections[0].text.find("BED DESTRUCTION") != std::string::npos; | ||
} | ||
|
||
bool is_kill(const std::vector<ColorSection>& sections) { | ||
return sections.size() == 4 | ||
|| (sections.size() == 5 && sections[4].text == "FINAL KILL!"); | ||
} | ||
|
||
std::optional<Event> parse_line(const std::string& line) { | ||
auto sections = parse_color_sections(line); | ||
|
||
if (is_game_start(sections)) { | ||
return [](Game& game) { game.notify_start(); }; | ||
} | ||
|
||
if (is_bed_destruction(sections)) { | ||
auto opt_bed_color = color_from_str(sections[2].color); | ||
auto opt_player_color = color_from_str(sections[5].color); | ||
|
||
if (!opt_bed_color.has_value() || !opt_player_color.has_value()) { | ||
return {}; | ||
} | ||
|
||
return [opt_bed_color, opt_player_color](Game& game) { | ||
game.notify_break_bed(opt_player_color.value(), | ||
opt_bed_color.value()); | ||
}; | ||
} | ||
|
||
if (is_kill(sections)) { | ||
auto opt_killed = color_from_str(sections[0].color); | ||
auto opt_killer = color_from_str(sections[2].color); | ||
|
||
if (!opt_killed.has_value() || !opt_killer.has_value()) { | ||
return {}; | ||
} | ||
|
||
return [opt_killed, opt_killer](Game& game) { | ||
game.notify_player_kill(opt_killer.value(), opt_killed.value()); | ||
}; | ||
} | ||
|
||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <optional> | ||
#include <functional> | ||
#include "game/game.h" | ||
|
||
namespace bwmodel { | ||
using Event = std::function<void(Game&)>; | ||
|
||
struct ColorSection { | ||
std::string color; | ||
std::string text; | ||
}; | ||
|
||
std::optional<Event> parse_line(const std::string& line); | ||
} |
Oops, something went wrong.