feat: implement contact listeners

This commit is contained in:
2026-09-02 21:42:49 +02:00
parent 287e5c6885
commit d515a36403
20 changed files with 595 additions and 95 deletions
@@ -0,0 +1,45 @@
#include <components/TriggerLoggerComponent.h>
#include "spdlog/spdlog.h"
#include <destrum/ObjectModel/GameObject.h>
TriggerLoggerComponent::TriggerLoggerComponent(GameObject& parent)
: Component(parent, "TriggerLoggerComponent") {}
void TriggerLoggerComponent::OnTriggerEnter(GameObject* other) {
++triggerEnterCount;
lastOtherName = other ? other->GetName() : "null";
spdlog::info(
"TriggerLogger: ENTER {} -> {} (enters: {}, exits: {})",
GetGameObject()->GetName(),
lastOtherName,
triggerEnterCount,
triggerExitCount);
}
void TriggerLoggerComponent::OnTriggerExit(GameObject* other) {
++triggerExitCount;
lastOtherName = other ? other->GetName() : "null";
spdlog::info(
"TriggerLogger: EXIT {} -> {} (enters: {}, exits: {})",
GetGameObject()->GetName(),
lastOtherName,
triggerEnterCount,
triggerExitCount);
}
nlohmann::json TriggerLoggerComponent::Serialize() const {
return {
{"triggerEnterCount", triggerEnterCount},
{"triggerExitCount", triggerExitCount}
};
}
void TriggerLoggerComponent::Deserialize(const nlohmann::json& data) {
if (data.contains("triggerEnterCount")) {
triggerEnterCount = data.at("triggerEnterCount").get<int>();
}
if (data.contains("triggerExitCount")) {
triggerExitCount = data.at("triggerExitCount").get<int>();
}
}