1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#pragma once
#include <libultraship.h>
#include <libultra/gbi.h>
#include "CoreMath.h"
#include <nlohmann/json.hpp>
// todo: Make this class AStaticMeshActor : public AActor
class StaticMeshActor {
public:
std::string Name;
FVector Pos;
IRotator Rot;
FVector Scale;
std::string Model;
int32_t* Collision;
bool bPendingDestroy = false;
StaticMeshActor(std::string name, FVector pos, IRotator rot, FVector scale, std::string model, int32_t* collision);
nlohmann::json to_json() const {
nlohmann::json j;
// Serialize each field of the class
j["Name"] = Name;
j["Position"] = {Pos.x, Pos.y, Pos.z}; // Assuming FVector has x, y, z fields
j["Rotation"] = {Rot.pitch, Rot.yaw, Rot.roll}; // Assuming IRotator has pitch, yaw, roll fields
j["Scale"] = {Scale.x, Scale.y, Scale.z}; // Assuming FVector has x, y, z fields
j["Model"] = Model;
// If Collision is not null, serialize it
if (Collision != nullptr) {
j["Collision"] = *Collision; // Serialize the value that Collision points to
} else {
j["Collision"] = nullptr; // Handle the case where Collision is nullptr
}
return j;
}
void from_json(const nlohmann::json& j) {
Name = j.at("Name").get<std::string>();
Pos = FVector(j.at("Position")[0].get<float>(), j.at("Position")[1].get<float>(), j.at("Position")[2].get<float>());
Rot.Set(j.at("Rotation")[0].get<uint16_t>(), j.at("Rotation")[1].get<uint16_t>(), j.at("Rotation")[2].get<uint16_t>());
Scale = FVector(j.at("Scale")[0].get<float>(), j.at("Scale")[1].get<float>(), j.at("Scale")[2].get<float>());
// Deserialize the Model string
Model = j.at("Model").get<std::string>();
// Check if Collision is present in the JSON and deserialize it
//if (j.contains("Collision") && !j["Collision"].is_null()) {
// If Collision is a valid value, allocate memory for it and assign the value
// Collision = new int32_t(j.at("Collision").get<int32_t>());
//} else {
// If Collision is not present or is null, set it to nullptr
Collision = nullptr;
//}
}
virtual void Draw();
virtual void Destroy();
};
|