Files
integration/Source/Integration/TangibleManager.cpp

75 lines
1.9 KiB
C++
Raw Normal View History

2023-09-02 01:33:11 -04:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "TangibleManager.h"
2023-09-15 00:01:41 -04:00
#include "TangibleInterface.h"
#include "IntegrationGameState.h"
#include "TangibleComponent.h"
2023-09-15 00:01:41 -04:00
#include "DebugPrint.h"
2023-09-02 01:33:11 -04:00
2023-09-15 00:01:41 -04:00
using namespace DebugPrint;
2023-09-02 01:33:11 -04:00
2023-09-25 14:25:24 -04:00
UTangibleManager::UTangibleManager() {
World = nullptr;
ClassTangibleActor = nullptr;
Player = 0;
Near = IdView();
}
2023-09-25 14:25:24 -04:00
void UTangibleManager::Init(UWorld *world, UClass* tanact) {
World = world;
ClassTangibleActor = tanact;
Player = 0;
Near = IdView();
}
UTangibleComponent *UTangibleManager::GetTangible(int64 id) {
AActor **p = IdToActor.Find(id);
if (p == nullptr) {
return nullptr;
} else {
AActor* a = *p;
UTangibleComponent* comp = a->FindComponentByClass<UTangibleComponent>();
check(comp != nullptr);
return comp;
}
}
UTangibleComponent *UTangibleManager::MakeTangible(int64 id) {
AActor *& p = IdToActor.FindOrAdd(id);
if (p == nullptr) {
FActorSpawnParameters params;
FVector location(0, 0, 0);
FRotator rotation(0, 0, 0);
UWorld* w = GetWorld();
AActor* a = w->SpawnActor(ClassTangibleActor, &location, &rotation, params);
2023-09-15 00:01:41 -04:00
check(a != nullptr);
2023-09-15 13:28:18 -04:00
check(a->GetClass()->ImplementsInterface(UlxTangibleInterface::StaticClass()));
// Insert a TangibleComponent into the actor.
UActorComponent* ac = a->AddComponentByClass(UTangibleComponent::StaticClass(), false, FTransform::Identity, false);
UTangibleComponent* tc = Cast<UTangibleComponent>(ac);
check(tc != nullptr);
tc->Init(this, a, id);
p = a;
return tc;
} else {
UTangibleComponent* comp = p->FindComponentByClass<UTangibleComponent>();
check(comp != nullptr);
return comp;
}
}
2023-09-25 14:25:24 -04:00
void UTangibleManager::DeleteTangible(int64 id) {
// IMPLEMENT ME
}
2023-09-25 14:25:24 -04:00
UTangibleManager::IdArray UTangibleManager::GetLive() {
IdArray result;
result.SetNum(IdToActor.Num());
int next = 0;
for (auto &pair : IdToActor) {
result[next++] = pair.Key;
}
return result;
}