Skip to content

Commit

Permalink
Add a check for missing resources in collection proxies. (#107)
Browse files Browse the repository at this point in the history
* Update monarch.lua

* Update monarch.lua

* Update monarch.lua
  • Loading branch information
SalavatR committed Jan 30, 2024
1 parent 4c6e26f commit 679482f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions monarch/monarch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ local function preload(screen)
screen.preloading = true
if screen.proxy then
log("preload() proxy")
local missing_resources = collectionproxy.missing_resources(screen.proxy)
if #missing_resources > 0 then
if M.has_missing_resources(screen.id) then
local error_message = ("preload() collection proxy %s is missing resources"):format(tostring(screen.id))
log(error_message)
screen.preloading = false
Expand Down Expand Up @@ -1131,6 +1130,20 @@ function M.preload(id, options, cb)
return true -- return true for legacy reasons (before queue existed)
end

--- Check if a screen has missing resources, always returns false for factory
-- @param id (string|hash) - Id of the screen to preload
function M.has_missing_resources(id)
assert(id, "You must provide a screen id")
id = tohash(id)
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))

local screen = screens[id]
if screen.proxy then
local missing_resources = collectionproxy.missing_resources(screen.proxy)
return #missing_resources > 0
end
return false
end

--- Unload a preloaded monarch screen
-- @param id (string|hash) - Id of the screen to unload
Expand Down

0 comments on commit 679482f

Please sign in to comment.