more event boilerplate
This commit is contained in:
parent
4295c6cc53
commit
70317ab4db
@ -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<FactorioLogParser>();
|
||||
g_f = std::make_unique<Factorio>(*cr, *rmm);
|
||||
g_f = std::make_unique<Factorio>(*cr, *rmm, *g_flp);
|
||||
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());
|
||||
|
@ -1,15 +1,24 @@
|
||||
#include "./factorio.hpp"
|
||||
#include "factorio_log_parser.hpp"
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,28 @@
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/util/event_provider.hpp>
|
||||
|
||||
#include <FileWatch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
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<FactorioLogParserEventI>;
|
||||
|
||||
class FactorioLogParser : public FactorioLogParserEventProviderI {
|
||||
filewatch::FileWatch<std::string> _fw;
|
||||
|
||||
public:
|
||||
|
@ -7,6 +7,7 @@ std::optional<LPLRes> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user