From 53c7c3775fae0810b0831297b50aab1b0a1ef4e0 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 17 Mar 2024 01:53:46 +1100 Subject: Lua: new Image userdata (& cursor mod fix) --- source/base/StarAssets.cpp | 14 +++++++++++++- source/base/StarMemoryAssetSource.cpp | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'source/base') diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp index 784d686..6593d3d 100644 --- a/source/base/StarAssets.cpp +++ b/source/base/StarAssets.cpp @@ -19,6 +19,7 @@ #include "StarSha256.hpp" #include "StarDataStreamDevices.hpp" #include "StarLua.hpp" +#include "StarImageLuaBindings.hpp" #include "StarUtilityLuaBindings.hpp" namespace Star { @@ -120,6 +121,14 @@ Assets::Assets(Settings settings, StringList assetSources) { return String(assetBytes->ptr(), assetBytes->size()); }); + callbacks.registerCallback("image", [this](String const& path) -> Image { + auto assetImage = image(path); + if (assetImage->bytesPerPixel() == 3) + return assetImage->convert(PixelFormat::RGBA32); + else + return *assetImage; + }); + callbacks.registerCallback("scan", [this](Maybe const& a, Maybe const& b) -> StringList { return b ? scan(a.value(), *b) : scan(a.value()); }); @@ -211,6 +220,9 @@ Assets::Assets(Settings settings, StringList assetSources) { addSource(strf("{}::{}", sourcePath, groupName), memoryAssets); } } + // clear any caching that may have been trigered by load scripts as they may no longer be valid + m_framesSpecifications.clear(); + m_assetsCache.clear(); }; List> sources; @@ -884,7 +896,7 @@ Json Assets::readJson(String const& path) const { } } else if (patchJson.isType(Json::Type::Object)) { //Kae: Do a good ol' json merge instead if the .patch file is a Json object auto patchData = patchJson.toObject(); - result = jsonMerge(result, patchData); + result = jsonMergeNulling(result, patchData); } } return result; diff --git a/source/base/StarMemoryAssetSource.cpp b/source/base/StarMemoryAssetSource.cpp index 1176f5a..17e3749 100644 --- a/source/base/StarMemoryAssetSource.cpp +++ b/source/base/StarMemoryAssetSource.cpp @@ -52,7 +52,7 @@ IODevicePtr MemoryAssetSource::open(String const& path) { } ByteArrayPtr assetData; - StreamOffset assetPos; + StreamOffset assetPos = 0; String name; }; -- cgit v1.2.3