From 0530e262db3e3d9955a3ec4e3cc7505ddb6394fe Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 14 Apr 2024 23:27:43 +0300 Subject: [PATCH] EventBus removal - remove 'settings updated' sound playing via eventbus --- core/src/com/unciv/models/metadata/SettingsEvents.kt | 5 ----- core/src/com/unciv/ui/audio/GameSounds.kt | 8 -------- core/src/com/unciv/ui/popups/options/SettingsSelect.kt | 7 ++----- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/core/src/com/unciv/models/metadata/SettingsEvents.kt b/core/src/com/unciv/models/metadata/SettingsEvents.kt index cfbd668a62..da73154095 100644 --- a/core/src/com/unciv/models/metadata/SettingsEvents.kt +++ b/core/src/com/unciv/models/metadata/SettingsEvents.kt @@ -1,14 +1,9 @@ package com.unciv.models.metadata import com.unciv.logic.event.Event -import com.unciv.models.UncivSound import com.unciv.models.metadata.GameSettings.GameSetting /** **Warning:** this event is in the process of completion and **not** used for all settings yet! **Only the settings in [GameSetting] get events sent!** */ interface SettingsPropertyChanged : Event { val gameSetting: GameSetting } - -interface SettingsPropertyUncivSoundChanged : SettingsPropertyChanged { - val value: UncivSound -} diff --git a/core/src/com/unciv/ui/audio/GameSounds.kt b/core/src/com/unciv/ui/audio/GameSounds.kt index 8cb477cf37..3e2f18fe3a 100644 --- a/core/src/com/unciv/ui/audio/GameSounds.kt +++ b/core/src/com/unciv/ui/audio/GameSounds.kt @@ -4,7 +4,6 @@ import com.unciv.UncivGame import com.unciv.logic.event.EventBus import com.unciv.logic.multiplayer.MultiplayerGameUpdated import com.unciv.logic.multiplayer.isUsersTurn -import com.unciv.models.metadata.SettingsPropertyUncivSoundChanged /** * Controls which sounds should be played when something happens while playing the game. @@ -18,16 +17,9 @@ object GameSounds { * Has to be called for sounds to be played. */ fun init() { - playSettingsSounds() playMultiplayerTurnNotification() } - private fun playSettingsSounds() { - events.receive(SettingsPropertyUncivSoundChanged::class) { - SoundPlayer.play(it.value) - } - } - private fun playMultiplayerTurnNotification() { events.receive(MultiplayerGameUpdated::class, { it.preview.isUsersTurn() }) { if (UncivGame.isDeepLinkedGameLoading()) return@receive // This means we already arrived here through a turn notification, no need to notify again diff --git a/core/src/com/unciv/ui/popups/options/SettingsSelect.kt b/core/src/com/unciv/ui/popups/options/SettingsSelect.kt index 5e87ea78c4..d934c82d3c 100644 --- a/core/src/com/unciv/ui/popups/options/SettingsSelect.kt +++ b/core/src/com/unciv/ui/popups/options/SettingsSelect.kt @@ -10,8 +10,8 @@ import com.unciv.models.UncivSound import com.unciv.models.metadata.GameSettings import com.unciv.models.metadata.GameSettings.GameSetting import com.unciv.models.metadata.SettingsPropertyChanged -import com.unciv.models.metadata.SettingsPropertyUncivSoundChanged import com.unciv.models.translations.tr +import com.unciv.ui.audio.SoundPlayer import com.unciv.ui.components.input.onChange import com.unciv.ui.components.extensions.toGdxArray import com.unciv.ui.components.extensions.toLabel @@ -84,10 +84,7 @@ open class SettingsSelect( private fun sendChangeEvent(item: T) { when (item) { - is UncivSound -> EventBus.send(object : SettingsPropertyUncivSoundChanged { - override val gameSetting = setting - override val value: UncivSound = settingsProperty.get() as UncivSound - }) + is UncivSound -> SoundPlayer.play(item) else -> EventBus.send(object : SettingsPropertyChanged { override val gameSetting = setting })