Skip to content

Commit

Permalink
hardcode some events (working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jun 12, 2024
1 parent d18ec4e commit a91b4d4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/factorio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#include <solanaceae/message3/components.hpp>
#include <solanaceae/contact/components.hpp>

void Factorio::sendToLinked(const std::string& message) {
for (const auto& h : _linked_contacts) {
if (!static_cast<bool>(h)) {
continue;
}

_rmm.sendText(h, message);
}
}

Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) :
_cr(cr),
_rmm(rmm),
Expand Down Expand Up @@ -57,21 +67,48 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) {

bool Factorio::onEvent(const FactorioLog::Events::Join& e) {
std::cout << "Factorio: event join " << e.player_name << "\n";

std::string message{e.player_name};
message += " joined";

sendToLinked(message);

return false;
}

bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n";

std::string message{e.player_name};
message += " left";

sendToLinked(message);

return false;
}

bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n";

std::string message{"<"};
message += e.player_name;
message += ">: ";
message += e.message;

sendToLinked(message);

return false;
}

bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n";

std::string message{e.player_name};
message += " died from ";
message += e.reason;

sendToLinked(message);

return false;
}

Expand All @@ -87,6 +124,13 @@ bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) {

bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
std::cout << "Factorio: event research finished " << e.name << "\n";

std::string message{"Research "};
message += e.name;
message += " finished!";

sendToLinked(message);

return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/factorio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEven

std::vector<Contact3Handle> _linked_contacts;

void sendToLinked(const std::string& message);

public:
Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp);
virtual ~Factorio(void);
Expand Down

0 comments on commit a91b4d4

Please sign in to comment.