diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 235dadd7..9484fc4f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -35,7 +35,6 @@ jobs: - name: Build with Gradle Wrapper run: ./gradlew build - # NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html). # If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version. diff --git a/app/detekt-baseline.xml b/app/detekt-baseline.xml index 9ee17a55..062be5e2 100644 --- a/app/detekt-baseline.xml +++ b/app/detekt-baseline.xml @@ -47,12 +47,6 @@ LongParameterList:MainActivity.kt$MainActivity$( channelId: String, title: String, message: String, ongoing: Boolean = false, onIntent: Intent.() -> Unit = { }, setBuilder: (NotificationCompat.Builder) -> Unit = { } ) LongParameterList:RoutingGraph.kt$RoutingGraph$( sourceX: Float, sourceZ: Float, destX: Float, destZ: Float, simpleDistance: Float, maxCost: Float = Float.POSITIVE_INFINITY ) LoopWithTooManyJumpStatements:RoutingGraph.kt$RoutingGraph$while - MagicNumber:AgentViewModel.kt$AgentViewModel$3 - MagicNumber:HelpFragment.kt$HelpFragment$3 - MagicNumber:HelpFragment.kt$HelpFragment$5 - MagicNumber:HelpFragment.kt$HelpFragment$7 - MagicNumber:RouteObjective.kt$RouteObjective.ReplacementFighters$4 - MagicNumber:RouteObjective.kt$RouteObjective.ReplacementFighters$6 NestedBlockDepth:AgentViewModel.kt$AgentViewModel$private suspend fun updateObjects() NestedBlockDepth:CPU.kt$CPU$@Listener fun onPlayerUpdate(update: ArtemisPlayer) NestedBlockDepth:CPU.kt$CPU$private fun onNpcCreate(npc: ArtemisNpc): Boolean @@ -75,11 +69,5 @@ TooManyFunctions:AgentViewModel.kt$AgentViewModel : AndroidViewModelListener TooManyFunctions:CPU.kt$CPU : CoroutineScope TooManyFunctions:ObjectEntry.kt$ObjectEntry$Station : ObjectEntry - UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.HeartbeatLost - UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.HeartbeatRegained - UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.Success - UnusedParameter:AgentViewModel.kt$AgentViewModel$packet: EndGamePacket - UnusedParameter:AgentViewModel.kt$AgentViewModel$packet: JumpEndPacket - UnusedPrivateProperty:ConnectFragment.kt$ConnectFragment$val prevUrl = viewModel.connectedUrl.value diff --git a/app/src/main/kotlin/artemis/agent/AgentViewModel.kt b/app/src/main/kotlin/artemis/agent/AgentViewModel.kt index 121f3e1b..192eab90 100644 --- a/app/src/main/kotlin/artemis/agent/AgentViewModel.kt +++ b/app/src/main/kotlin/artemis/agent/AgentViewModel.kt @@ -409,7 +409,7 @@ class AgentViewModel(application: Application) : private var updateJob: Job? = null // Determines whether directions are shown as padded three-digit numbers - var threeDigitDirections = true + private var threeDigitDirections = true // Page flash variables var missionUpdate: Boolean = false @@ -589,7 +589,7 @@ class AgentViewModel(application: Application) : } fun formattedHeading(heading: Int): String = - heading.toString().padStart(if (threeDigitDirections) 3 else 0, '0') + heading.toString().padStart(if (threeDigitDirections) PADDED_ZEROES else 0, '0') /** * Calculates the heading from the player ship to the given object and formats it as a string. @@ -1242,7 +1242,7 @@ class AgentViewModel(application: Application) : } @Listener - fun onConnect(event: ConnectionEvent.Success) { + fun onConnect(@Suppress("UNUSED_PARAMETER") event: ConnectionEvent.Success) { connectionStatus.value = ConnectionStatus.Connected playSound(SoundEffect.CONNECTED) @@ -1263,13 +1263,13 @@ class AgentViewModel(application: Application) : } @Listener - fun onHeartbeatLost(event: ConnectionEvent.HeartbeatLost) { + fun onHeartbeatLost(@Suppress("UNUSED_PARAMETER") event: ConnectionEvent.HeartbeatLost) { connectionStatus.value = ConnectionStatus.HeartbeatLost playSound(SoundEffect.HEARTBEAT_LOST) } @Listener - fun onHeartbeatRegained(event: ConnectionEvent.HeartbeatRegained) { + fun onHeartbeatRegained(@Suppress("UNUSED_PARAMETER") event: ConnectionEvent.HeartbeatRegained) { connectionStatus.value = ConnectionStatus.Connected playSound(SoundEffect.BEEP_2) } @@ -1363,7 +1363,7 @@ class AgentViewModel(application: Application) : } @Listener - fun onPacket(packet: EndGamePacket) { + fun onPacket(@Suppress("UNUSED_PARAMETER") packet: EndGamePacket) { endGame() } @@ -1374,7 +1374,7 @@ class AgentViewModel(application: Application) : } @Listener - fun onPacket(packet: JumpEndPacket) { + fun onPacket(@Suppress("UNUSED_PARAMETER") packet: JumpEndPacket) { viewModelScope.launch { jumping.value = true delay(JUMP_DURATION) @@ -1621,6 +1621,7 @@ class AgentViewModel(application: Application) : private const val JUMP_DURATION = 3000L const val FULL_HEADING_RANGE = 360 const val VOLUME_SCALE = 100f + private const val PADDED_ZEROES = 3 private val STATION_CALLSIGN = Regex("DS\\d+") private val ENEMY_STATION = Regex("^[A-Z][a-z]+ Base \\d+") diff --git a/app/src/main/kotlin/artemis/agent/game/route/RouteObjective.kt b/app/src/main/kotlin/artemis/agent/game/route/RouteObjective.kt index d141bc31..8bccb731 100644 --- a/app/src/main/kotlin/artemis/agent/game/route/RouteObjective.kt +++ b/app/src/main/kotlin/artemis/agent/game/route/RouteObjective.kt @@ -25,7 +25,9 @@ sealed interface RouteObjective { return "$totalFighters/${maxFighters + extraShuttle}" } + @Suppress("MagicNumber") val REPORT_VERSION = Version(2, 4, 0) + @Suppress("MagicNumber") val SHUTTLE_VERSION = Version(2, 6, 0) } diff --git a/app/src/main/kotlin/artemis/agent/help/HelpFragment.kt b/app/src/main/kotlin/artemis/agent/help/HelpFragment.kt index e15cca23..eb476e18 100644 --- a/app/src/main/kotlin/artemis/agent/help/HelpFragment.kt +++ b/app/src/main/kotlin/artemis/agent/help/HelpFragment.kt @@ -35,8 +35,10 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_getting_started).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(3, HelpTopicContent.Image(R.drawable.connect_preview)) - add(5, HelpTopicContent.Image(R.drawable.ship_entry_preview)) + addImages( + INDEX_PREVIEW_CONNECT to R.drawable.connect_preview, + INDEX_PREVIEW_SHIP to R.drawable.ship_entry_preview, + ) }, ), HelpTopic( @@ -44,7 +46,7 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_basics).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.game_header_preview)) + addImages(1 to R.drawable.game_header_preview) }, ), HelpTopic( @@ -52,7 +54,7 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_stations).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.station_entry_preview)) + addImages(1 to R.drawable.station_entry_preview) }, ), HelpTopic( @@ -60,7 +62,7 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_allies).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.ally_entry_preview)) + addImages(1 to R.drawable.ally_entry_preview) }, ), HelpTopic( @@ -68,8 +70,10 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_missions).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.comms_message)) - add(7, HelpTopicContent.Image(R.drawable.mission_entry_preview)) + addImages( + INDEX_PREVIEW_COMMS_MESSAGE to R.drawable.comms_message, + INDEX_PREVIEW_MISSION to R.drawable.mission_entry_preview, + ) }, ), HelpTopic( @@ -77,8 +81,10 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_routing).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.route_tasks_preview)) - add(3, HelpTopicContent.Image(R.drawable.route_supplies_preview)) + addImages( + INDEX_PREVIEW_ROUTE_TASKS to R.drawable.route_tasks_preview, + INDEX_PREVIEW_ROUTE_SUPPLIES to R.drawable.route_supplies_preview, + ) } ), HelpTopic( @@ -86,8 +92,10 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_enemies).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.enemy_entry_preview)) - add(3, HelpTopicContent.Image(R.drawable.enemy_intel_preview)) + addImages( + INDEX_PREVIEW_ENEMY to R.drawable.enemy_entry_preview, + INDEX_PREVIEW_INTEL to R.drawable.enemy_intel_preview, + ) }, ), HelpTopic( @@ -95,7 +103,7 @@ class HelpFragment : Fragment(R.layout.help_fragment) { getStringArray(R.array.help_contents_biomechs).map { HelpTopicContent.Text(it) }.toMutableList().apply { - add(1, HelpTopicContent.Image(R.drawable.biomech_entry_preview)) + addImages(1 to R.drawable.biomech_entry_preview) }, ), HelpTopic( @@ -247,5 +255,21 @@ class HelpFragment : Fragment(R.layout.help_fragment) { const val MENU = -1 const val IMAGE = 0 const val TEXT = 1 + + private const val INDEX_PREVIEW_CONNECT = 3 + private const val INDEX_PREVIEW_SHIP = 5 + + private const val INDEX_PREVIEW_COMMS_MESSAGE = 1 + private const val INDEX_PREVIEW_MISSION = 7 + + private const val INDEX_PREVIEW_ROUTE_TASKS = 1 + private const val INDEX_PREVIEW_ROUTE_SUPPLIES = 3 + + private const val INDEX_PREVIEW_ENEMY = 1 + private const val INDEX_PREVIEW_INTEL = 3 + + private fun MutableList.addImages(vararg entries: Pair) { + entries.forEach { (index, entry) -> add(index, HelpTopicContent.Image(entry)) } + } } } diff --git a/app/src/main/kotlin/artemis/agent/setup/ConnectFragment.kt b/app/src/main/kotlin/artemis/agent/setup/ConnectFragment.kt index 1d754377..3dae26ae 100644 --- a/app/src/main/kotlin/artemis/agent/setup/ConnectFragment.kt +++ b/app/src/main/kotlin/artemis/agent/setup/ConnectFragment.kt @@ -102,12 +102,9 @@ class ConnectFragment : Fragment(R.layout.connect_fragment) { binding.connectSpinner.visibility = it.spinnerVisibility if (!viewModel.attemptingConnection && it is ConnectionStatus.Connecting) { - val prevUrl = viewModel.connectedUrl.value - addressBar.clearFocus() val url = addressBar.text.toString() - viewModel.tryConnect(url) } }