Skip to content

Commit

Permalink
Fix some Detekt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanLongstaff committed Aug 16, 2024
1 parent 3bf1b29 commit 12268da
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
1 change: 0 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions app/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
<ID>LongParameterList:MainActivity.kt$MainActivity$( channelId: String, title: String, message: String, ongoing: Boolean = false, onIntent: Intent.() -&gt; Unit = { }, setBuilder: (NotificationCompat.Builder) -&gt; Unit = { } )</ID>
<ID>LongParameterList:RoutingGraph.kt$RoutingGraph$( sourceX: Float, sourceZ: Float, destX: Float, destZ: Float, simpleDistance: Float, maxCost: Float = Float.POSITIVE_INFINITY )</ID>
<ID>LoopWithTooManyJumpStatements:RoutingGraph.kt$RoutingGraph$while</ID>
<ID>MagicNumber:AgentViewModel.kt$AgentViewModel$3</ID>
<ID>MagicNumber:HelpFragment.kt$HelpFragment$3</ID>
<ID>MagicNumber:HelpFragment.kt$HelpFragment$5</ID>
<ID>MagicNumber:HelpFragment.kt$HelpFragment$7</ID>
<ID>MagicNumber:RouteObjective.kt$RouteObjective.ReplacementFighters$4</ID>
<ID>MagicNumber:RouteObjective.kt$RouteObjective.ReplacementFighters$6</ID>
<ID>NestedBlockDepth:AgentViewModel.kt$AgentViewModel$private suspend fun updateObjects()</ID>
<ID>NestedBlockDepth:CPU.kt$CPU$@Listener fun onPlayerUpdate(update: ArtemisPlayer)</ID>
<ID>NestedBlockDepth:CPU.kt$CPU$private fun onNpcCreate(npc: ArtemisNpc): Boolean</ID>
Expand All @@ -75,11 +69,5 @@
<ID>TooManyFunctions:AgentViewModel.kt$AgentViewModel : AndroidViewModelListener</ID>
<ID>TooManyFunctions:CPU.kt$CPU : CoroutineScope</ID>
<ID>TooManyFunctions:ObjectEntry.kt$ObjectEntry$Station : ObjectEntry</ID>
<ID>UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.HeartbeatLost</ID>
<ID>UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.HeartbeatRegained</ID>
<ID>UnusedParameter:AgentViewModel.kt$AgentViewModel$event: ConnectionEvent.Success</ID>
<ID>UnusedParameter:AgentViewModel.kt$AgentViewModel$packet: EndGamePacket</ID>
<ID>UnusedParameter:AgentViewModel.kt$AgentViewModel$packet: JumpEndPacket</ID>
<ID>UnusedPrivateProperty:ConnectFragment.kt$ConnectFragment$val prevUrl = viewModel.connectedUrl.value</ID>
</CurrentIssues>
</SmellBaseline>
15 changes: 8 additions & 7 deletions app/src/main/kotlin/artemis/agent/AgentViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down Expand Up @@ -1363,7 +1363,7 @@ class AgentViewModel(application: Application) :
}

@Listener
fun onPacket(packet: EndGamePacket) {
fun onPacket(@Suppress("UNUSED_PARAMETER") packet: EndGamePacket) {
endGame()
}

Expand All @@ -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)
Expand Down Expand Up @@ -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+")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
48 changes: 36 additions & 12 deletions app/src/main/kotlin/artemis/agent/help/HelpFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,75 @@ class HelpFragment : Fragment(R.layout.help_fragment) {
getStringArray(R.array.help_contents_getting_started).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().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(
getString(R.string.help_topics_basics),
getStringArray(R.array.help_contents_basics).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().apply {
add(1, HelpTopicContent.Image(R.drawable.game_header_preview))
addImages(1 to R.drawable.game_header_preview)
},
),
HelpTopic(
getString(R.string.help_topics_stations),
getStringArray(R.array.help_contents_stations).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().apply {
add(1, HelpTopicContent.Image(R.drawable.station_entry_preview))
addImages(1 to R.drawable.station_entry_preview)
},
),
HelpTopic(
getString(R.string.help_topics_allies),
getStringArray(R.array.help_contents_allies).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().apply {
add(1, HelpTopicContent.Image(R.drawable.ally_entry_preview))
addImages(1 to R.drawable.ally_entry_preview)
},
),
HelpTopic(
getString(R.string.help_topics_missions),
getStringArray(R.array.help_contents_missions).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().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(
getString(R.string.help_topics_routing),
getStringArray(R.array.help_contents_routing).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().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(
getString(R.string.help_topics_enemies),
getStringArray(R.array.help_contents_enemies).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().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(
getString(R.string.help_topics_biomechs),
getStringArray(R.array.help_contents_biomechs).map {
HelpTopicContent.Text(it)
}.toMutableList<HelpTopicContent>().apply {
add(1, HelpTopicContent.Image(R.drawable.biomech_entry_preview))
addImages(1 to R.drawable.biomech_entry_preview)
},
),
HelpTopic(
Expand Down Expand Up @@ -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<HelpTopicContent>.addImages(vararg entries: Pair<Int, Int>) {
entries.forEach { (index, entry) -> add(index, HelpTopicContent.Image(entry)) }
}
}
}
3 changes: 0 additions & 3 deletions app/src/main/kotlin/artemis/agent/setup/ConnectFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 12268da

Please sign in to comment.