mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 12:33:17 +01:00
Implement ride music objects and refactor
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "FootpathItemObject.h"
|
||||
#include "FootpathObject.h"
|
||||
#include "LargeSceneryObject.h"
|
||||
#include "MusicObject.h"
|
||||
#include "Object.h"
|
||||
#include "ObjectLimits.h"
|
||||
#include "ObjectList.h"
|
||||
@@ -44,6 +45,7 @@ struct IFileDataRetriever
|
||||
{
|
||||
virtual ~IFileDataRetriever() = default;
|
||||
virtual std::vector<uint8_t> GetData(std::string_view path) const abstract;
|
||||
virtual ObjectAsset GetAsset(std::string_view path) const abstract;
|
||||
};
|
||||
|
||||
class FileSystemDataRetriever : public IFileDataRetriever
|
||||
@@ -59,19 +61,27 @@ public:
|
||||
|
||||
std::vector<uint8_t> GetData(std::string_view path) const override
|
||||
{
|
||||
auto absolutePath = Path::Combine(_basePath, std::string(path).c_str());
|
||||
auto absolutePath = Path::Combine(_basePath, path);
|
||||
return File::ReadAllBytes(absolutePath);
|
||||
}
|
||||
|
||||
ObjectAsset GetAsset(std::string_view path) const override
|
||||
{
|
||||
auto absolutePath = Path::Combine(_basePath, path);
|
||||
return ObjectAsset(absolutePath);
|
||||
}
|
||||
};
|
||||
|
||||
class ZipDataRetriever : public IFileDataRetriever
|
||||
{
|
||||
private:
|
||||
const std::string _path;
|
||||
const IZipArchive& _zipArchive;
|
||||
|
||||
public:
|
||||
ZipDataRetriever(const IZipArchive& zipArchive)
|
||||
: _zipArchive(zipArchive)
|
||||
ZipDataRetriever(std::string_view path, const IZipArchive& zipArchive)
|
||||
: _path(path)
|
||||
, _zipArchive(zipArchive)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,6 +89,11 @@ public:
|
||||
{
|
||||
return _zipArchive.GetFileData(path);
|
||||
}
|
||||
|
||||
ObjectAsset GetAsset(std::string_view path) const override
|
||||
{
|
||||
return ObjectAsset(_path, path);
|
||||
}
|
||||
};
|
||||
|
||||
class ReadObjectContext : public IReadObjectContext
|
||||
@@ -137,6 +152,15 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
ObjectAsset GetAsset(std::string_view path) override
|
||||
{
|
||||
if (_fileDataRetriever != nullptr)
|
||||
{
|
||||
return _fileDataRetriever->GetAsset(path);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void LogWarning(ObjectError code, const utf8* text) override
|
||||
{
|
||||
_wasWarning = true;
|
||||
@@ -314,6 +338,9 @@ namespace ObjectFactory
|
||||
case ObjectType::Station:
|
||||
result = std::make_unique<StationObject>(entry);
|
||||
break;
|
||||
case ObjectType::Music:
|
||||
result = std::make_unique<MusicObject>(entry);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid object type");
|
||||
}
|
||||
@@ -348,6 +375,8 @@ namespace ObjectFactory
|
||||
return ObjectType::TerrainEdge;
|
||||
if (s == "station")
|
||||
return ObjectType::Station;
|
||||
if (s == "music")
|
||||
return ObjectType::Music;
|
||||
return ObjectType::None;
|
||||
}
|
||||
|
||||
@@ -366,7 +395,7 @@ namespace ObjectFactory
|
||||
|
||||
if (jRoot.is_object())
|
||||
{
|
||||
auto fileDataRetriever = ZipDataRetriever(*archive);
|
||||
auto fileDataRetriever = ZipDataRetriever(path, *archive);
|
||||
return CreateObjectFromJson(objectRepository, jRoot, &fileDataRetriever);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user