Files
Destrum/lightkeeper/src/components/TriggerLoggerComponent.cpp
T

37 lines
1.2 KiB
C++

#include <components/TriggerLoggerComponent.h>
#include "spdlog/spdlog.h"
#include <destrum/ObjectModel/GameObject.h>
#include <destrum/Serialization/Reflect.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);
}
void TriggerLoggerComponent::Reflect(FieldVisitor& v) {
v.Field("triggerEnterCount", triggerEnterCount, {.readOnly = true});
v.Field("triggerExitCount", triggerExitCount, {.readOnly = true});
v.Field("lastOtherName", lastOtherName, {.readOnly = true, .transient = true});
}