diff --git a/plugins/plugin_factorio.cpp b/plugins/plugin_factorio.cpp index 6383ae5..04a15eb 100644 --- a/plugins/plugin_factorio.cpp +++ b/plugins/plugin_factorio.cpp @@ -37,7 +37,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) // static store, could be anywhere tho // construct with fetched dependencies g_flp = std::make_unique(); - g_f = std::make_unique(*cr, *rmm); + g_f = std::make_unique(*cr, *rmm, *g_flp); // register types PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get()); diff --git a/src/factorio.cpp b/src/factorio.cpp index df8ed78..424ac4a 100644 --- a/src/factorio.cpp +++ b/src/factorio.cpp @@ -1,15 +1,24 @@ #include "./factorio.hpp" +#include "factorio_log_parser.hpp" #include #include -Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) : +Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) : _cr(cr), - _rmm(rmm) + _rmm(rmm), + _flp(flp) { - - _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); + + _flp.subscribe(this, FactorioLogParser_Event::join); + _flp.subscribe(this, FactorioLogParser_Event::leave); + _flp.subscribe(this, FactorioLogParser_Event::chat); + _flp.subscribe(this, FactorioLogParser_Event::died); + _flp.subscribe(this, FactorioLogParser_Event::evolution); + _flp.subscribe(this, FactorioLogParser_Event::research_started); + _flp.subscribe(this, FactorioLogParser_Event::research_finished); + _flp.subscribe(this, FactorioLogParser_Event::research_cancelled); } Factorio::~Factorio(void) { @@ -19,3 +28,35 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) { return false; } +bool Factorio::onEvent(const FactorioLog::Events::Join& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::Leave& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::Chat& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::Died& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) { + return false; +} + +bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) { + return false; +} + diff --git a/src/factorio.hpp b/src/factorio.hpp index ea7c960..541f380 100644 --- a/src/factorio.hpp +++ b/src/factorio.hpp @@ -2,15 +2,28 @@ #include -class Factorio : public RegistryMessageModelEventI { +#include "./factorio_log_parser.hpp" + +class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI { Contact3Registry& _cr; RegistryMessageModel& _rmm; + FactorioLogParser& _flp; public: - Factorio(Contact3Registry& cr, RegistryMessageModel& rmm); + Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp); virtual ~Factorio(void); protected: // rmm bool onEvent(const Message::Events::MessageConstruct& e) override; + + protected: // flp + bool onEvent(const FactorioLog::Events::Join&) override; + bool onEvent(const FactorioLog::Events::Leave&) override; + bool onEvent(const FactorioLog::Events::Chat&) override; + bool onEvent(const FactorioLog::Events::Died&) override; + bool onEvent(const FactorioLog::Events::Evolution&) override; + bool onEvent(const FactorioLog::Events::ResearchStarted&) override; + bool onEvent(const FactorioLog::Events::ResearchFinished&) override; + bool onEvent(const FactorioLog::Events::ResearchCancelled&) override; }; diff --git a/src/factorio_log_parser.cpp b/src/factorio_log_parser.cpp index e0222dc..2b418d3 100644 --- a/src/factorio_log_parser.cpp +++ b/src/factorio_log_parser.cpp @@ -15,5 +15,13 @@ void FactorioLogParser::onFileEvent(const std::string& path, const filewatch::Ev // on create, close open log file and reopen and skip to end // on mod (?), read line, parse + + + dispatch( + FactorioLogParser_Event::join, + FactorioLog::Events::Join{ + "Player" + } + ); } diff --git a/src/factorio_log_parser.hpp b/src/factorio_log_parser.hpp index 3888c21..ee5d3a5 100644 --- a/src/factorio_log_parser.hpp +++ b/src/factorio_log_parser.hpp @@ -1,10 +1,80 @@ #pragma once +#include + #include #include -class FactorioLogParser { +namespace FactorioLog::Events { + + // TODO: string views? + struct Join { + std::string player_name; + }; + + struct Leave { + std::string player_name; + }; + + struct Chat { + std::string player_name; + std::string message; + }; + + struct Died { + std::string player_name; + }; + + struct Evolution { + // ? + std::string evo; + }; + + struct ResearchStarted { + std::string name; + }; + + struct ResearchFinished { + std::string name; + }; + + struct ResearchCancelled { + std::string name; + }; + +} // FactorioLog::Events + +enum class FactorioLogParser_Event : uint32_t { + join, + leave, + chat, + died, + evolution, + research_started, + research_finished, + research_cancelled, + + MAX +}; + +struct FactorioLogParserEventI { + using enumType = FactorioLogParser_Event; + + virtual ~FactorioLogParserEventI(void) {} + + virtual bool onEvent(const FactorioLog::Events::Join&) { return false; } + virtual bool onEvent(const FactorioLog::Events::Leave&) { return false; } + virtual bool onEvent(const FactorioLog::Events::Chat&) { return false; } + virtual bool onEvent(const FactorioLog::Events::Died&) { return false; } + virtual bool onEvent(const FactorioLog::Events::Evolution&) { return false; } + virtual bool onEvent(const FactorioLog::Events::ResearchStarted&) { return false; } + virtual bool onEvent(const FactorioLog::Events::ResearchFinished&) { return false; } + virtual bool onEvent(const FactorioLog::Events::ResearchCancelled&) { return false; } +}; +using FactorioLogParserEventProviderI = EventProviderI; + +class FactorioLogParser : public FactorioLogParserEventProviderI { filewatch::FileWatch _fw; public: diff --git a/src/log_parse.cpp b/src/log_parse.cpp index 6b9691f..56aa246 100644 --- a/src/log_parse.cpp +++ b/src/log_parse.cpp @@ -7,6 +7,7 @@ std::optional log_parse_line(std::string_view line) { return std::nullopt; } + // TODO: make mod name configurable static const std::regex mod_match{".*Factorio-Event-Logger+.*\\[([A-Z ]+)\\] (.+)$"}; std::cmatch matches;