mirror of https://github.com/OpenRCT2/OpenRCT2.git
Get basic relative .png loading
This commit is contained in:
parent
9aef466b9b
commit
580f1baff2
|
@ -736,8 +736,12 @@ void FASTCALL gfx_draw_sprite_raw_masked_software(rct_drawpixelinfo *dpi, sint32
|
|||
return;
|
||||
}
|
||||
|
||||
assert(imgMask->flags & G1_FLAG_BMP);
|
||||
assert(imgColour->flags & G1_FLAG_BMP);
|
||||
// Only BMP format is supported for masking
|
||||
if (!(imgMask->flags & G1_FLAG_BMP) || !(imgColour->flags & G1_FLAG_BMP))
|
||||
{
|
||||
gfx_draw_sprite_software(dpi, colourImage, x, y, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dpi->zoom_level != 0) {
|
||||
// TODO: Implement other zoom levels (probably not used though)
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include "../common.h"
|
||||
#include "../core/Json.hpp"
|
||||
#include "ImageTable.h"
|
||||
|
@ -122,6 +124,7 @@ interface IReadObjectContext
|
|||
|
||||
virtual IObjectRepository& GetObjectRepository() abstract;
|
||||
virtual bool ShouldLoadImages() abstract;
|
||||
virtual std::vector<uint8> GetData(const std::string_view& path) abstract;
|
||||
|
||||
virtual void LogWarning(uint32 code, const utf8 * text) abstract;
|
||||
virtual void LogError(uint32 code, const utf8 * text) abstract;
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
#pragma endregion
|
||||
|
||||
#include "../core/Console.hpp"
|
||||
#include "../core/File.h"
|
||||
#include "../core/FileStream.hpp"
|
||||
#include "../core/Json.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/MemoryStream.h"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../core/Zip.h"
|
||||
#include "../OpenRCT2.h"
|
||||
|
@ -46,6 +48,7 @@ private:
|
|||
|
||||
std::string _objectName;
|
||||
bool _loadImages;
|
||||
std::string _basePath;
|
||||
bool _wasWarning = false;
|
||||
bool _wasError = false;
|
||||
|
||||
|
@ -53,10 +56,11 @@ public:
|
|||
bool WasWarning() const { return _wasWarning; }
|
||||
bool WasError() const { return _wasError; }
|
||||
|
||||
ReadObjectContext(IObjectRepository& objectRepository, const std::string &objectName, bool loadImages)
|
||||
ReadObjectContext(IObjectRepository& objectRepository, const std::string &objectName, bool loadImages, const std::string& basePath)
|
||||
: _objectRepository(objectRepository),
|
||||
_objectName(objectName),
|
||||
_loadImages(loadImages)
|
||||
_loadImages(loadImages),
|
||||
_basePath(basePath)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -70,6 +74,12 @@ public:
|
|||
return _loadImages;
|
||||
}
|
||||
|
||||
std::vector<uint8> GetData(const std::string_view& path) override
|
||||
{
|
||||
auto absolutePath = Path::Combine(_basePath, path.data());
|
||||
return File::ReadAllBytes(absolutePath);
|
||||
}
|
||||
|
||||
void LogWarning(uint32 code, const utf8 * text) override
|
||||
{
|
||||
_wasWarning = true;
|
||||
|
@ -93,7 +103,7 @@ public:
|
|||
|
||||
namespace ObjectFactory
|
||||
{
|
||||
static Object * CreateObjectFromJson(IObjectRepository& objectRepository, const json_t * jRoot);
|
||||
static Object * CreateObjectFromJson(IObjectRepository& objectRepository, const json_t * jRoot, const std::string_view& basePath);
|
||||
|
||||
static void ReadObjectLegacy(Object * object, IReadObjectContext * context, IStream * stream)
|
||||
{
|
||||
|
@ -133,7 +143,7 @@ namespace ObjectFactory
|
|||
log_verbose(" size: %zu", chunk->GetLength());
|
||||
|
||||
auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength());
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless);
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless, "");
|
||||
ReadObjectLegacy(result, &readContext, &chunkStream);
|
||||
if (readContext.WasError())
|
||||
{
|
||||
|
@ -159,7 +169,7 @@ namespace ObjectFactory
|
|||
utf8 objectName[DAT_NAME_LENGTH + 1];
|
||||
object_entry_get_name_fixed(objectName, sizeof(objectName), entry);
|
||||
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless);
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless, "");
|
||||
auto chunkStream = MemoryStream(data, dataSize);
|
||||
ReadObjectLegacy(result, &readContext, &chunkStream);
|
||||
|
||||
|
@ -250,7 +260,7 @@ namespace ObjectFactory
|
|||
throw JsonException(&jsonLoadError);
|
||||
}
|
||||
|
||||
return CreateObjectFromJson(objectRepository, jRoot);
|
||||
return CreateObjectFromJson(objectRepository, jRoot, "");
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
@ -270,7 +280,7 @@ namespace ObjectFactory
|
|||
try
|
||||
{
|
||||
auto jRoot = Json::ReadFromFile(path.c_str());
|
||||
result = CreateObjectFromJson(objectRepository, jRoot);
|
||||
result = CreateObjectFromJson(objectRepository, jRoot, Path::GetDirectory(path));
|
||||
json_decref(jRoot);
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
|
@ -283,7 +293,7 @@ namespace ObjectFactory
|
|||
return result;
|
||||
}
|
||||
|
||||
Object * CreateObjectFromJson(IObjectRepository& objectRepository, const json_t * jRoot)
|
||||
Object * CreateObjectFromJson(IObjectRepository& objectRepository, const json_t * jRoot, const std::string_view& basePath)
|
||||
{
|
||||
log_verbose("CreateObjectFromJson(...)");
|
||||
|
||||
|
@ -309,7 +319,7 @@ namespace ObjectFactory
|
|||
memcpy(entry.name, originalName.c_str(), minLength);
|
||||
|
||||
result = CreateObject(entry);
|
||||
auto readContext = ReadObjectContext(objectRepository, id, !gOpenRCT2Headless);
|
||||
auto readContext = ReadObjectContext(objectRepository, id, !gOpenRCT2Headless, basePath.data());
|
||||
result->ReadJson(&readContext, jRoot);
|
||||
if (readContext.WasError())
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../drawing/ImageImporter.h"
|
||||
#include "../interface/Cursors.h"
|
||||
#include "../localisation/Language.h"
|
||||
#include "../PlatformEnvironment.h"
|
||||
|
@ -35,6 +36,7 @@
|
|||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
|
||||
namespace ObjectJsonHelpers
|
||||
{
|
||||
|
@ -316,6 +318,27 @@ namespace ObjectJsonHelpers
|
|||
result = LoadObjectImages(context, name, range);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
auto imageData = context->GetData(s);
|
||||
auto image = Imaging::ReadFromBuffer(imageData, IMAGE_FORMAT::PNG_32);
|
||||
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image, 0, 0, ImageImporter::IMPORT_FLAGS::RLE);
|
||||
|
||||
result.push_back(importResult.Element);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
auto msg = String::StdFormat("Unable to load image '%s': %s", s.c_str(), e.what());
|
||||
context->LogWarning(OBJECT_ERROR_BAD_IMAGE_TABLE, msg.c_str());
|
||||
|
||||
rct_g1_element emptyg1 = { 0 };
|
||||
result.push_back(emptyg1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue