Skip to content

Commit

Permalink
Auto stash before merge of "main" and "origin/main"
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Jul 30, 2024
1 parent 749af27 commit 189aec5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
85 changes: 85 additions & 0 deletions components/ScreenSaver/ScreenSaver.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import "pkg:/source/utilities/utilities.bs"

sub init()
m.layer1 = m.top.findNode("layer1")
m.layer2 = m.top.findNode("layer2")
m.layer3 = m.top.findNode("layer3")
end sub

sub setCover()
registerNewPoster(Rnd(15), 0)
registerNewPoster(Rnd(15), 1)
registerNewPoster(Rnd(15), 2)
registerNewPoster(Rnd(15), 3)
registerNewPoster(Rnd(15), 4)
registerNewPoster(Rnd(15), 5)
registerNewPoster(Rnd(15), 6)
registerNewPoster(Rnd(15), 7)
registerNewPoster(Rnd(15), 8)
registerNewPoster(Rnd(15), 9)
end sub

sub registerNewPoster(delay, posterIndex)
newPosterID = `newPoster${posterIndex}`
posterNode = m.top.findNode(newPosterID)
if isValid(posterNode) then return

horizPosition = Rnd(1080)
animationType = Rnd(4)

if animationType = 1
size = "200"
duration = 15
targetLayer = m.layer1
blendColor = "#FFFFFF"
else if animationType = 2
size = "100"
duration = 25
targetLayer = m.layer2
blendColor = "#AAAAAA"
else
size = "40"
duration = 40
targetLayer = m.layer3
blendColor = "#555555"
end if

newPoster = createObject("roSGNode", "Poster")
newPoster.id = `newPoster${posterIndex}`
newPoster.blendColor = blendColor
newPoster.width = size
newPoster.height = size
newPoster.uri = m.top.trackCover
newPoster.translation = `[${horizPosition}, -200]`
m.top.appendChild(newPoster)

newAnimation = createObject("roSGNode", "Animation")
newAnimation.duration = duration
newAnimation.repeat = "false"
newAnimation.easeFunction = "linear"
newAnimation.delay = delay

newVector2DFieldInterpolator = createObject("roSGNode", "Vector2DFieldInterpolator")
newVector2DFieldInterpolator.key = "[0.0, 1.0]"
newVector2DFieldInterpolator.keyValue = `[[${horizPosition}, -200], [${horizPosition}, 800]]`
newVector2DFieldInterpolator.fieldToInterp = `newPoster${posterIndex}.translation`

newAnimation.appendChild(newVector2DFieldInterpolator)
newAnimation.observeFieldScoped("state", "onAnimationStateChange")
targetLayer.appendChild(newAnimation)

newAnimation.control = "start"
end sub

sub onAnimationStateChange(msg)
animationNode = msg.getRoSGNode()
if LCase(animationNode.state) = "stopped"
posterID = animationNode.getChild(0).fieldToInterp.replace(".translation", "")
posterIndex = Right(posterID, 1)
posterNode = m.top.findNode(posterID)
if isValid(posterNode)
posterNode.getParent().removeChild(posterNode)
registerNewPoster(Rnd(10), posterIndex)
end if
end if
end sub
17 changes: 17 additions & 0 deletions components/ScreenSaver/ScreenSaver.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="ScreenSaver" extends="Group">
<children>
<Rectangle
color="0x000000FF"
height="800"
translation="[0,0]"
width="1280"
/>
<Group id="layer3" />
<Group id="layer2" />
<Group id="layer1" />
</children>
<interface>
<field id="trackCover" type="string" onChange="setCover" />
</interface>
</component>
17 changes: 16 additions & 1 deletion components/scenes/BaseScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub onResponseBodyLoaded()
tags: selectedRadioGenre,
groupby: "artist_id",
audioformat: "mp32",
imagesize: "100"
imagesize: "200"
}
m.getTracksTask.control = "RUN"
end sub
Expand Down Expand Up @@ -124,6 +124,7 @@ sub onStateChange()
m.nowPlaying.isPaused = LCase(m.audioPlayer.state) = "paused"

if LCase(m.audioPlayer.state) = "playing"
m.audioPlayer.disableScreenSaver = true
m.progressDialog.close = true

if m.nowPlaying.translation[1] <> 600
Expand All @@ -134,6 +135,11 @@ sub onStateChange()
m.nowPlaying.trackTitle = currentSong.title
m.nowPlaying.trackAlbum = currentSong.album
m.nowPlaying.trackCover = currentSong.FHDPosterUrl

screenSaver = m.top.findNode("screenSaver")
if isValid(screenSaver)
screenSaver.trackCover = currentSong.FHDPosterUrl
end if
return
end if

Expand All @@ -147,6 +153,7 @@ sub onStateChange()

' There are no more songs in the queue
if isEmpty(m.indexList)
m.audioPlayer.disableScreenSaver = false
m.hideNowPlayingAnimation.control = "start"
m.nowPlaying.trackArtist = ""
m.nowPlaying.trackTitle = ""
Expand Down Expand Up @@ -176,5 +183,13 @@ function onKeyEvent(key as string, press as boolean) as boolean
return true
end if

if LCase(key) = "up"
screenSaver = createObject("roSGNode", "ScreenSaver")
screenSaver.id = "screenSaver"
screenSaver.trackCover = m.audioPlayer.content.FHDPosterUrl
m.top.appendChild(screenSaver)
return true
end if

return false
end function
3 changes: 2 additions & 1 deletion components/scenes/BaseScene.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="BaseScene" extends="Scene">
<children>
<Audio id="audioPlayer" contentIsPlaylist="true" />
<Video id="audioPlayer" />
<Group id="content">
<RadioGrid
id="radioGrid"
Expand All @@ -17,6 +17,7 @@
translation="[50,450]"
text="Music created by JAMENDO members. Content provided by JAMENDO" />
<NowPlaying id="nowPlaying" translation="[0, 800]" />

<Animation id="showNowPlayingAnimation" duration="0.5" repeat="false">
<Vector2DFieldInterpolator key="[0.0, 1.0]" keyValue="[[0, 800], [0, 600]]"
fieldToInterp="nowPlaying.translation" />
Expand Down

0 comments on commit 189aec5

Please sign in to comment.