Skip to content

Commit

Permalink
refactor(admin): rename variable and function names in ModrinthLaunch…
Browse files Browse the repository at this point in the history
…er and ATLauncher implementations, fix some issues with the names
  • Loading branch information
Ellet committed Jun 25, 2024
1 parent d2ba66f commit a852ac4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion admin/src/main/kotlin/launchers/LauncherDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface LauncherDataSource {
* @return A list of [Mod] which contains the information about the mod, converting it from the specified launcher
* into the script data format
* */
suspend fun getMods(
suspend fun getLauncherInstanceMods(
launcherInstanceDirectory: File,
curseForgeApiKeyOverride: String?,
): Result<List<Mod>>
Expand Down
33 changes: 17 additions & 16 deletions admin/src/main/kotlin/launchers/atLauncher/ATLauncherDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ATLauncherDataSource : LauncherDataSource {
private fun getInstance(launcherInstanceDirectory: File): Result<ATLauncherInstance> {
return try {
val instanceConfigFile = getInstanceConfigFile(launcherInstanceDirectory = launcherInstanceDirectory)
val atLauncherInstance = JsonIgnoreUnknownKeys.decodeFromString<ATLauncherInstance>(instanceConfigFile.readText())
return Result.success(atLauncherInstance)
val instance = JsonIgnoreUnknownKeys.decodeFromString<ATLauncherInstance>(instanceConfigFile.readText())
return Result.success(instance)
} catch (e: Exception) {
e.printStackTrace()
Result.failure(e)
Expand All @@ -41,7 +41,7 @@ class ATLauncherDataSource : LauncherDataSource {
*
* @see ATLauncherInstance.Launcher.Mod.Type
* */
private fun getATLauncherMods(instance: ATLauncherInstance): List<ATLauncherInstance.Launcher.Mod> =
private fun getMods(instance: ATLauncherInstance): List<ATLauncherInstance.Launcher.Mod> =
instance.launcher.mods
.filter { it.type == ATLauncherInstance.Launcher.Mod.Type.Mods }

Expand All @@ -61,17 +61,17 @@ class ATLauncherDataSource : LauncherDataSource {
}
}

private fun isCurseForgeApiRequestNeededForMod(atLauncherMod: ATLauncherInstance.Launcher.Mod): Boolean {
val modrinthFile = atLauncherMod.modrinthVersion?.files?.firstOrNull()
return modrinthFile == null && (atLauncherMod.curseForgeProjectId != null && atLauncherMod.curseForgeFileId != null)
private fun isCurseForgeApiRequestNeededForMod(mod: ATLauncherInstance.Launcher.Mod): Boolean {
val modrinthFile = mod.modrinthVersion?.files?.firstOrNull()
return modrinthFile == null && (mod.curseForgeProjectId != null && mod.curseForgeFileId != null)
}

override suspend fun isCurseForgeApiRequestNeededForConvertingMods(launcherInstanceDirectory: File): Result<Boolean> =
try {
val instance = getInstance(launcherInstanceDirectory = launcherInstanceDirectory).getOrThrow()
val isCurseForgeApiRequestNeeded =
getATLauncherMods(instance).any { atLauncherMod ->
isCurseForgeApiRequestNeededForMod(atLauncherMod = atLauncherMod)
getMods(instance).any { atLauncherMod ->
isCurseForgeApiRequestNeededForMod(mod = atLauncherMod)
}
Result.success(isCurseForgeApiRequestNeeded)
} catch (e: Exception) {
Expand All @@ -81,24 +81,24 @@ class ATLauncherDataSource : LauncherDataSource {

override suspend fun hasMods(launcherInstanceDirectory: File): Result<Boolean> =
try {
val atLauncherMods =
getATLauncherMods(
val mods =
getMods(
instance = getInstance(launcherInstanceDirectory = launcherInstanceDirectory).getOrThrow(),
)
Result.success(atLauncherMods.isNotEmpty())
Result.success(mods.isNotEmpty())
} catch (e: Exception) {
Result.failure(e)
}

override suspend fun getMods(
override suspend fun getLauncherInstanceMods(
launcherInstanceDirectory: File,
curseForgeApiKeyOverride: String?,
): Result<List<Mod>> =
try {
val instance = getInstance(launcherInstanceDirectory = launcherInstanceDirectory).getOrThrow()

val mods =
instance.launcher.mods
.filter { it.type == ATLauncherInstance.Launcher.Mod.Type.Mods }
getMods(instance = instance)
.map { atLauncherMod ->
val modrinthFile = atLauncherMod.modrinthVersion?.files?.firstOrNull()
val modrinthProject = atLauncherMod.modrinthProject
Expand All @@ -112,7 +112,7 @@ class ATLauncherDataSource : LauncherDataSource {

// ATLauncher always store Modrinth data even if the mod downloaded
// from Curse Forge if available on both.
if (isCurseForgeApiRequestNeededForMod(atLauncherMod = atLauncherMod)) {
if (isCurseForgeApiRequestNeededForMod(mod = atLauncherMod)) {
// Handle the case when the mod is exclusively found on Curse Forge, not on Modrinth
val curseForgeModFile =
curseForgeDataSource
Expand Down Expand Up @@ -173,7 +173,8 @@ class ATLauncherDataSource : LauncherDataSource {
this.remove(preLaunchCommandJsonKey)
// The user might use other commands like post-exit command,
// make sure we don't touch this key if they are used
val instance: ATLauncherInstance = JsonIgnoreUnknownKeys.decodeFromJsonElement(instanceJsonObject)
val instance: ATLauncherInstance =
JsonIgnoreUnknownKeys.decodeFromJsonElement(instanceJsonObject)
if (instance.launcher.postExitCommand == null && instance.launcher.wrapperCommand == null) {
// The instance settings do not have any other commands,
// remove overriding enable commands for this instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ class ModrinthLauncherDataSource : LauncherDataSource {
if (!instanceConfigFile.isFile) {
return Result.failure(IllegalArgumentException("The file (${instanceConfigFile.absolutePath}) should be a file."))
}
val atLauncherMods =
val mods =
getModrinthLauncherProjects(
instance =
getInstance(
launcherInstanceDirectory = launcherInstanceDirectory,
).getOrThrow(),
)
Result.success(atLauncherMods.isNotEmpty())
Result.success(mods.isNotEmpty())
} catch (e: Exception) {
Result.failure(e)
}
}

override suspend fun getMods(
override suspend fun getLauncherInstanceMods(
launcherInstanceDirectory: File,
curseForgeApiKeyOverride: String?,
): Result<List<Mod>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PrismLauncherDataSource : LauncherDataSource {
}
}

override suspend fun getMods(
override suspend fun getLauncherInstanceMods(
launcherInstanceDirectory: File,
curseForgeApiKeyOverride: String?,
): Result<List<Mod>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ModsConverterImpl : ModsConverter {
}
val mods =
launcherDataSource
.getMods(
.getLauncherInstanceMods(
launcherInstanceDirectory = launcherInstanceDirectory,
curseForgeApiKeyOverride = curseForgeApiKeyOverride?.ifBlank { null },
).getOrElse {
Expand Down

0 comments on commit a852ac4

Please sign in to comment.