mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Create function to create object from file
This commit is contained in:
@@ -264,6 +264,28 @@ namespace OpenRCT2::ObjectFactory
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Object> CreateObjectFromFile(IObjectRepository& objectRepository, u8string_view path, bool loadImages)
|
||||
{
|
||||
std::unique_ptr<Object> object;
|
||||
auto extension = Path::GetExtension(path);
|
||||
if (String::iequals(extension, ".json"))
|
||||
{
|
||||
auto pathStr = u8string(path);
|
||||
object = ObjectFactory::CreateObjectFromJsonFile(objectRepository, pathStr, loadImages);
|
||||
}
|
||||
else if (String::iequals(extension, ".parkobj"))
|
||||
{
|
||||
object = ObjectFactory::CreateObjectFromZipFile(objectRepository, path, loadImages);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto pathStr = u8string(path);
|
||||
object = ObjectFactory::CreateObjectFromLegacyFile(objectRepository, pathStr.c_str(), loadImages);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
std::unique_ptr<Object> CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8* path, bool loadImages)
|
||||
{
|
||||
LOG_VERBOSE("CreateObjectFromLegacyFile(..., \"%s\")", path);
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace OpenRCT2
|
||||
|
||||
namespace OpenRCT2::ObjectFactory
|
||||
{
|
||||
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromFile(
|
||||
IObjectRepository& objectRepository, u8string_view path, bool loadImages);
|
||||
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromLegacyFile(
|
||||
IObjectRepository& objectRepository, const utf8* path, bool loadImages);
|
||||
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromLegacyData(
|
||||
|
||||
@@ -98,20 +98,7 @@ namespace OpenRCT2
|
||||
public:
|
||||
std::optional<ObjectRepositoryItem> Create([[maybe_unused]] int32_t language, const std::string& path) const override
|
||||
{
|
||||
std::unique_ptr<Object> object;
|
||||
auto extension = Path::GetExtension(path);
|
||||
if (String::iequals(extension, ".json"))
|
||||
{
|
||||
object = ObjectFactory::CreateObjectFromJsonFile(_objectRepository, path, false);
|
||||
}
|
||||
else if (String::iequals(extension, ".parkobj"))
|
||||
{
|
||||
object = ObjectFactory::CreateObjectFromZipFile(_objectRepository, path, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
object = ObjectFactory::CreateObjectFromLegacyFile(_objectRepository, path.c_str(), false);
|
||||
}
|
||||
std::unique_ptr<Object> object = ObjectFactory::CreateObjectFromFile(_objectRepository, path, false);
|
||||
|
||||
// All official DAT files have a JSON object counterpart. Avoid loading the obsolete .DAT versions,
|
||||
// which can happen if the user copies the official DAT objects to their custom content folder.
|
||||
@@ -271,18 +258,7 @@ namespace OpenRCT2
|
||||
std::unique_ptr<Object> LoadObject(const ObjectRepositoryItem* ori) override
|
||||
{
|
||||
Guard::ArgumentNotNull(ori, GUARD_LINE);
|
||||
|
||||
auto extension = Path::GetExtension(ori->Path);
|
||||
if (String::iequals(extension, ".json"))
|
||||
{
|
||||
return ObjectFactory::CreateObjectFromJsonFile(*this, ori->Path, !gOpenRCT2NoGraphics);
|
||||
}
|
||||
if (String::iequals(extension, ".parkobj"))
|
||||
{
|
||||
return ObjectFactory::CreateObjectFromZipFile(*this, ori->Path, !gOpenRCT2NoGraphics);
|
||||
}
|
||||
|
||||
return ObjectFactory::CreateObjectFromLegacyFile(*this, ori->Path.c_str(), !gOpenRCT2NoGraphics);
|
||||
return ObjectFactory::CreateObjectFromFile(*this, ori->Path, !gOpenRCT2NoGraphics);
|
||||
}
|
||||
|
||||
void RegisterLoadedObject(const ObjectRepositoryItem* ori, std::unique_ptr<Object>&& object) override
|
||||
|
||||
Reference in New Issue
Block a user