feat: implement contact listeners
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user