Kotlin 2.0 migration

This commit is contained in:
minjaesong
2024-07-05 01:25:36 +09:00
parent 69571b6a3f
commit 68ed16aa5a
37 changed files with 161 additions and 386 deletions

View File

@@ -13,8 +13,6 @@
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-controllers-desktop-2.2.1.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-controllers-desktop-2.2.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/GetCpuName.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/GetCpuName.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jxinput-1.0.0.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/jxinput-1.0.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar" path-in-jar="/" />
<element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-csv-1.8.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-csv-1.8.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/prtree.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/prtree.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/Terrarum_Joise.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/Terrarum_Joise.jar" path-in-jar="/" />
@@ -85,9 +83,9 @@
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-desktop.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-desktop.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-x86_64.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-x86_64.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/TerranVirtualDisk.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/TerranVirtualDisk.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.24/kotlin-stdlib-jdk8-1.9.24.jar" path-in-jar="/" /> <element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.24/kotlin-stdlib-1.9.24.jar" path-in-jar="/" /> <element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.24/kotlin-stdlib-jdk7-1.9.24.jar" path-in-jar="/" /> <element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/2.0.0/kotlin-stdlib-jdk7-2.0.0.jar" path-in-jar="/" />
</root> </root>
</artifact> </artifact>
</component> </component>

8
.idea/kotlinc.xml generated
View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Kotlin2JvmCompilerArguments"> <component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="21" /> <option name="jvmTarget" value="1.8" />
</component> </component>
<component name="KotlinCommonCompilerArguments"> <component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.9" /> <option name="apiVersion" value="2.0" />
<option name="languageVersion" value="1.9" /> <option name="languageVersion" value="2.0" />
</component> </component>
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.23-release-779" /> <option name="version" value="2.0.0" />
</component> </component>
</project> </project>

View File

@@ -1,14 +1,23 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="KotlinJavaRuntime" type="repository"> <library name="KotlinJavaRuntime" type="repository">
<properties include-transitive-deps="false" maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.0" /> <properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.0" />
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/2.0.0/kotlin-stdlib-jdk7-2.0.0.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/2.0.0/kotlin-stdlib-jdk7-2.0.0-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/2.0.0/kotlin-stdlib-jdk8-2.0.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/2.0.0/kotlin-stdlib-jdk7-2.0.0-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>

View File

@@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="jetbrains.kotlin.reflect" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-reflect:1.8.22" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-reflect/1.8.22/kotlin-reflect-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.22/kotlin-stdlib-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.22/kotlin-stdlib-common-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="jetbrains.kotlin.test" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.22/kotlin-stdlib-jdk8-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.22/kotlin-stdlib-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.22/kotlin-stdlib-common-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.22/kotlin-stdlib-jdk7-1.8.22.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.22/kotlin-stdlib-jdk8-1.8.22-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.22/kotlin-stdlib-1.8.22-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.22/kotlin-stdlib-common-1.8.22-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.22/kotlin-stdlib-jdk7-1.8.22-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.22/kotlin-stdlib-jdk8-1.8.22-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.22/kotlin-stdlib-1.8.22-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.22/kotlin-stdlib-common-1.8.22-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.22/kotlin-stdlib-jdk7-1.8.22-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="jetbrains.kotlin.test1" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-test:1.8.22" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-test/1.8.22/kotlin-test-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.22/kotlin-stdlib-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.22/kotlin-stdlib-common-1.8.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -13,12 +13,9 @@
<orderEntry type="library" scope="PROVIDED" name="TerrarumSansBitmap" level="project" /> <orderEntry type="library" scope="PROVIDED" name="TerrarumSansBitmap" level="project" />
<orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx" level="project" /> <orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx" level="project" />
<orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx.backend.lwjgl3" level="project" /> <orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx.backend.lwjgl3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.reflect" level="project" />
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test" level="project" />
<orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" /> <orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" />
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test1" level="project" />
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" /> <orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
<orderEntry type="library" name="TerranVirtualDisk" level="project" /> <orderEntry type="library" name="TerranVirtualDisk" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component> </component>
</module> </module>

View File

@@ -7,13 +7,12 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test" level="project" />
<orderEntry type="module" module-name="TerrarumBuild" scope="PROVIDED" /> <orderEntry type="module" module-name="TerrarumBuild" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx" level="project" /> <orderEntry type="library" scope="PROVIDED" name="badlogicgames.gdx" level="project" />
<orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" /> <orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" />
<orderEntry type="library" scope="PROVIDED" name="TerrarumSansBitmap" level="project" /> <orderEntry type="library" scope="PROVIDED" name="TerrarumSansBitmap" level="project" />
<orderEntry type="library" scope="PROVIDED" name="apache.commons.math3" level="project" /> <orderEntry type="library" scope="PROVIDED" name="apache.commons.math3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test1" level="project" />
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" /> <orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component> </component>
</module> </module>

View File

@@ -94,8 +94,11 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
private var currentlySelectedAlbum: AlbumProp? = null private var currentlySelectedAlbum: AlbumProp? = null
/** Returns the internal playlist of the MusicGovernor */ /** Returns the internal playlist of the MusicGovernor */
private val songsInGovernor: List<MusicContainer> private val songsInGovernorrrrrrrrrr: List<MusicContainer>
get() = ingame.backgroundMusicPlayer.extortField<List<MusicContainer>>("songs")!! get() = ingame.musicStreamer.extortField<List<MusicContainer>>("songs")!!
// the value must be "latched" to stay consistent
private fun getCurrentPlaylist() = MusicService.currentPlaylist
/*private val shouldPlayerBeDisabled: Boolean /*private val shouldPlayerBeDisabled: Boolean
get() { get() {
@@ -107,7 +110,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
* is recommended as an ingame interaction may cancel the playback from the playlist from the MusicPlayer * is recommended as an ingame interaction may cancel the playback from the playlist from the MusicPlayer
* (e.g. interacting with a jukebox) */ * (e.g. interacting with a jukebox) */
private val internalPlaylistName: String private val internalPlaylistName: String
get() = ingame.backgroundMusicPlayer.playlistName get() = ingame.musicStreamer.playlistName
fun registerPlaylist(path: String, fileToName: JsonValue?, shuffled: Boolean, diskJockeyingMode: String): TerrarumMusicPlaylist { fun registerPlaylist(path: String, fileToName: JsonValue?, shuffled: Boolean, diskJockeyingMode: String): TerrarumMusicPlaylist {
fun String.isNum(): Boolean { fun String.isNum(): Boolean {
@@ -120,7 +123,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
} }
} }
val playlist = ingame.backgroundMusicPlayer.queueDirectory(path, shuffled, diskJockeyingMode, false) { filename -> val playlist = ingame.musicStreamer.queueDirectory(path, shuffled, diskJockeyingMode, false) { filename ->
fileToName?.get(filename).let { fileToName?.get(filename).let {
if (it == null) if (it == null)
filename.substringBeforeLast('.').replace('_', ' ').split(" ").map { it.capitalize() }.let { filename.substringBeforeLast('.').replace('_', ' ').split(" ").map { it.capitalize() }.let {
@@ -136,19 +139,19 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
} }
} }
ingame.backgroundMusicPlayer.addMusicStartHook { music -> ingame.musicStreamer.addMusicStartHook { music ->
setMusicName(music.name) setMusicName(music.name)
if (mode <= MODE_PLAYING) if (mode <= MODE_PLAYING)
transitionRequest = MODE_PLAYING transitionRequest = MODE_PLAYING
} }
ingame.backgroundMusicPlayer.addMusicStopHook { music -> ingame.musicStreamer.addMusicStopHook { music ->
setIntermission() setIntermission()
if (mode <= MODE_PLAYING) if (mode <= MODE_PLAYING)
transitionRequest = MODE_IDLE transitionRequest = MODE_IDLE
} }
setPlaylistDisplayVars(songsInGovernor) setPlaylistDisplayVars(playlist)
return playlist return playlist
} }
@@ -189,6 +192,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
override fun updateImpl(delta: Float) { override fun updateImpl(delta: Float) {
val transactionLocked = MusicService.transactionLocked val transactionLocked = MusicService.transactionLocked
val currentPlaylist = getCurrentPlaylist()
// process transition request // process transition request
if (transitionRequest != null) { if (transitionRequest != null) {
@@ -348,7 +352,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
// prev song // prev song
if (mode < MODE_SHOW_LIST) { if (mode < MODE_SHOW_LIST) {
MusicService.playPrevSongInPlaylist { MusicService.playPrevSongInPlaylist {
ingame.backgroundMusicPlayer.startMusic(this) // required for "intermittent" mode ingame.musicStreamer.startMusic(this) // required for "intermittent" mode
iHitTheStopButton = false iHitTheStopButton = false
stopRequested = false stopRequested = false
} }
@@ -401,7 +405,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
// next song // next song
if (mode < MODE_SHOW_LIST) { if (mode < MODE_SHOW_LIST) {
MusicService.playNextSongInPlaylist { MusicService.playNextSongInPlaylist {
ingame.backgroundMusicPlayer.startMusic(this) // required for "intermittent" mode ingame.musicStreamer.startMusic(this) // required for "intermittent" mode
iHitTheStopButton = false iHitTheStopButton = false
stopRequested = false stopRequested = false
} }
@@ -442,26 +446,27 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
// make playlist clicking (change song within the playlist) work // make playlist clicking (change song within the playlist) work
else if (listViewPanelScroll == 1f && mouseOnList != null) { else if (listViewPanelScroll == 1f && mouseOnList != null) {
val index = playlistScroll + mouseOnList!! val index = playlistScroll + mouseOnList!!
val list = songsInGovernor if (currentPlaylist != null) {
if (index < list.size) { if (index < currentPlaylist.musicList.size) {
// if selected song != currently playing // if selected song != currently playing
if (App.audioMixer.musicTrack.currentTrack == null || list[index] != App.audioMixer.musicTrack.currentTrack) { if (App.audioMixer.musicTrack.currentTrack == null || currentPlaylist.musicList[index] != App.audioMixer.musicTrack.currentTrack) {
// FIXME the olde way -- must be replaced with one that utilises MusicService // FIXME the olde way -- must be replaced with one that utilises MusicService
// rebuild playlist // rebuild playlist
//ingame.backgroundMusicPlayer.queueIndexFromPlaylist(index) //ingame.backgroundMusicPlayer.queueIndexFromPlaylist(index)
// fade out // fade out
/*App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) { /*App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
if (!shouldPlayerBeDisabled) { if (!shouldPlayerBeDisabled) {
ingame.backgroundMusicPlayer.startMusic(this) // required for "intermittent" mode ingame.backgroundMusicPlayer.startMusic(this) // required for "intermittent" mode
iHitTheStopButton = false
stopRequested = false
}
}*/
MusicService.playNthSongInPlaylist(index) {
ingame.musicStreamer.startMusic(this) // required for "intermittent" mode
iHitTheStopButton = false iHitTheStopButton = false
stopRequested = false stopRequested = false
} }
}*/
MusicService.playNthSongInPlaylist(index) {
ingame.backgroundMusicPlayer.startMusic(this) // required for "intermittent" mode
iHitTheStopButton = false
stopRequested = false
} }
} }
} }
@@ -474,7 +479,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
if (index < list.size) { if (index < list.size) {
// if selected album is not the same album currently playing, queue that album immediately // if selected album is not the same album currently playing, queue that album immediately
// (navigating into the selected album involves too much complication :p) // (navigating into the selected album involves too much complication :p)
if (ingame.backgroundMusicPlayer.playlistSource != albumsList[index].canonicalPath) { if (ingame.musicStreamer.playlistSource != albumsList[index].canonicalPath) {
// FIXME the olde way -- must be replaced with one that utilises MusicService // FIXME the olde way -- must be replaced with one that utilises MusicService
// fade out // fade out
/*App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) { /*App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
@@ -510,10 +515,10 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
ingame.backgroundMusicPlayer.stopMusic(this) ingame.backgroundMusicPlayer.stopMusic(this)
} }
} }
else*/ if (ingame.backgroundMusicPlayer.playCaller is PlaysMusic && !jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) { else*/ if (ingame.musicStreamer.playCaller is PlaysMusic && !jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) {
jukeboxStopMonitorAlert = true jukeboxStopMonitorAlert = true
val interval = ingame.backgroundMusicPlayer.getRandomMusicInterval() val interval = ingame.musicStreamer.getRandomMusicInterval()
ingame.backgroundMusicPlayer.stopMusic(this, false, interval) ingame.musicStreamer.stopMusic(this, false, interval)
} }
else if (App.audioMixer.musicTrack.isPlaying) { else if (App.audioMixer.musicTrack.isPlaying) {
jukeboxStopMonitorAlert = false jukeboxStopMonitorAlert = false
@@ -525,7 +530,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
private var stopRequested = false private var stopRequested = false
private fun resetAlbumlistScroll() { private fun resetAlbumlistScroll() {
val currentlyPlaying = albumsList.indexOfFirst { it.canonicalPath.replace('\\', '/') == ingame.backgroundMusicPlayer.playlistSource } val currentlyPlaying = albumsList.indexOfFirst { it.canonicalPath.replace('\\', '/') == ingame.musicStreamer.playlistSource }
if (currentlyPlaying >= 0) { if (currentlyPlaying >= 0) {
albumlistScroll = (currentlyPlaying / PLAYLIST_LINES) * PLAYLIST_LINES albumlistScroll = (currentlyPlaying / PLAYLIST_LINES) * PLAYLIST_LINES
} }
@@ -535,9 +540,15 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
} }
private fun resetPlaylistScroll(song: MusicContainer? = null) { private fun resetPlaylistScroll(song: MusicContainer? = null) {
val currentlyPlaying = songsInGovernor.indexOf(song ?: App.audioMixer.musicTrack.currentTrack) val currentPlaylist = getCurrentPlaylist()
if (currentlyPlaying >= 0) { if (currentPlaylist != null) {
playlistScroll = (currentlyPlaying / PLAYLIST_LINES) * PLAYLIST_LINES val currentlyPlaying = currentPlaylist.musicList.indexOf(song ?: App.audioMixer.musicTrack.currentTrack)
if (currentlyPlaying >= 0) {
playlistScroll = (currentlyPlaying / PLAYLIST_LINES) * PLAYLIST_LINES
}
else {
playlistScroll = 0
}
} }
else { else {
playlistScroll = 0 playlistScroll = 0
@@ -804,9 +815,9 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
albumlistNameOverflown.clear() albumlistNameOverflown.clear()
} }
private fun setPlaylistDisplayVars(plist: List<MusicContainer>) { private fun setPlaylistDisplayVars(plist: TerrarumMusicPlaylist) {
resetPlaylistDisplay() resetPlaylistDisplay()
plist.forEachIndexed { i, music -> plist.musicList.forEachIndexed { i, music ->
val len = App.fontGameFBO.getWidth(music.name) val len = App.fontGameFBO.getWidth(music.name)
val overflown = (len >= playlistNameLenMax) val overflown = (len >= playlistNameLenMax)
playlistRealNameLen[i] = len playlistRealNameLen[i] = len
@@ -828,26 +839,47 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
private fun drawPlayList(camera: OrthographicCamera, delta: Float, batch: SpriteBatch, x: Float, y: Float, alpha: Float, scale: Float) { private fun drawPlayList(camera: OrthographicCamera, delta: Float, batch: SpriteBatch, x: Float, y: Float, alpha: Float, scale: Float) {
batch.end() batch.end()
playlistFBOs.forEachIndexed { i, it -> val currentPlaylist = getCurrentPlaylist()
val pnum = i + playlistScroll
it.inAction(camera, batch) {
batch.inUse {
batch.color = Color.WHITE
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
blendNormalStraightAlpha(batch)
// draw text if (currentPlaylist != null) {
App.fontGameFBO.draw(batch, if (pnum in songsInGovernor.indices) songsInGovernor[pnum].name else "", maskOffWidth - playlistNameScrolls[pnum], (PLAYLIST_LINE_HEIGHT - 24) / 2) playlistFBOs.forEachIndexed { i, it ->
val pnum = i + playlistScroll
it.inAction(camera, batch) {
batch.inUse {
batch.color = Color.WHITE
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
blendNormalStraightAlpha(batch)
// mask off the area // draw text
batch.color = Color.WHITE App.fontGameFBO.draw(
blendAlphaMask(batch) batch,
batch.draw(textmask.get(0, 0), 0f, 0f, maskOffWidth.toFloat(), PLAYLIST_LINE_HEIGHT) if (pnum in currentPlaylist.musicList.indices) currentPlaylist.musicList[pnum].name else "",
batch.draw(textmask.get(1, 0), maskOffWidth.toFloat(), 0f, PLAYLIST_NAME_LEN - 2f * maskOffWidth, PLAYLIST_LINE_HEIGHT) maskOffWidth - playlistNameScrolls[pnum],
batch.draw(textmask.get(2, 0), PLAYLIST_NAME_LEN - maskOffWidth.toFloat(), 0f, maskOffWidth.toFloat(), PLAYLIST_LINE_HEIGHT) (PLAYLIST_LINE_HEIGHT - 24) / 2
)
blendNormalStraightAlpha(batch) // qnd hack to make sure this line gets called, otherwise the screen briefly goes blank when the playlist view is closed // mask off the area
Toolkit.fillArea(batch, 999f, 999f, 1f, 1f) batch.color = Color.WHITE
blendAlphaMask(batch)
batch.draw(textmask.get(0, 0), 0f, 0f, maskOffWidth.toFloat(), PLAYLIST_LINE_HEIGHT)
batch.draw(
textmask.get(1, 0),
maskOffWidth.toFloat(),
0f,
PLAYLIST_NAME_LEN - 2f * maskOffWidth,
PLAYLIST_LINE_HEIGHT
)
batch.draw(
textmask.get(2, 0),
PLAYLIST_NAME_LEN - maskOffWidth.toFloat(),
0f,
maskOffWidth.toFloat(),
PLAYLIST_LINE_HEIGHT
)
blendNormalStraightAlpha(batch) // qnd hack to make sure this line gets called, otherwise the screen briefly goes blank when the playlist view is closed
Toolkit.fillArea(batch, 999f, 999f, 1f, 1f)
}
} }
} }
} }
@@ -856,37 +888,40 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
blendNormalStraightAlpha(batch) blendNormalStraightAlpha(batch)
if (alpha > 0f) { if (alpha > 0f) {
playlistFBOs.forEachIndexed { i, it -> playlistFBOs.forEachIndexed { i, it ->
val alpha2 = alpha + (playListAnimAkku[i] * 0.2f)
val pnum = i + playlistScroll
val m1 = songsInGovernor.getOrNull(pnum) if (currentPlaylist != null) {
val m2 = App.audioMixer.musicTrack.currentTrack val alpha2 = alpha + (playListAnimAkku[i] * 0.2f)
val currentlyPlaying = if (m1 == null || m2 == null) false else (m1 == m2) val pnum = i + playlistScroll
// print number val m1 = currentPlaylist.musicList.getOrNull(pnum)
val m2 = App.audioMixer.musicTrack.currentTrack
val currentlyPlaying = if (m1 == null || m2 == null) false else (m1 == m2)
// print bars instead of numbers if the song is currently being played // print number
if (currentlyPlaying) {
val xoff = 6 // print bars instead of numbers if the song is currently being played
val yoff = 5 + 7 + (PLAYLIST_LINE_HEIGHT - 24) / 2 if (currentlyPlaying) {
// it will set the colour on its own val xoff = 6
drawFreqMeter(batch, x + xoff, y + yoff + PLAYLIST_LINE_HEIGHT * i * scale, alpha) val yoff = 5 + 7 + (PLAYLIST_LINE_HEIGHT - 24) / 2
// it will set the colour on its own
drawFreqMeter(batch, x + xoff, y + yoff + PLAYLIST_LINE_HEIGHT * i * scale, alpha)
}
else {
val xoff = maskOffWidth + (if (pnum < 9) 3 else 0)
val yoff = 7 + (PLAYLIST_LINE_HEIGHT - 24) / 2
batch.color = Color(1f, 1f, 1f, alpha * 0.75f)
App.fontSmallNumbers.draw(
batch,
if (pnum in currentPlaylist.musicList.indices) "${pnum + 1}" else "",
x + xoff,
y + yoff + PLAYLIST_LINE_HEIGHT * i * scale
)
}
// print the name
batch.color = Color(1f, 1f, 1f, alpha2)
batch.draw(it.colorBufferTexture, x + PLAYLIST_LEFT_GAP * scale, y + PLAYLIST_LINE_HEIGHT * i * scale, it.width * scale, it.height * scale)
} }
else {
val xoff = maskOffWidth + (if (pnum < 9) 3 else 0)
val yoff = 7 + (PLAYLIST_LINE_HEIGHT - 24) / 2
batch.color = Color(1f, 1f, 1f, alpha * 0.75f)
App.fontSmallNumbers.draw(
batch,
if (pnum in songsInGovernor.indices) "${pnum + 1}" else "",
x + xoff,
y + yoff + PLAYLIST_LINE_HEIGHT * i * scale
)
}
// print the name
batch.color = Color(1f, 1f, 1f, alpha2)
batch.draw(it.colorBufferTexture, x + PLAYLIST_LEFT_GAP * scale, y + PLAYLIST_LINE_HEIGHT * i * scale, it.width * scale, it.height * scale)
// separator // separator
batch.color = Color(1f, 1f, 1f, alpha * 0.25f) batch.color = Color(1f, 1f, 1f, alpha * 0.25f)
@@ -936,7 +971,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
val pnum = i + albumlistScroll val pnum = i + albumlistScroll
val currentlyPlaying = if (pnum in albumsList.indices) { val currentlyPlaying = if (pnum in albumsList.indices) {
val m1 = ingame.backgroundMusicPlayer.playlistSource val m1 = ingame.musicStreamer.playlistSource
val m2 = albumsList[pnum].canonicalPath.replace('\\', '/') val m2 = albumsList[pnum].canonicalPath.replace('\\', '/')
(m1 == m2) (m1 == m2)
} }
@@ -1303,7 +1338,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
track.doGaplessPlayback = (albumProp.diskJockeyingMode == "continuous") track.doGaplessPlayback = (albumProp.diskJockeyingMode == "continuous")
if (track.doGaplessPlayback) { if (track.doGaplessPlayback) {
track.pullNextTrack = { track.pullNextTrack = {
track.currentTrack = ingame.backgroundMusicPlayer.pullNextMusicTrack(true) track.currentTrack = ingame.musicStreamer.pullNextMusicTrack(true)
setMusicName(track.currentTrack?.name ?: "") setMusicName(track.currentTrack?.name ?: "")
} }
} }

View File

@@ -18,17 +18,14 @@
<orderEntry type="library" name="gdx-controllers-desktop-2.2.1" level="project" /> <orderEntry type="library" name="gdx-controllers-desktop-2.2.1" level="project" />
<orderEntry type="library" name="jxinput-1.0.0" level="project" /> <orderEntry type="library" name="jxinput-1.0.0" level="project" />
<orderEntry type="library" name="graalvm-js 22.3.1" level="project" /> <orderEntry type="library" name="graalvm-js 22.3.1" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="badlogicgames.gdx" level="project" /> <orderEntry type="library" name="badlogicgames.gdx" level="project" />
<orderEntry type="library" name="badlogicgames.gdx.backend.lwjgl3" level="project" /> <orderEntry type="library" name="badlogicgames.gdx.backend.lwjgl3" level="project" />
<orderEntry type="library" name="jetbrains.kotlin.reflect" level="project" />
<orderEntry type="library" name="jetbrains.kotlin.test" level="project" />
<orderEntry type="library" name="io.github.classgraph" level="project" /> <orderEntry type="library" name="io.github.classgraph" level="project" />
<orderEntry type="library" name="apache.commons.math3" level="project" /> <orderEntry type="library" name="apache.commons.math3" level="project" />
<orderEntry type="library" name="github.wendykierp.JTransforms" level="project" /> <orderEntry type="library" name="github.wendykierp.JTransforms" level="project" />
<orderEntry type="library" name="io.airlift.aircompressor" level="project" /> <orderEntry type="library" name="io.airlift.aircompressor" level="project" />
<orderEntry type="library" name="jetbrains.kotlin.test1" level="project" />
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" /> <orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
<orderEntry type="library" name="TerranVirtualDisk" level="project" /> <orderEntry type="library" name="TerranVirtualDisk" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component> </component>
</module> </module>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,127 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.android.tools.lint</groupId>
<artifactId>lint</artifactId>
<version>31.0.1</version>
<name>com.android.tools.lint.lint</name>
<description>Lint tools. Both a Command line tool and a library to add lint features to other tools</description>
<url>http://tools.android.com/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>The Android Open Source Project</name>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.android.tools.lint</groupId>
<artifactId>lint-api</artifactId>
<version>31.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.tools.lint</groupId>
<artifactId>lint-checks</artifactId>
<version>31.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.tools.external.com-intellij</groupId>
<artifactId>intellij-core</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.external.com-intellij</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.external.org-jetbrains</groupId>
<artifactId>uast</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.analytics-library</groupId>
<artifactId>protos</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.analytics-library</groupId>
<artifactId>shared</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.analytics-library</groupId>
<artifactId>tracker</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>manifest-merger</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools</groupId>
<artifactId>common</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools.layoutlib</groupId>
<artifactId>layoutlib-api</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools</groupId>
<artifactId>sdk-common</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.android.tools</groupId>
<artifactId>sdklib</artifactId>
<version>31.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sf.kxml</groupId>
<artifactId>kxml2</artifactId>
<version>2.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>1.7.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.7.10</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -240,8 +240,8 @@ class Application(val WIDTH: Int, val HEIGHT: Int) : Game() {
} }
ymaxDisp.text = "${ys.max()}" ymaxDisp.text = "${ys.maxOrNull()}"
ymaxDisp2.text = "${ys2.max()}" ymaxDisp2.text = "${ys2.maxOrNull()}"
//System.exit(0) //System.exit(0)
} }

View File

@@ -581,7 +581,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
noticelet.sendNotification(itemID, itemCount) noticelet.sendNotification(itemID, itemCount)
} }
open val backgroundMusicPlayer: BackgroundMusicPlayer = BackgroundMusicPlayer() open val musicStreamer: MusicStreamer = MusicStreamer()
} }
inline fun Lock.lock(body: () -> Unit) { inline fun Lock.lock(body: () -> Unit) {

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarum.transaction.TransactionState
*/ */
object MusicService : TransactionListener() { object MusicService : TransactionListener() {
private var currentPlaylist: TerrarumMusicPlaylist? = null var currentPlaylist: TerrarumMusicPlaylist? = null; private set
override fun getCurrentStatusForTransaction(): TransactionState { override fun getCurrentStatusForTransaction(): TransactionState {
return TransactionState( return TransactionState(

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum package net.torvald.terrarum
open class BackgroundMusicPlayer { open class MusicStreamer {
open fun update(ingameInstance: IngameInstance, delta: Float) { open fun update(ingameInstance: IngameInstance, delta: Float) {

View File

@@ -123,8 +123,7 @@ class AudioMixer : Disposable {
fun getFreeGuiTrackNoMatterWhat(): TerrarumAudioMixerTrack { fun getFreeGuiTrackNoMatterWhat(): TerrarumAudioMixerTrack {
synchronized(this) { synchronized(this) {
val it = getFreeGuiTrack() ?: guiTracks.minBy { it.playStartedTime }.also { it.checkedOutTime = System.nanoTime() } return getFreeGuiTrack() ?: guiTracks.minByOrNull { it.playStartedTime }.also { it!!.checkedOutTime = System.nanoTime() }!!
return it
} }
} }
@@ -142,7 +141,7 @@ class AudioMixer : Disposable {
*/ */
fun getFreeTrackNoMatterWhat(): TerrarumAudioMixerTrack { fun getFreeTrackNoMatterWhat(): TerrarumAudioMixerTrack {
synchronized(this) { synchronized(this) {
return getFreeTrack() ?: dynamicTracks.minBy { it.playStartedTime }.also { it.checkedOutTime = System.nanoTime() } return getFreeTrack() ?: dynamicTracks.minByOrNull { it.playStartedTime }.also { it!!.checkedOutTime = System.nanoTime() }!!
} }
} }

View File

@@ -62,7 +62,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
lateinit var gameWorld: GameWorld lateinit var gameWorld: GameWorld
override val backgroundMusicPlayer = TerrarumBackgroundMusicPlayer() override val musicStreamer = TerrarumMusicStreamer()
init { init {
gameUpdateGovernor = ConsistentUpdateRate gameUpdateGovernor = ConsistentUpdateRate
@@ -396,7 +396,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
} }
backgroundMusicPlayer.update(this, delta) musicStreamer.update(this, delta)
} }
@@ -495,7 +495,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
// blockMarkings.dispose() // blockMarkings.dispose()
uiPenMenu.dispose() uiPenMenu.dispose()
uiGetPoiName.dispose() uiGetPoiName.dispose()
backgroundMusicPlayer.dispose() musicStreamer.dispose()
} }
fun getPoiNameForExport(w: Int, h: Int, callback: (String) -> Unit) { fun getPoiNameForExport(w: Int, h: Int, callback: (String) -> Unit) {

View File

@@ -262,7 +262,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
override var gameFullyLoaded = false override var gameFullyLoaded = false
internal set internal set
override val backgroundMusicPlayer = TerrarumBackgroundMusicPlayer() override val musicStreamer = TerrarumMusicStreamer()
////////////// //////////////
@@ -1006,7 +1006,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
oldSelectedWireRenderClass = selectedWireRenderClass oldSelectedWireRenderClass = selectedWireRenderClass
} }
backgroundMusicPlayer.update(this, delta) musicStreamer.update(this, delta)
//////////////////////// ////////////////////////
// ui-related updates // // ui-related updates //
@@ -1795,7 +1795,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
catch (e: IllegalArgumentException) {} catch (e: IllegalArgumentException) {}
} }
backgroundMusicPlayer.dispose() musicStreamer.dispose()
super.dispose() super.dispose()
} }
} }

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.audio.audiobank.MusicContainer
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
import java.io.File import java.io.File
class TerrarumBackgroundMusicPlayer : BackgroundMusicPlayer() { class TerrarumMusicStreamer : MusicStreamer() {
private val STATE_INIT = 0 private val STATE_INIT = 0
private val STATE_FIREPLAY = 1 private val STATE_FIREPLAY = 1
private val STATE_PLAYING = 2 private val STATE_PLAYING = 2
@@ -30,41 +30,7 @@ class TerrarumBackgroundMusicPlayer : BackgroundMusicPlayer() {
private var shuffled = true private var shuffled = true
private var diskJockeyingMode = "intermittent" // intermittent, continuous private var diskJockeyingMode = "intermittent" // intermittent, continuous
private fun registerSongsFromDir(musicDir: String, fileToName: ((String) -> String)?) {
val musicDir = musicDir.replace('\\', '/')
playlistSource = musicDir
printdbg(this, "registerSongsFromDir $musicDir")
val fileToName = if (fileToName == null) {
{ name: String -> name.substringBeforeLast('.').replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" ") }
}
else fileToName
playlistName = musicDir.substringAfterLast('/')
playlist = File(musicDir).listFiles()?.sortedBy { it.name }?.mapNotNull {
printdbg(this, "Music: ${it.absolutePath}")
try {
MusicContainer(
fileToName(it.name),
it
).also { muscon ->
printdbg(this, "MusicTitle: ${muscon.name}")
muscon.songFinishedHook = {
if (App.audioMixer.musicTrack.currentTrack == it) {
stopMusic(this, true, getRandomMusicInterval())
}
}
}
}
catch (e: GdxRuntimeException) {
e.printStackTrace()
null
}
} ?: emptyList() // TODO test code
}
private fun restockMusicBin() { private fun restockMusicBin() {
musicBin = ArrayList(if (shuffled) playlist.shuffled() else playlist.slice(playlist.indices)) musicBin = ArrayList(if (shuffled) playlist.shuffled() else playlist.slice(playlist.indices))
@@ -232,7 +198,7 @@ class TerrarumBackgroundMusicPlayer : BackgroundMusicPlayer() {
val timeNow = System.currentTimeMillis() val timeNow = System.currentTimeMillis()
val trackThis = App.audioMixer.musicTrack.currentTrack val trackThis = App.audioMixer.musicTrack.currentTrack
if (caller is TerrarumBackgroundMusicPlayer) { if (caller is TerrarumMusicStreamer) {
if (stopCaller == null) { if (stopCaller == null) {
// printdbg(this, "Caller: this, prev caller: $stopCaller, len: $pauseLen, obliging stop request") // printdbg(this, "Caller: this, prev caller: $stopCaller, len: $pauseLen, obliging stop request")
stopMusic0(trackThis, callStopMusicHook, pauseLen) stopMusic0(trackThis, callStopMusicHook, pauseLen)

View File

@@ -19,7 +19,7 @@ import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumBackgroundMusicPlayer import net.torvald.terrarum.modulebasegame.TerrarumMusicStreamer
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper
@@ -106,7 +106,7 @@ class FixtureJukebox : Electric, PlaysMusic {
// supress the normal background music playback // supress the normal background music playback
if (musicIsPlaying && !flagDespawn) { if (musicIsPlaying && !flagDespawn) {
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, true) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, true)
} }
} }
@@ -138,7 +138,7 @@ class FixtureJukebox : Electric, PlaysMusic {
printdbg(this, "Stop music $title - $artist") printdbg(this, "Stop music $title - $artist")
// can't call stopDiscPlayback() because of the recursion // can't call stopDiscPlayback() because of the recursion
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, pauseLen = (INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).getRandomMusicInterval()) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, pauseLen = (INGAME.musicStreamer as TerrarumMusicStreamer).getRandomMusicInterval())
} }
discCurrentlyPlaying = index discCurrentlyPlaying = index
@@ -185,7 +185,7 @@ class FixtureJukebox : Electric, PlaysMusic {
*/ */
fun stopGracefully() { fun stopGracefully() {
stopDiscPlayback() stopDiscPlayback()
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, pauseLen = (INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).getRandomMusicInterval()) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, pauseLen = (INGAME.musicStreamer as TerrarumMusicStreamer).getRandomMusicInterval())
} }

View File

@@ -3,14 +3,13 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.spriteanimation.SheetSpriteAnimation import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.audio.AudioMixer
import net.torvald.terrarum.audio.audiobank.MusicContainer import net.torvald.terrarum.audio.audiobank.MusicContainer
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumBackgroundMusicPlayer import net.torvald.terrarum.modulebasegame.TerrarumMusicStreamer
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper
@@ -96,7 +95,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
// supress the normal background music playback // supress the normal background music playback
if (musicIsPlaying && !flagDespawn) { if (musicIsPlaying && !flagDespawn) {
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, true) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, true)
} }
} }
@@ -122,7 +121,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
App.printdbg(this, "Stop music $title - $artist") App.printdbg(this, "Stop music $title - $artist")
// can't call stopDiscPlayback() because of the recursion // can't call stopDiscPlayback() because of the recursion
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, pauseLen = (INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).getRandomMusicInterval()) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, pauseLen = (INGAME.musicStreamer as TerrarumMusicStreamer).getRandomMusicInterval())
} }
@@ -163,7 +162,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
*/ */
fun stopGracefully() { fun stopGracefully() {
stopDiscPlayback() stopDiscPlayback()
(INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).stopMusic(this, pauseLen = (INGAME.backgroundMusicPlayer as TerrarumBackgroundMusicPlayer).getRandomMusicInterval()) (INGAME.musicStreamer as TerrarumMusicStreamer).stopMusic(this, pauseLen = (INGAME.musicStreamer as TerrarumMusicStreamer).getRandomMusicInterval())
} }

View File

@@ -72,7 +72,7 @@ class UIItemSpinner(
val intermediate = (0..(maxd - mind).div(stepd).ceilToInt()).map { val intermediate = (0..(maxd - mind).div(stepd).ceilToInt()).map {
it to ((mind + stepd * it) - id).absoluteValue it to ((mind + stepd * it) - id).absoluteValue
}.minBy { it.second }.first * stepd + mind }.minByOrNull { it.second }!!.first * stepd + mind
initialValue = when (initialValue.javaClass.simpleName) { initialValue = when (initialValue.javaClass.simpleName) {
"Integer" -> intermediate.toInt() "Integer" -> intermediate.toInt()
else -> intermediate else -> intermediate