Create Component Library (#43)
* Move src under playlet-lib * Update configuration * Update script * Update script * Working version * Vs code config WIP * Package lock sync * Lint fix * Fix images * Reuse config files * Kind of a working setup * Lock node version * Rename scripts to tools * Fix build scripts, lib url system * Lint fix * rale * Fix args and web server * Load fallbacks and build script cleanups * Remove unused method * no message * no message * Remove generic message field * Lint fix * no message * Use loading indicator on main app * Add playlet lib version to settings --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
90df81df4b
commit
9d8a3d1cea
156 files changed
+3341
-213
No files matched your search
@@ -0,0 +1,103 @@
|
||||
function Init() as void
|
||||
m.top.backgroundColor = "0x242424FF"
|
||||
m.top.backgroundURI = ""
|
||||
|
||||
m.loadingIndicator = m.top.findNode("LoadingIndicator")
|
||||
m.loadingIndicator.visible = true
|
||||
m.global.addFields({
|
||||
loadingIndicator: m.loadingIndicator
|
||||
})
|
||||
|
||||
m.playletLibUrls = GetPlayletLibUrls()
|
||||
m.playletLibUrlIndex = 0
|
||||
|
||||
LoadPlayletLib()
|
||||
end function
|
||||
|
||||
function GetPlayletLibUrls() as object
|
||||
github = { type: "github", link: ReadManifestValue("playlet_lib_remote_url") }
|
||||
embedded = { type: "embedded", link: ReadManifestValue("playlet_lib_embedded_url") }
|
||||
registry = { type: "registry", link: ReadRegistryKey("playlet_lib_url", "Playlet") }
|
||||
|
||||
if IsDebugMode()
|
||||
return [embedded]
|
||||
end if
|
||||
|
||||
urls = []
|
||||
|
||||
if registry.link <> invalid
|
||||
urls.Push(registry)
|
||||
end if
|
||||
|
||||
urls.push(github)
|
||||
urls.push(embedded)
|
||||
|
||||
return urls
|
||||
end function
|
||||
|
||||
function LoadPlayletLib() as void
|
||||
if m.playletLibUrlIndex >= m.playletLibUrls.Count()
|
||||
m.loadingIndicator.visible = false
|
||||
ShowPlayletLibLoadErrorDialog()
|
||||
return
|
||||
end if
|
||||
|
||||
RemoveComponentLibrary()
|
||||
m.lib = m.top.getScene().createChild("ComponentLibrary")
|
||||
m.lib.observeField("loadStatus", "OnLoadStatusChanged")
|
||||
|
||||
uri = m.playletLibUrls[m.playletLibUrlIndex].link
|
||||
?"Loading Playlet lib from " uri
|
||||
m.lib.uri = uri
|
||||
end function
|
||||
|
||||
function OnLoadStatusChanged() as void
|
||||
uri = m.playletLibUrls[m.playletLibUrlIndex].link
|
||||
if m.lib.loadStatus = "ready"
|
||||
RemoveComponentLibrary()
|
||||
?"Playlet lib loaded from " uri
|
||||
scene = m.top.getScene()
|
||||
container = scene.findNode("MainSceneContainer")
|
||||
container.createChild("PlayletLib:MainScene")
|
||||
return
|
||||
end if
|
||||
|
||||
if m.lib.loadStatus = "failed"
|
||||
?"Playlet lib failed to load from " uri
|
||||
if m.playletLibUrls[m.playletLibUrlIndex].type = "registry"
|
||||
' Delete library url from registry since it failed
|
||||
DeleteRegistryKey("playlet_lib_url", "Playlet")
|
||||
end if
|
||||
' Try next url
|
||||
m.playletLibUrlIndex += 1
|
||||
LoadPlayletLib()
|
||||
end if
|
||||
end function
|
||||
|
||||
function RemoveComponentLibrary() as void
|
||||
if m.lib = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
scene = m.top.getScene()
|
||||
scene.removeChild(m.lib)
|
||||
m.lib = invalid
|
||||
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
|
||||
Reference in new issue
Block a user