SpaghettiKart
Loading...
Searching...
No Matches
SpawnParams.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <optional>
5#include <string>
6#include <nlohmann/json.hpp>
7#include "CoreMath.h"
8
9extern "C" {
10#include "common_structs.h"
11}
12
13// Helper function to handle std::optional deserialization
14template <typename T>
15void get_optional_to(const nlohmann::json& j, const char* key, std::optional<T>& opt_val) {
16 if (j.contains(key) && !j.at(key).is_null()) {
17 opt_val = j.at(key).get<T>();
18 }
19}
20
21// Helper function to handle std::optional serialization
22template <typename T>
23void set_optional_from(nlohmann::json& j, const char* key, const std::optional<T>& opt_val) {
24 if (opt_val.has_value()) {
25 j[key] = opt_val.value();
26 }
27}
28
29// Used to save and load all game actors to the scene file
31 std::string Name; // Must use format mk:actor_name for stock game, mymodname:myactorname for mods
32 std::optional<int16_t> Type; // OObject type (ex. Emperor penguin, sliding penguin) or literal actor type for AActors
33 std::optional<int16_t> Behaviour;
34 std::optional<std::string> Skin;
35
36 std::optional<FVector> Location;
37 std::optional<IRotator> Rotation; // int16_t
38 std::optional<FVector> Scale;
39 std::optional<FVector> Velocity; // Used by some AActors
40 std::optional<FVector2D> PatrolStart; // OCrab
41 std::optional<FVector2D> PatrolEnd; // OCrab & Hedgehog
42 std::optional<IPathSpan> PathSpan; // Cheep Cheep
43
44 // Thwomps
45 std::optional<int16_t> PrimAlpha; // Thwomp
46 std::optional<uint16_t> BoundingBoxSize;
47
48 // Boos
49 std::optional<uint32_t> Count; // vehicles
50 std::optional<IPathSpan> LeftExitSpan; // Disable boo
51 std::optional<IPathSpan> TriggerSpan; // Activate boos
52 std::optional<IPathSpan> RightExitSpan; // Disable boo
53
54
55 // Vehicles
56 std::optional<uint32_t> PathIndex; // 0-3 Place vehicle this path
57 std::optional<uint32_t> PathPoint; // Path point index
58 std::optional<bool> Bool; // train tender
59 std::optional<bool> Bool2;
60 std::optional<float> Speed; // Train
61 std::optional<float> SpeedB; // cars, trucks, buses, etc.
62 std::optional<FVector> FVec2;
63
64 std::optional<RGBA8> Colour;
65 std::optional<RGBA8> Colour2;
66 std::optional<RGBA8> Colour3;
67 std::optional<RGBA8> Colour4;
68
69 void from_json(const nlohmann::json& j) {
70 j.at("Name").get_to(Name);
71 get_optional_to(j, "Type", Type);
72 get_optional_to(j, "Behaviour", Behaviour);
73 get_optional_to(j, "Skin", Skin);
74 get_optional_to(j, "Location", Location);
75 get_optional_to(j, "Rotation", Rotation);
76 get_optional_to(j, "Scale", Scale);
77 get_optional_to(j, "Velocity", Velocity);
78 get_optional_to(j, "PatrolStart", PatrolStart);
79 get_optional_to(j, "PatrolEnd", PatrolEnd);
80 get_optional_to(j, "PathSpan", PathSpan);
81 get_optional_to(j, "PrimAlpha", PrimAlpha);
82 get_optional_to(j, "BoundingBoxSize", BoundingBoxSize);
83 get_optional_to(j, "Count", Count);
84 get_optional_to(j, "LeftExitSpan", LeftExitSpan);
85 get_optional_to(j, "TriggerSpan", TriggerSpan);
86 get_optional_to(j, "RightExitSpan", RightExitSpan);
87 get_optional_to(j, "PathIndex", PathIndex);
88 get_optional_to(j, "PathPoint", PathPoint);
89 get_optional_to(j, "Bool", Bool);
90 get_optional_to(j, "Bool2", Bool2);
91 get_optional_to(j, "Speed", Speed);
92 get_optional_to(j, "SpeedB", SpeedB);
93 get_optional_to(j, "FVec2", FVec2);
94 get_optional_to(j, "Colour", Colour);
95 get_optional_to(j, "Colour2", Colour2);
96 get_optional_to(j, "Colour3", Colour3);
97 get_optional_to(j, "Colour4", Colour4);
98 }
99
100 nlohmann::json to_json() const {
101 nlohmann::json j;
102 j["Name"] = Name;
103 set_optional_from(j, "Type", Type);
104 set_optional_from(j, "Behaviour", Behaviour);
105 set_optional_from(j, "Skin", Skin);
106 set_optional_from(j, "Location", Location);
107 set_optional_from(j, "Rotation", Rotation);
108 set_optional_from(j, "Scale", Scale);
109 set_optional_from(j, "Velocity", Velocity);
110 set_optional_from(j, "PatrolStart", PatrolStart);
111 set_optional_from(j, "PatrolEnd", PatrolEnd);
112 set_optional_from(j, "PathSpan", PathSpan);
113 set_optional_from(j, "PrimAlpha", PrimAlpha);
114 set_optional_from(j, "BoundingBoxSize", BoundingBoxSize);
115 set_optional_from(j, "Count", Count);
116 set_optional_from(j, "LeftExitSpan", LeftExitSpan);
117 set_optional_from(j, "TriggerSpan", TriggerSpan);
118 set_optional_from(j, "RightExitSpan", RightExitSpan);
119 set_optional_from(j, "PathIndex", PathIndex);
120 set_optional_from(j, "PathPoint", PathPoint);
121 set_optional_from(j, "Bool", Bool);
122 set_optional_from(j, "Bool2", Bool2);
123 set_optional_from(j, "Speed", Speed);
124 set_optional_from(j, "SpeedB", SpeedB);
125 set_optional_from(j, "FVec2", FVec2);
126 set_optional_from(j, "Colour", Colour);
127 set_optional_from(j, "Colour2", Colour2);
128 set_optional_from(j, "Colour3", Colour3);
129 set_optional_from(j, "Colour4", Colour4);
130 return j;
131 }
132};
void set_optional_from(nlohmann::json &j, const char *key, const std::optional< T > &opt_val)
Definition SpawnParams.h:23
void get_optional_to(const nlohmann::json &j, const char *key, std::optional< T > &opt_val)
Definition SpawnParams.h:15
#define j
Definition SpawnParams.h:30
std::optional< RGBA8 > Colour3
Definition SpawnParams.h:66
std::optional< IRotator > Rotation
Definition SpawnParams.h:37
std::optional< bool > Bool2
Definition SpawnParams.h:59
std::optional< float > Speed
Definition SpawnParams.h:60
std::optional< FVector > Velocity
Definition SpawnParams.h:39
std::string Name
Definition SpawnParams.h:31
std::optional< IPathSpan > LeftExitSpan
Definition SpawnParams.h:50
std::optional< RGBA8 > Colour
Definition SpawnParams.h:64
std::optional< IPathSpan > RightExitSpan
Definition SpawnParams.h:52
std::optional< uint32_t > PathIndex
Definition SpawnParams.h:56
void from_json(const nlohmann::json &j)
Definition SpawnParams.h:69
std::optional< IPathSpan > PathSpan
Definition SpawnParams.h:42
std::optional< uint16_t > BoundingBoxSize
Definition SpawnParams.h:46
nlohmann::json to_json() const
Definition SpawnParams.h:100
std::optional< FVector > Scale
Definition SpawnParams.h:38
std::optional< FVector2D > PatrolStart
Definition SpawnParams.h:40
std::optional< FVector2D > PatrolEnd
Definition SpawnParams.h:41
std::optional< int16_t > Type
Definition SpawnParams.h:32
std::optional< float > SpeedB
Definition SpawnParams.h:61
std::optional< RGBA8 > Colour4
Definition SpawnParams.h:67
std::optional< bool > Bool
Definition SpawnParams.h:58
std::optional< uint32_t > PathPoint
Definition SpawnParams.h:57
std::optional< FVector > Location
Definition SpawnParams.h:36
std::optional< uint32_t > Count
Definition SpawnParams.h:49
std::optional< FVector > FVec2
Definition SpawnParams.h:62
std::optional< int16_t > Behaviour
Definition SpawnParams.h:33
std::optional< IPathSpan > TriggerSpan
Definition SpawnParams.h:51
std::optional< int16_t > PrimAlpha
Definition SpawnParams.h:45
std::optional< std::string > Skin
Definition SpawnParams.h:34
std::optional< RGBA8 > Colour2
Definition SpawnParams.h:65