1
1
#include " ./factorio.hpp"
2
- #include " factorio_log_parser.hpp"
2
+
3
+ #include < solanaceae/util/config_model.hpp>
4
+ #include < solanaceae/util/utils.hpp>
3
5
4
6
#include < solanaceae/message3/components.hpp>
5
7
#include < solanaceae/contact/components.hpp>
6
8
7
- Factorio::Factorio (Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
9
+ Factorio::Factorio (ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
8
10
_cr(cr),
9
11
_rmm(rmm),
10
12
_flp(flp)
11
13
{
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
+
12
39
_rmm.subscribe (this , RegistryMessageModel_Event::message_construct);
13
40
14
41
_flp.subscribe (this , FactorioLogParser_Event::join);
@@ -29,42 +56,42 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) {
29
56
}
30
57
31
58
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 " ;
33
60
return false ;
34
61
}
35
62
36
63
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 " ;
38
65
return false ;
39
66
}
40
67
41
68
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 " ;
43
70
return false ;
44
71
}
45
72
46
73
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 " ;
48
75
return false ;
49
76
}
50
77
51
78
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 " ;
53
80
return false ;
54
81
}
55
82
56
83
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 " ;
58
85
return false ;
59
86
}
60
87
61
88
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 " ;
63
90
return false ;
64
91
}
65
92
66
93
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 " ;
68
95
return false ;
69
96
}
70
97
0 commit comments