From 679482f84d5ca6ae7d58a9576b99cc3ebebdb46c Mon Sep 17 00:00:00 2001 From: SalavatR Date: Tue, 30 Jan 2024 16:03:37 +0600 Subject: [PATCH] Add a check for missing resources in collection proxies. (#107) * Update monarch.lua * Update monarch.lua * Update monarch.lua --- monarch/monarch.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 85200cd..26aa590 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -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 @@ -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