load linked contacts from config (not sending yet)
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousDelivery / linux-ubuntu (push) Failing after 21s
ContinuousIntegration / linux (push) Successful in 22s

This commit is contained in:
Green Sky 2024-06-12 21:11:12 +02:00
parent 7c3b867c7c
commit d18ec4e1ca
No known key found for this signature in database
3 changed files with 46 additions and 12 deletions

View File

@ -40,7 +40,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>(*conf);
g_f = std::make_unique<Factorio>(*cr, *rmm, *g_flp);
g_f = std::make_unique<Factorio>(*conf, *cr, *rmm, *g_flp);
// register types
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());

View File

@ -1,14 +1,41 @@
#include "./factorio.hpp"
#include "factorio_log_parser.hpp"
#include <solanaceae/util/config_model.hpp>
#include <solanaceae/util/utils.hpp>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/contact/components.hpp>
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
_cr(cr),
_rmm(rmm),
_flp(flp)
{
// config
for (const auto&& [contact_id, enabled] : conf.entries_bool("Factorio", "link_to_contact")) {
//std::cout << "config id:" << contact_id << " e:" << enabled << "\n";
const auto id_vec = hex2bin(contact_id);
// search
Contact3Handle h;
auto view = _cr.view<Contact::Components::ID>();
for (const auto c : view) {
if (view.get<Contact::Components::ID>(c).data == id_vec) {
h = Contact3Handle{_cr, c};
std::cout << "Factorio: found contact for link.\n";
break;
}
}
if (!static_cast<bool>(h)) {
// not found, create thin contact with just id
h = {_cr, _cr.create()};
h.emplace<Contact::Components::ID>(id_vec);
std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n";
}
_linked_contacts.push_back(h);
}
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
_flp.subscribe(this, FactorioLogParser_Event::join);
@ -29,42 +56,42 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) {
}
bool Factorio::onEvent(const FactorioLog::Events::Join& e) {
std::cout << "F: event join " << e.player_name << "\n";
std::cout << "Factorio: event join " << e.player_name << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
std::cout << "F: event leave " << e.player_name << " " << e.reason << "\n";
std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
std::cout << "F: event chat " << e.player_name << ": " << e.message << "\n";
std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
std::cout << "F: event died " << e.player_name << ": " << e.reason << "\n";
std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) {
std::cout << "F: event evolution " << e.evo << "\n";
std::cout << "Factorio: event evolution " << e.evo << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) {
std::cout << "F: event research started " << e.name << "\n";
std::cout << "Factorio: event research started " << e.name << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
std::cout << "F: event research finished " << e.name << "\n";
std::cout << "Factorio: event research finished " << e.name << "\n";
return false;
}
bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) {
std::cout << "F: event research cancelled " << e.name << "\n";
std::cout << "Factorio: event research cancelled " << e.name << "\n";
return false;
}

View File

@ -4,13 +4,20 @@
#include "./factorio_log_parser.hpp"
#include <vector>
// fwd
struct ConfigModelI;
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
Contact3Registry& _cr;
RegistryMessageModel& _rmm;
FactorioLogParser& _flp;
std::vector<Contact3Handle> _linked_contacts;
public:
Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
virtual ~Factorio(void);
protected: // rmm