Mario Kart 64
Loading...
Searching...
No Matches
SceneManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <libultraship/libultraship.h>
4#include "CoreMath.h"
6#include <optional>
7#include <nlohmann/json.hpp>
8
9namespace Editor {
10 void SaveLevel();
11 void LoadLevel(Track* track, std::string sceneFile);
12 void Load_AddStaticMeshActor(const nlohmann::json& actorJson);
13 void SetSceneFile(std::shared_ptr<Ship::Archive> archive, std::string sceneFile);
14 void LoadMinimap(Track* track, std::string filePath);
15 void SetDefaultMinimap(Track* track);
16
17 void SaveActors(nlohmann::json& actorList);
18 void SaveStaticMeshActors(nlohmann::json& actorList);
19 void SaveTour(nlohmann::json& tour);
20
21 void LoadProps(Track* track, nlohmann::json& data);
22 void LoadActors(Track* track, nlohmann::json& data);
23 void LoadStaticMeshActors(Track* track, nlohmann::json& data);
24 void LoadTour(Track* track, nlohmann::json& data);
25
26 void SpawnActors(std::vector<std::pair<std::string, SpawnParams>> spawnList);
27
28 extern std::shared_ptr<Ship::Archive> CurrentArchive; // This is used to retrieve and write the scene data file
29 extern std::string SceneFile;
30
31
32 inline nlohmann::json ToJson(const FVector& v) {
33 return {
34 {"x", v.x},
35 {"y", v.y},
36 {"z", v.z}
37 };
38 }
39
40 inline nlohmann::json ToJson(const TourCamera::KeyFrame& kf) {
41 return {
42 {"Pos", ToJson(kf.Pos)},
43 {"LookAt", ToJson(kf.LookAt)},
44 {"Duration", kf.Duration}
45 };
46 }
47
48 inline nlohmann::json ToJson(const TourCamera::CameraShot& shot) {
49 nlohmann::json j;
50 j["StartPos"] = ToJson(shot.Pos);
51 j["StartLookAt"] = ToJson(shot.LookAt);
52
53 // KeyFrames
54 nlohmann::json keyframes = nlohmann::json::array();
55 for (const auto& kf : shot.Frames) {
56 keyframes.push_back(ToJson(kf));
57 }
58 j["KeyFrames"] = keyframes;
59
60 return j;
61 }
62
63 inline FVector FromJsonVec(const nlohmann::json& j) {
64 FVector v{};
65 if (j.contains("x")) v.x = j["x"].get<float>();
66 if (j.contains("y")) v.y = j["y"].get<float>();
67 if (j.contains("z")) v.z = j["z"].get<float>();
68 return v;
69 }
70
71 inline TourCamera::KeyFrame FromJsonKeyFrame(const nlohmann::json& j) {
73 if (j.contains("Pos")) kf.Pos = FromJsonVec(j["Pos"]);
74 if (j.contains("LookAt")) kf.LookAt = FromJsonVec(j["LookAt"]);
75 if (j.contains("Duration")) kf.Duration = j["Duration"].get<float>();
76 return kf;
77 }
78
79 inline TourCamera::CameraShot FromJsonCameraShot(const nlohmann::json& j) {
81 if (j.contains("StartPos")) shot.Pos = FromJsonVec(j["StartPos"]);
82 if (j.contains("StartLookAt")) shot.LookAt = FromJsonVec(j["StartLookAt"]);
83
84 if (j.contains("KeyFrames") && j["KeyFrames"].is_array()) {
85 for (const auto& kfJson : j["KeyFrames"]) {
86 shot.Frames.push_back(FromJsonKeyFrame(kfJson));
87 }
88 }
89
90 return shot;
91 }
92}
#define j
Definition Collision.cpp:16
std::shared_ptr< Ship::Archive > CurrentArchive
Definition SceneManager.cpp:32
void LoadActors(Track *track, nlohmann::json &data)
Definition SceneManager.cpp:279
void LoadLevel(Track *track, std::string sceneFile)
Definition SceneManager.cpp:88
void LoadStaticMeshActors(Track *track, nlohmann::json &data)
Definition SceneManager.cpp:296
void LoadProps(Track *track, nlohmann::json &data)
Definition SceneManager.cpp:265
void Load_AddStaticMeshActor(const nlohmann::json &actorJson)
Definition SceneManager.cpp:126
FVector FromJsonVec(const nlohmann::json &j)
Definition SceneManager.h:63
void SaveStaticMeshActors(nlohmann::json &actorList)
Definition SceneManager.cpp:249
void SaveLevel()
Definition SceneManager.cpp:35
void SetSceneFile(std::shared_ptr< Ship::Archive > archive, std::string sceneFile)
Definition SceneManager.cpp:135
std::string SceneFile
Definition SceneManager.cpp:33
void SaveActors(nlohmann::json &actorList)
Definition SceneManager.cpp:182
void SaveTour(nlohmann::json &tour)
Definition SceneManager.cpp:255
nlohmann::json ToJson(const FVector &v)
Definition SceneManager.h:32
TourCamera::CameraShot FromJsonCameraShot(const nlohmann::json &j)
Definition SceneManager.h:79
TourCamera::KeyFrame FromJsonKeyFrame(const nlohmann::json &j)
Definition SceneManager.h:71
void SetDefaultMinimap(Track *track)
Definition SceneManager.cpp:175
void LoadTour(Track *track, nlohmann::json &data)
Definition SceneManager.cpp:309
void LoadMinimap(Track *track, std::string filePath)
Definition SceneManager.cpp:141
void SpawnActors(std::vector< std::pair< std::string, SpawnParams > > spawnList)
Definition CoreMath.h:30
float x
Definition CoreMath.h:31
float z
Definition CoreMath.h:31
float y
Definition CoreMath.h:31
Definition TourCamera.h:48
FVector LookAt
Definition TourCamera.h:50
FVector Pos
Definition TourCamera.h:49
std::vector< KeyFrame > Frames
Definition TourCamera.h:51
Definition TourCamera.h:41
FVector LookAt
Definition TourCamera.h:43
f32 Duration
Definition TourCamera.h:44
FVector Pos
Definition TourCamera.h:42