Skip to content

Commit d18ec4e

Browse files
committed
load linked contacts from config (not sending yet)
1 parent 7c3b867 commit d18ec4e

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

plugins/plugin_factorio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
4040
// static store, could be anywhere tho
4141
// construct with fetched dependencies
4242
g_flp = std::make_unique<FactorioLogParser>(*conf);
43-
g_f = std::make_unique<Factorio>(*cr, *rmm, *g_flp);
43+
g_f = std::make_unique<Factorio>(*conf, *cr, *rmm, *g_flp);
4444

4545
// register types
4646
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());

src/factorio.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
#include "./factorio.hpp"
2-
#include "factorio_log_parser.hpp"
2+
3+
#include <solanaceae/util/config_model.hpp>
4+
#include <solanaceae/util/utils.hpp>
35

46
#include <solanaceae/message3/components.hpp>
57
#include <solanaceae/contact/components.hpp>
68

7-
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
9+
Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
810
_cr(cr),
911
_rmm(rmm),
1012
_flp(flp)
1113
{
14+
// config
15+
for (const auto&& [contact_id, enabled] : conf.entries_bool("Factorio", "link_to_contact")) {
16+
//std::cout << "config id:" << contact_id << " e:" << enabled << "\n";
17+
18+
const auto id_vec = hex2bin(contact_id);
19+
20+
// search
21+
Contact3Handle h;
22+
auto view = _cr.view<Contact::Components::ID>();
23+
for (const auto c : view) {
24+
if (view.get<Contact::Components::ID>(c).data == id_vec) {
25+
h = Contact3Handle{_cr, c};
26+
std::cout << "Factorio: found contact for link.\n";
27+
break;
28+
}
29+
}
30+
if (!static_cast<bool>(h)) {
31+
// not found, create thin contact with just id
32+
h = {_cr, _cr.create()};
33+
h.emplace<Contact::Components::ID>(id_vec);
34+
std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n";
35+
}
36+
_linked_contacts.push_back(h);
37+
}
38+
1239
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
1340

1441
_flp.subscribe(this, FactorioLogParser_Event::join);
@@ -29,42 +56,42 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) {
2956
}
3057

3158
bool Factorio::onEvent(const FactorioLog::Events::Join& e) {
32-
std::cout << "F: event join " << e.player_name << "\n";
59+
std::cout << "Factorio: event join " << e.player_name << "\n";
3360
return false;
3461
}
3562

3663
bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
37-
std::cout << "F: event leave " << e.player_name << " " << e.reason << "\n";
64+
std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n";
3865
return false;
3966
}
4067

4168
bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
42-
std::cout << "F: event chat " << e.player_name << ": " << e.message << "\n";
69+
std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n";
4370
return false;
4471
}
4572

4673
bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
47-
std::cout << "F: event died " << e.player_name << ": " << e.reason << "\n";
74+
std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n";
4875
return false;
4976
}
5077

5178
bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) {
52-
std::cout << "F: event evolution " << e.evo << "\n";
79+
std::cout << "Factorio: event evolution " << e.evo << "\n";
5380
return false;
5481
}
5582

5683
bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) {
57-
std::cout << "F: event research started " << e.name << "\n";
84+
std::cout << "Factorio: event research started " << e.name << "\n";
5885
return false;
5986
}
6087

6188
bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
62-
std::cout << "F: event research finished " << e.name << "\n";
89+
std::cout << "Factorio: event research finished " << e.name << "\n";
6390
return false;
6491
}
6592

6693
bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) {
67-
std::cout << "F: event research cancelled " << e.name << "\n";
94+
std::cout << "Factorio: event research cancelled " << e.name << "\n";
6895
return false;
6996
}
7097

src/factorio.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
#include "./factorio_log_parser.hpp"
66

7+
#include <vector>
8+
9+
// fwd
10+
struct ConfigModelI;
11+
712
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
813
Contact3Registry& _cr;
914
RegistryMessageModel& _rmm;
1015
FactorioLogParser& _flp;
1116

17+
std::vector<Contact3Handle> _linked_contacts;
18+
1219
public:
13-
Factorio(Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
20+
Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
1421
virtual ~Factorio(void);
1522

1623
protected: // rmm

0 commit comments

Comments
 (0)