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