From b0e0c2d09d4a3e0d8631c3cff7a4b77469305e09 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 11 Dec 2023 08:19:15 -0500 Subject: [PATCH] Small refactor in bootstrap scene --- .../BootstrapScene/BootstrapScene.bs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/playlet-app/src/components/BootstrapScene/BootstrapScene.bs b/playlet-app/src/components/BootstrapScene/BootstrapScene.bs index a9d37503..20f2ae96 100644 --- a/playlet-app/src/components/BootstrapScene/BootstrapScene.bs +++ b/playlet-app/src/components/BootstrapScene/BootstrapScene.bs @@ -1,6 +1,7 @@ import "LoadingMessages.bs" function Init() as void + m.scene = m.top.getScene() m.top.backgroundColor = "0x242424FF" m.top.backgroundURI = "" @@ -46,14 +47,8 @@ function LoadPlayletLib() as void end if RemoveComponentLibrary() - m.lib = m.top.getScene().createChild("ComponentLibrary") - ' bs:disable-next-line NO_OBSERVE_STRING_CALLBACK - m.lib.observeField("loadStatus", "OnLoadStatusChanged") - uri = m.playletLibUrls[m.playletLibUrlIndex].link - ' bs:disable-next-line LINT3012 - ?"Loading Playlet lib from " uri - m.lib.uri = uri + LoadComponentLibrary(uri) end function function OnLoadStatusChanged() as void @@ -62,9 +57,8 @@ function OnLoadStatusChanged() as void RemoveComponentLibrary() ' bs:disable-next-line LINT3012 ?"Playlet lib loaded from " libUrl.link - scene = m.top.getScene() - scene.playletLibLoadedUrl = libUrl - container = scene.findNode("MainSceneContainer") + m.scene.playletLibLoadedUrl = libUrl + container = m.scene.findNode("MainSceneContainer") container.createChild("PlayletLib:MainScene") return end if @@ -83,11 +77,20 @@ function RemoveComponentLibrary() as void return end if - scene = m.top.getScene() - scene.removeChild(m.lib) + m.lib.unobserveField("loadStatus") + m.scene.removeChild(m.lib) m.lib = invalid end function +function LoadComponentLibrary(uri as string) + 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:",