Files
shadow-over-bishkek001/src/items/GameObjectLoader.h
T

78 lines
2.6 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <memory>
#include <unordered_map>
#include <map>
#include "external/nlohmann/json.hpp"
#include "TextModel.h"
#include "InteractiveObject.h"
#include "InteractiveObjectState.h"
#include "../CharacterState.h"
#include "../content/LocationDefinition.h"
namespace FRG {
class IGameServer;
class Character;
// Result of loading a static object list: unique objects keep their own mesh,
// repeated ones are merged into instanced batches.
struct StaticObjectSet {
std::unordered_map<std::string, LoadedGameObject> single;
std::vector<InstancedBatch> batches;
};
class GameObjectLoader {
public:
static StaticObjectSet createGameObjects(
const std::vector<GameObjectData>& definitions,
Renderer& renderer, const std::string& zipPath = "");
static std::vector<InteractiveObject> createInteractiveObjects(
const std::vector<InteractiveObjectData>& definitions,
Renderer& renderer,
std::unordered_map<std::string,
std::shared_ptr<InteractiveObjectState>>& states,
const std::string& zipPath = "");
static std::vector<std::unique_ptr<FRG::Character>> createNpcs(
const std::vector<NpcData>& definitions,
Renderer& renderer,
const std::unordered_map<std::string,
std::shared_ptr<CharacterState>>& states,
IGameServer& server, const std::string& locationId,
const std::string& zipPath);
static StaticObjectSet loadAndCreateGameObjects(
const std::string& jsonPath,
Renderer& renderer,
const std::string& zipPath = ""
);
static std::vector<InteractiveObject> loadAndCreateInteractiveObjects(
const std::string& jsonPath,
Renderer& renderer,
std::unordered_map<std::string, std::shared_ptr<InteractiveObjectState>>& states,
const std::string& zipPath = ""
);
static std::vector<std::unique_ptr<FRG::Character>> loadAndCreate_Npcs(
const std::string& jsonPath,
Renderer& renderer,
std::unordered_map<std::string, std::shared_ptr<CharacterState>>& states,
IGameServer& server,
const std::string& locationId,
const std::string& zipPath
);
static std::vector<NpcData> loadNpcsFromJson(const std::string& jsonPath, const std::string& zipPath = "");
static LoadedGameObject buildLoadedObject(const GameObjectData& data, Renderer& renderer, const std::string& zipPath);
private:
static nlohmann::json loadJson(const std::string& jsonPath, const std::string& zipPath);
static std::vector<GameObjectData> loadFromJson(const std::string& jsonPath, const std::string& zipPath);
static std::vector<InteractiveObjectData> loadInteractiveFromJson(const std::string& jsonPath, const std::string& zipPath);
};
} // namespace FRG