-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathmain_WorldViewer.cpp
More file actions
165 lines (128 loc) · 4.23 KB
/
main_WorldViewer.cpp
File metadata and controls
165 lines (128 loc) · 4.23 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <memory>
#include <string>
#include "BsFPSCamera.h"
#include <Components/BsCCamera.h>
#include <Scene/BsPrefab.h>
#include <Scene/BsSceneObject.h>
#include <String/BsString.h>
#include <core.hpp>
#include <components/Character.hpp>
#include <components/CharacterAI.hpp>
#include <components/CharacterEventQueue.hpp>
#include <components/CharacterKeyboardInput.hpp>
#include <components/GameWorld.hpp>
#include <components/GameplayUI.hpp>
#include <components/Inventory.hpp>
#include <components/ThirdPersonCamera.hpp>
#include <components/UIInventory.hpp>
#include <exception/Throw.hpp>
#include <log/logging.hpp>
#include <original-content/OriginalGameFiles.hpp>
#include <original-content/VirtualFileSystem.hpp>
struct WorldViewerConfig : public REGoth::EngineConfig
{
virtual void registerCLIOptions(cxxopts::Options& opts) override
{
const std::string grp = "WorldViewer";
opts.add_option(grp, "w", "world", "Name of the world to load",
cxxopts::value<bs::String>(world), "[NAME]");
}
virtual void verifyCLIOptions() override
{
// Make sure that world is set.
if (world.empty())
{
REGOTH_THROW(InvalidStateException, "World cannot be empty.");
}
// Unify possible inputs.
bs::StringUtil::toUpperCase(world);
if (!bs::StringUtil::endsWith(world, ".ZEN"))
{
world += ".ZEN";
}
}
bs::String world;
};
class REGothWorldViewer : public REGoth::Engine
{
public:
REGothWorldViewer(std::unique_ptr<const WorldViewerConfig>&& config)
: mConfig{std::move(config)}
{
// pass
}
const WorldViewerConfig* config() const override
{
return mConfig.get();
}
void loadModPackages(const REGoth::OriginalGameFiles& /* files */) override
{
// using namespace REGoth;
// for (auto p : files.allModPackages())
// {
// REGOTH_LOG(Info, Uncategorized, "[WorldViewer] Loading Mod: " + p.toString());
// gVirtualFileSystem().loadPackage(p);
// }
// for (auto zen : gVirtualFileSystem().listByExtension(".ZEN"))
// {
// REGOTH_LOG(Info, Uncategorized, "[WorldViewer] Found ZEN: " + zen);
// }
}
void setupMainCamera() override
{
REGoth::Engine::setupMainCamera();
mThirdPersonCamera = mMainCamera->SO()->addComponent<REGoth::ThirdPersonCamera>();
}
void setupScene() override
{
using namespace REGoth;
const bs::String SAVEGAME = "WorldViewer-" + config()->world;
bs::HPrefab worldPrefab = GameWorld::load(SAVEGAME);
HGameWorld world;
if (!worldPrefab)
{
world = GameWorld::importZEN(config()->world);
HCharacter hero = world->insertCharacter("PC_HERO", world->getWorldStartpoint()->getName());
hero->useAsHero();
hero->SO()->addComponent<CharacterKeyboardInput>(world);
// bs::HSceneObject diegoSO = world->insertCharacter("PC_THIEF", "WP_INTRO_FALL3")->SO();
world->runInitScripts();
REGOTH_LOG(Info, Uncategorized, "[WorldViewer] Saving world...");
world->save(SAVEGAME);
REGOTH_LOG(Info, Uncategorized, "[WorldViewer] Done!");
}
else
{
bs::HSceneObject worldSO = worldPrefab->instantiate();
world = worldSO->getComponent<GameWorld>();
}
bs::HSceneObject heroSO = world->SO()->findChild("PC_HERO");
if (!heroSO)
{
REGOTH_THROW(InvalidStateException, "Expected PC_HERO in world");
}
HCharacter hero = heroSO->getComponent<Character>();
mThirdPersonCamera->follow(hero);
REGoth::GameplayUI::createGlobal(mMainCamera);
auto inventory = hero->SO()->getComponent<Inventory>();
inventory->giveItem("ITFOAPPLE");
inventory->giveItem("ITFOAPPLE");
inventory->giveItem("ITFOAPPLE");
inventory->giveItem("ITFOAPPLE");
inventory->giveItem("ITFOAPPLE");
inventory->giveItem("ITARSCROLLSHRINK");
inventory->giveItem("ITARSCROLLSHRINK");
gGameplayUI()->inventoryUI()->setViewedInventory(inventory);
gGameplayUI()->setTargetCharacter(hero);
}
protected:
REGoth::HThirdPersonCamera mThirdPersonCamera;
private:
std::unique_ptr<const WorldViewerConfig> mConfig;
};
int main(int argc, char** argv)
{
auto config = REGoth::parseArguments<WorldViewerConfig>(argc, argv);
REGothWorldViewer engine{std::move(config)};
return REGoth::runEngine(engine);
}