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"
|
2023-09-25 18:00:34 -04:00
|
|
|
#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() {
|
2023-09-06 23:25:37 -04:00
|
|
|
World = nullptr;
|
|
|
|
|
ClassTangibleActor = nullptr;
|
2023-09-25 18:00:34 -04:00
|
|
|
Player = 0;
|
2023-09-07 23:50:49 -04:00
|
|
|
Near = IdView();
|
2023-09-06 23:25:37 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-25 14:25:24 -04:00
|
|
|
void UTangibleManager::Init(UWorld *world, UClass* tanact) {
|
2023-09-02 01:39:35 -04:00
|
|
|
World = world;
|
|
|
|
|
ClassTangibleActor = tanact;
|
2023-09-25 18:00:34 -04:00
|
|
|
Player = 0;
|
2023-09-07 23:50:49 -04:00
|
|
|
Near = IdView();
|
2023-09-02 01:39:35 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-25 18:00:34 -04:00
|
|
|
UTangibleComponent *UTangibleManager::GetTangible(int64 id) {
|
|
|
|
|
AActor **p = IdToActor.Find(id);
|
2023-09-02 01:43:44 -04:00
|
|
|
if (p == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
} else {
|
2023-09-25 18:00:34 -04:00
|
|
|
AActor* a = *p;
|
|
|
|
|
UTangibleComponent* comp = a->FindComponentByClass<UTangibleComponent>();
|
|
|
|
|
check(comp != nullptr);
|
|
|
|
|
return comp;
|
2023-09-02 01:43:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 18:00:34 -04:00
|
|
|
UTangibleComponent *UTangibleManager::MakeTangible(int64 id) {
|
|
|
|
|
AActor *& p = IdToActor.FindOrAdd(id);
|
2023-09-02 01:43:44 -04:00
|
|
|
if (p == nullptr) {
|
|
|
|
|
FActorSpawnParameters params;
|
2023-09-25 18:00:34 -04:00
|
|
|
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()));
|
2023-09-25 18:00:34 -04:00
|
|
|
// 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-02 01:43:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 14:25:24 -04:00
|
|
|
void UTangibleManager::DeleteTangible(int64 id) {
|
2023-09-02 01:43:44 -04:00
|
|
|
// IMPLEMENT ME
|
|
|
|
|
}
|
2023-09-07 23:50:49 -04:00
|
|
|
|
2023-09-25 14:25:24 -04:00
|
|
|
UTangibleManager::IdArray UTangibleManager::GetLive() {
|
2023-09-07 23:50:49 -04:00
|
|
|
IdArray result;
|
2023-09-25 18:00:34 -04:00
|
|
|
result.SetNum(IdToActor.Num());
|
2023-09-07 23:50:49 -04:00
|
|
|
int next = 0;
|
2023-09-25 18:00:34 -04:00
|
|
|
for (auto &pair : IdToActor) {
|
2023-09-07 23:50:49 -04:00
|
|
|
result[next++] = pair.Key;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2023-09-25 18:00:34 -04:00
|
|
|
}
|