* Prune empty code files * delete file * Restore * refactor * fix warnings * Fix tasks * Add diag * tweak * Log load times * changelog
118 lines
3.5 KiB
Plaintext
118 lines
3.5 KiB
Plaintext
import "LoadingMessages.bs"
|
|
|
|
' TODO:P2 Add a "logQueue" field to the scene, and push it to the logger later when playlet-lib is loaded
|
|
' Alternatively, just log to the console and the known log file in cachefs
|
|
' TODO:P2 log the playlet-lib load status and load speed to the log queue
|
|
function Init() as void
|
|
m.scene = m.top.getScene()
|
|
m.top.backgroundColor = "#242424FF"
|
|
m.top.backgroundURI = ""
|
|
|
|
m.loadingIndicator = m.top.findNode("LoadingIndicator")
|
|
m.global.addFields({
|
|
loadingIndicator: m.loadingIndicator
|
|
})
|
|
|
|
m.loadingIndicator.visible = true
|
|
m.loadingIndicator.message = GetLoadingMessage()
|
|
|
|
m.playletLibUrls = GetPlayletLibUrls()
|
|
m.playletLibUrlIndex = 0
|
|
|
|
LoadPlayletLib()
|
|
end function
|
|
|
|
function GetPlayletLibUrls() as object
|
|
#if DEBUG
|
|
debug = { type: "debug", link: ReadManifestValue("playlet_lib_debug_url") }
|
|
return [debug]
|
|
#else
|
|
savedUrls = GetPlayletLibUrlsFromRegistry()
|
|
if savedUrls <> invalid
|
|
m.shouldClearRegistryOnLoadFail = true
|
|
return savedUrls
|
|
end if
|
|
|
|
github = { type: "github", link: ReadManifestValue("playlet_lib_remote_url") }
|
|
embedded = { type: "embedded", link: ReadManifestValue("playlet_lib_embedded_url") }
|
|
return [github, embedded]
|
|
#end if
|
|
end function
|
|
|
|
function LoadPlayletLib() as void
|
|
if m.playletLibUrlIndex >= m.playletLibUrls.Count()
|
|
m.loadingIndicator.visible = false
|
|
if m.shouldClearRegistryOnLoadFail = true
|
|
DeleteRegistryKey("playlet_lib_urls", "Playlet")
|
|
end if
|
|
ShowPlayletLibLoadErrorDialog()
|
|
return
|
|
end if
|
|
|
|
RemoveComponentLibrary()
|
|
uri = m.playletLibUrls[m.playletLibUrlIndex].link
|
|
LoadComponentLibrary(uri)
|
|
end function
|
|
|
|
function OnLoadStatusChanged() as void
|
|
libUrl = m.playletLibUrls[m.playletLibUrlIndex]
|
|
if m.lib.loadStatus = "ready"
|
|
RemoveComponentLibrary()
|
|
' bs:disable-next-line LINT3012
|
|
?"Playlet lib loaded from " libUrl.link " in " m.timer.TotalMilliseconds().ToStr() "ms"
|
|
m.timer = invalid
|
|
m.scene.playletLibLoadedUrl = libUrl
|
|
container = m.scene.findNode("MainSceneContainer")
|
|
container.createChild("PlayletLib:MainScene")
|
|
return
|
|
end if
|
|
|
|
if m.lib.loadStatus = "failed"
|
|
' bs:disable-next-line LINT3012
|
|
?"Playlet lib failed to load from " libUrl.link
|
|
' Try next url
|
|
m.playletLibUrlIndex += 1
|
|
LoadPlayletLib()
|
|
end if
|
|
end function
|
|
|
|
function RemoveComponentLibrary() as void
|
|
if m.lib = invalid
|
|
return
|
|
end if
|
|
|
|
m.lib.unobserveField("loadStatus")
|
|
m.scene.removeChild(m.lib)
|
|
m.lib = invalid
|
|
end function
|
|
|
|
function LoadComponentLibrary(uri as string)
|
|
m.timer = CreateObject("roTimespan")
|
|
m.timer.mark()
|
|
|
|
m.lib = m.scene.createChild("ComponentLibrary")
|
|
' bs:disable-next-line NO_OBSERVE_STRING_CALLBACK
|
|
m.lib.observeField("loadStatus", "OnLoadStatusChanged")
|
|
' bs:disable-next-line LINT3012
|
|
?"Loading Playlet lib from " uri
|
|
m.lib.uri = uri
|
|
end function
|
|
|
|
function ShowPlayletLibLoadErrorDialog()
|
|
message = [
|
|
"Could not load Playlet component library from any of the following urls:",
|
|
]
|
|
|
|
bulletText = []
|
|
for each url in m.playletLibUrls
|
|
bulletText.push("[" + url.type + "] " + url.link)
|
|
end for
|
|
|
|
bottomText = [
|
|
"Please restart Playlet.",
|
|
"If the problem persist, contact Playlet authors."
|
|
]
|
|
|
|
ShowErrorDialog(message, bulletText, bottomText)
|
|
end function
|