Skip to content

Commit

Permalink
Updated SetImageSource()
Browse files Browse the repository at this point in the history
Now it loads the images into an internal dictionary, instead of
just keeping the object around.

SetImageSource() is now deprecated, but AddImageSource() and
ClearImageSource() have been added.

AddImageSource() adds a source worth of new images, but doesn't
forget existing ones.

ClearImageSource() just removes all images from the lookup.
  • Loading branch information
Montoli committed Apr 3, 2024
1 parent af9f102 commit 2995dde
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Data/Scripts/_RichTextMgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local propEmbeddedImageTemplate = script:GetCustomProperty("EmbeddedImageTemplat
local propEmbeddedPanelTemplate = script:GetCustomProperty("EmbeddedPanelTemplate")

local fonts = require(prop_FontLookup)
local images = nil
local imageList = {}

local API = {}
local allFontData = {}
Expand Down Expand Up @@ -437,9 +437,22 @@ end


function API.SetImageSource(obj)
images = obj
warn("RichText.SetImageSource is deprecated. Use AddImageSource instead.")
API.ClearImageSources()
API.AddImageSource(obj)
end

function API.ClearImageSources()
imageList = {}
end

function API.AddImageSource(obj)
for k,v in pairs(obj:GetCustomProperties()) do
imageList[k:upper()] = v
end
end


function API.ClearText(panel)
for k,v in pairs(panel:GetChildren()) do
if v.clientUserData.isText then
Expand All @@ -450,12 +463,12 @@ end


function ImageLookup(name)
if images ~= nil then
for k,v in pairs(images:GetCustomProperties()) do
if k:upper() == name:upper() then return v end
end
local result = imageList[name:upper()]
if result ~= nil then
return result
else
return name
end
return name
end

function AsColor(str)
Expand Down

0 comments on commit 2995dde

Please sign in to comment.