Compare commits
2 Commits
06bd55c165
...
70317ab4db
Author | SHA1 | Date | |
---|---|---|---|
70317ab4db | |||
4295c6cc53 |
@ -3,10 +3,12 @@
|
||||
#include <entt/entt.hpp>
|
||||
#include <entt/fwd.hpp>
|
||||
|
||||
#include "factorio_log_parser.hpp"
|
||||
#include "factorio.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static std::unique_ptr<FactorioLogParser> g_flp = nullptr;
|
||||
static std::unique_ptr<Factorio> g_f = nullptr;
|
||||
|
||||
constexpr const char* plugin_name = "Factorio";
|
||||
@ -34,9 +36,11 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
||||
|
||||
// static store, could be anywhere tho
|
||||
// construct with fetched dependencies
|
||||
g_f = std::make_unique<Factorio>(*cr, *rmm);
|
||||
g_flp = std::make_unique<FactorioLogParser>();
|
||||
g_f = std::make_unique<Factorio>(*cr, *rmm, *g_flp);
|
||||
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());
|
||||
PLUG_PROVIDE_INSTANCE(Factorio, plugin_name, g_f.get());
|
||||
} catch (const ResolveException& e) {
|
||||
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
|
||||
@ -50,6 +54,7 @@ SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
|
||||
std::cout << "PLUGIN " << plugin_name << " STOP()\n";
|
||||
|
||||
g_f.reset();
|
||||
g_flp.reset();
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float) {
|
||||
|
@ -5,6 +5,8 @@ project(solanaceae)
|
||||
add_library(solanaceae_factorio
|
||||
./log_parse.hpp
|
||||
./log_parse.cpp
|
||||
./factorio_log_parser.hpp
|
||||
./factorio_log_parser.cpp
|
||||
./factorio.hpp
|
||||
./factorio.cpp
|
||||
)
|
||||
|
@ -1,18 +1,24 @@
|
||||
#include "./factorio.hpp"
|
||||
#include "factorio_log_parser.hpp"
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
#include "./log_parse.hpp"
|
||||
|
||||
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) :
|
||||
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
|
||||
_cr(cr),
|
||||
_rmm(rmm),
|
||||
_fw("test.txt", [this](const auto& path, const auto event){ this->onFileEvent(path, event);})
|
||||
_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) {
|
||||
@ -22,7 +28,35 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Factorio::onFileEvent(const std::string& path, const filewatch::Event change_type) {
|
||||
std::cout << "file even " << filewatch::event_to_string(change_type) << " on '" << path << "'\n";
|
||||
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,24 +2,28 @@
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include <FileWatch.hpp>
|
||||
#include "./factorio_log_parser.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Factorio : public RegistryMessageModelEventI {
|
||||
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
|
||||
Contact3Registry& _cr;
|
||||
RegistryMessageModel& _rmm;
|
||||
|
||||
filewatch::FileWatch<std::string> _fw;
|
||||
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:
|
||||
void onFileEvent(const std::string& path, const filewatch::Event change_type);
|
||||
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;
|
||||
};
|
||||
|
||||
|
27
src/factorio_log_parser.cpp
Normal file
27
src/factorio_log_parser.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "./factorio_log_parser.hpp"
|
||||
|
||||
#include "./log_parse.hpp"
|
||||
|
||||
FactorioLogParser::FactorioLogParser(void) :
|
||||
_fw("test.txt", [this](const auto& path, const auto event){ this->onFileEvent(path, event);})
|
||||
{
|
||||
}
|
||||
|
||||
FactorioLogParser::~FactorioLogParser(void) {
|
||||
}
|
||||
|
||||
void FactorioLogParser::onFileEvent(const std::string& path, const filewatch::Event change_type) {
|
||||
std::cout << "file even " << filewatch::event_to_string(change_type) << " on '" << path << "'\n";
|
||||
|
||||
// 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"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
87
src/factorio_log_parser.hpp
Normal file
87
src/factorio_log_parser.hpp
Normal file
@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/util/event_provider.hpp>
|
||||
|
||||
#include <FileWatch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
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:
|
||||
FactorioLogParser(void);
|
||||
virtual ~FactorioLogParser(void);
|
||||
|
||||
protected:
|
||||
void onFileEvent(const std::string& path, const filewatch::Event change_type);
|
||||
};
|
||||
|
@ -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