Compare commits
No commits in common. "70317ab4db5719b3b14170073d6e7d2f01c4bcbb" and "06bd55c165d4d28f112d9b05c8d67364f94ce36a" have entirely different histories.
70317ab4db
...
06bd55c165
@ -3,12 +3,10 @@
|
||||
#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";
|
||||
@ -36,11 +34,9 @@ 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_flp);
|
||||
g_f = std::make_unique<Factorio>(*cr, *rmm);
|
||||
|
||||
// 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";
|
||||
@ -54,7 +50,6 @@ 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,8 +5,6 @@ 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,24 +1,18 @@
|
||||
#include "./factorio.hpp"
|
||||
#include "factorio_log_parser.hpp"
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
|
||||
#include "./log_parse.hpp"
|
||||
|
||||
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) :
|
||||
_cr(cr),
|
||||
_rmm(rmm),
|
||||
_flp(flp)
|
||||
_fw("test.txt", [this](const auto& path, const auto event){ this->onFileEvent(path, event);})
|
||||
{
|
||||
_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);
|
||||
|
||||
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
|
||||
}
|
||||
|
||||
Factorio::~Factorio(void) {
|
||||
@ -28,35 +22,7 @@ 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;
|
||||
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";
|
||||
}
|
||||
|
||||
|
@ -2,28 +2,24 @@
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include "./factorio_log_parser.hpp"
|
||||
#include <FileWatch.hpp>
|
||||
|
||||
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
|
||||
#include <string>
|
||||
|
||||
class Factorio : public RegistryMessageModelEventI {
|
||||
Contact3Registry& _cr;
|
||||
RegistryMessageModel& _rmm;
|
||||
FactorioLogParser& _flp;
|
||||
|
||||
filewatch::FileWatch<std::string> _fw;
|
||||
|
||||
public:
|
||||
Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
|
||||
Factorio(Contact3Registry& cr, RegistryMessageModel& rmm);
|
||||
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;
|
||||
protected:
|
||||
void onFileEvent(const std::string& path, const filewatch::Event change_type);
|
||||
};
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
#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"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,87 +0,0 @@
|
||||
#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,7 +7,6 @@ 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