From b77519493d4ebc6420723c8758a27f25e0fab663 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sun, 10 Dec 2023 15:24:30 -0500 Subject: [PATCH] Feature/loading messages (#220) * Add loading message * Add messages and cache file * Lint fix --------- Co-authored-by: github-action linter --- CHANGELOG.md | 6 ++++ .../BootstrapScene/BootstrapScene.bs | 6 +++- .../BootstrapScene/LoadingMessages.bs | 29 +++++++++++++++++++ .../LoadingIndicator/LoadingIndicator.xml | 13 +++++++++ playlet-lib/src/components/MainScene.bs | 1 + .../src/components/MainScene.transpiled.brs | 1 + playlet-lib/src/config/loading-messages.json5 | 14 +++++++++ playlet-lib/src/source/utils/LoadingScreen.bs | 10 ++++++- 8 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 playlet-app/src/components/BootstrapScene/LoadingMessages.bs create mode 100644 playlet-lib/src/config/loading-messages.json5 diff --git a/CHANGELOG.md b/CHANGELOG.md index 68c23fec..10b6a13a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Loading message + ## [0.17.1] - 2023-12-08 ### Added diff --git a/playlet-app/src/components/BootstrapScene/BootstrapScene.bs b/playlet-app/src/components/BootstrapScene/BootstrapScene.bs index 7285c172..a9d37503 100644 --- a/playlet-app/src/components/BootstrapScene/BootstrapScene.bs +++ b/playlet-app/src/components/BootstrapScene/BootstrapScene.bs @@ -1,13 +1,17 @@ +import "LoadingMessages.bs" + 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.loadingIndicator.visible = true + m.loadingIndicator.message = GetLoadingMessage() + m.playletLibUrls = GetPlayletLibUrls() m.playletLibUrlIndex = 0 diff --git a/playlet-app/src/components/BootstrapScene/LoadingMessages.bs b/playlet-app/src/components/BootstrapScene/LoadingMessages.bs new file mode 100644 index 00000000..a417081f --- /dev/null +++ b/playlet-app/src/components/BootstrapScene/LoadingMessages.bs @@ -0,0 +1,29 @@ +function GetLoadingMessage() as string + messages = GetLoadingMessagesFromCache() + if messages = invalid or messages.count() = 0 + messages = [ + "Now loading Playlet...", + "One moment please...", + "Downloading the internet...", + "Unclogging the tubes...", + "Warming up the flux capacitor...", + "Loading, ehm, stuff...", + "Restoring quantum entanglement...", + "Searching for kitten videos...", + "One Mississippi... two Mississippi...", + "Checking the TV's extended warranty...", + "Deleting system32...", + "Updating: 3 hours 32 minutes remaining...", + ] + end if + index = Rnd(messages.count()) - 1 + return messages[index] +end function + +function GetLoadingMessagesFromCache() as object + messagesFile = ReadAsciiFile("cachefs:/loading_messages_v1.json") + if messagesFile = invalid or messagesFile = "" + return invalid + end if + return ParseJson(messagesFile) +end function diff --git a/playlet-app/src/components/LoadingIndicator/LoadingIndicator.xml b/playlet-app/src/components/LoadingIndicator/LoadingIndicator.xml index 9beaecb4..2df312f1 100644 --- a/playlet-app/src/components/LoadingIndicator/LoadingIndicator.xml +++ b/playlet-app/src/components/LoadingIndicator/LoadingIndicator.xml @@ -1,4 +1,7 @@ + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/MainScene.bs b/playlet-lib/src/components/MainScene.bs index 77f512d7..c262bb72 100644 --- a/playlet-lib/src/components/MainScene.bs +++ b/playlet-lib/src/components/MainScene.bs @@ -16,6 +16,7 @@ function MainSceneContainerChanged() HideLoadingScreen() InitEcpArgs() m.scene.signalBeacon("AppLaunchComplete") + CopyLoadingMessagesToCache() end function function StartWebServer() diff --git a/playlet-lib/src/components/MainScene.transpiled.brs b/playlet-lib/src/components/MainScene.transpiled.brs index ef408e6d..61a3eb0a 100644 --- a/playlet-lib/src/components/MainScene.transpiled.brs +++ b/playlet-lib/src/components/MainScene.transpiled.brs @@ -17,6 +17,7 @@ function MainSceneContainerChanged() HideLoadingScreen() InitEcpArgs() m.scene.signalBeacon("AppLaunchComplete") + CopyLoadingMessagesToCache() end function function StartWebServer() diff --git a/playlet-lib/src/config/loading-messages.json5 b/playlet-lib/src/config/loading-messages.json5 new file mode 100644 index 00000000..9259f3ae --- /dev/null +++ b/playlet-lib/src/config/loading-messages.json5 @@ -0,0 +1,14 @@ +[ + "Now loading Playlet...", + "One moment please...", + "Downloading the internet...", + "Unclogging the tubes...", + "Warming up the flux capacitor...", + "Loading, ehm, stuff...", + "Restoring quantum entanglement...", + "Searching for kitten videos...", + "One Mississippi... two Mississippi...", + "Checking the TV's extended warranty...", + "Deleting system32...", + "Updating: 3 hours 32 minutes remaining...", +] diff --git a/playlet-lib/src/source/utils/LoadingScreen.bs b/playlet-lib/src/source/utils/LoadingScreen.bs index 51ceb59a..b257b0ec 100644 --- a/playlet-lib/src/source/utils/LoadingScreen.bs +++ b/playlet-lib/src/source/utils/LoadingScreen.bs @@ -3,5 +3,13 @@ function ShowLoadingScreen() end function function HideLoadingScreen() - m.global.loadingIndicator.visible = false + loadingIndicator = m.global.loadingIndicator + loadingIndicator.visible = false + if loadingIndicator.hasField("message") + loadingIndicator.message = "" + end if +end function + +function CopyLoadingMessagesToCache() + CopyFile("libpkg:/config/loading-messages.json5", "cachefs:/loading_messages_v1.json") end function