diff --git a/common/src/main/kotlin/syncInfo/models/mod/Mod.kt b/common/src/main/kotlin/syncInfo/models/mod/Mod.kt index 0b9d848..bf89a88 100644 --- a/common/src/main/kotlin/syncInfo/models/mod/Mod.kt +++ b/common/src/main/kotlin/syncInfo/models/mod/Mod.kt @@ -55,6 +55,10 @@ data class Mod( * for a specific mod * */ val verifyFileIntegrity: Boolean? = null, + /** + * Will override [ModSyncInfo.syncAllOptionalForCurrentEnv] for a specific mod + * */ + val syncOptionalForCurrentEnv: Boolean? = null, ) { @Serializable enum class ModSupport { diff --git a/common/src/main/kotlin/syncInfo/models/mod/ModSyncInfo.kt b/common/src/main/kotlin/syncInfo/models/mod/ModSyncInfo.kt index e7277a3..7c77bb7 100644 --- a/common/src/main/kotlin/syncInfo/models/mod/ModSyncInfo.kt +++ b/common/src/main/kotlin/syncInfo/models/mod/ModSyncInfo.kt @@ -43,7 +43,21 @@ data class ModSyncInfo( * You will get an error from the mod loader. * * */ - val syncOnlyForCurrentEnvironment: Boolean = true, + val syncOnlyForCurrentEnv: Boolean = true, + /** + * Indicates whether optional mods for the current [Environment] should be synced. + * + * Some mods might be optional to install on either server or client side or both. + * + * This setting only takes effect if [syncOnlyForCurrentEnv] is `true`. + * If [syncOnlyForCurrentEnv] is `false`, this property has no impact. + * + * if [syncAllOptionalForCurrentEnv] is `false`, then will only sync the + * required mods for the current system [Environment]. + * + * @see Mod.syncOptionalForCurrentEnv + * */ + val syncAllOptionalForCurrentEnv: Boolean = true, /** * Determines whether the script allows the player to use mods other than those synchronized by the script. * diff --git a/sync-script/src/main/kotlin/Main.kt b/sync-script/src/main/kotlin/Main.kt index 8478b0d..4a1c6b8 100644 --- a/sync-script/src/main/kotlin/Main.kt +++ b/sync-script/src/main/kotlin/Main.kt @@ -243,6 +243,7 @@ suspend fun fetchSyncInfo() { .fetchSyncInfo( url = ScriptConfig.getInstanceOrThrow().syncInfoUrl, ).getOrElse { + it.printStackTrace() showErrorMessageAndTerminate( title = "Sync Info Unavailable \uD83D\uDD04", message = "An error occurred while trying to fetch sync info from the server: ${it.message}", diff --git a/sync-script/src/main/kotlin/syncInfo/models/ModExtensions.kt b/sync-script/src/main/kotlin/syncInfo/models/ModExtensions.kt index a93a6a1..c15b130 100644 --- a/sync-script/src/main/kotlin/syncInfo/models/ModExtensions.kt +++ b/sync-script/src/main/kotlin/syncInfo/models/ModExtensions.kt @@ -15,29 +15,32 @@ import kotlin.system.exitProcess * */ fun Mod.getDisplayName(): String = name ?: getFileNameFromUrlOrError(downloadUrl) +private fun Mod.shouldSyncOptionalModForCurrentEnvironment() = + syncOptionalForCurrentEnv + ?: SyncInfo.instance.modSyncInfo.syncAllOptionalForCurrentEnv + /** * If this mod should be downloaded on the current [Environment]. * * For example, if this is a client side-only mod and the environment is [Environment.Server], * it will return false * */ -fun Mod.shouldSyncOnCurrentEnvironment(): Boolean { - // TODO: Currently, this function will always download the mod even if it's optional on both client and server. - // Consider providing an option for the admin to decide if the optional mods or a specific mods will be downloaded - return when (ScriptConfig.getInstanceOrThrow().environment) { +fun Mod.shouldSyncOnCurrentEnvironment(): Boolean = + when (ScriptConfig.getInstanceOrThrow().environment) { Environment.Client -> when (clientSupport) { - Mod.ModSupport.Required, Mod.ModSupport.Optional -> true + Mod.ModSupport.Required -> true + Mod.ModSupport.Optional -> shouldSyncOptionalModForCurrentEnvironment() Mod.ModSupport.Unsupported -> false } Environment.Server -> when (serverSupport) { - Mod.ModSupport.Required, Mod.ModSupport.Optional -> true + Mod.ModSupport.Required -> true + Mod.ModSupport.Optional -> shouldSyncOptionalModForCurrentEnvironment() Mod.ModSupport.Unsupported -> false } } -} /** * Allow overriding the value for a specific mod, or all the mods, or use a global value for all the assets. diff --git a/sync-script/src/main/kotlin/syncService/ModsSyncService.kt b/sync-script/src/main/kotlin/syncService/ModsSyncService.kt index 75fb1ba..304f38b 100644 --- a/sync-script/src/main/kotlin/syncService/ModsSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ModsSyncService.kt @@ -97,7 +97,7 @@ class ModsSyncService : } private fun getCurrentEnvironmentModsOrAll(mods: List): List { - if (!modSyncInfo.syncOnlyForCurrentEnvironment) { + if (!modSyncInfo.syncOnlyForCurrentEnv) { return mods } val currentEnvironmentMods =