Skip to content

Commit 34b4432

Browse files
committed
fix(modrinth): 修复未知项目类型反序列化失败问题
1 parent 21602cc commit 34b4432

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/download/assets/platform/modrinth/ModrinthSearchResult.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.movtery.zalithlauncher.game.download.assets.platform.PlatformFilterCo
2525
import com.movtery.zalithlauncher.game.download.assets.platform.PlatformSearchData
2626
import com.movtery.zalithlauncher.game.download.assets.platform.PlatformSearchResult
2727
import com.movtery.zalithlauncher.game.download.assets.platform.modrinth.models.ModrinthModLoaderCategory
28-
import com.movtery.zalithlauncher.game.download.assets.platform.modrinth.models.ModrinthProjectType
2928
import com.movtery.zalithlauncher.game.download.assets.platform.modrinth.models.ModrinthSide
3029
import com.movtery.zalithlauncher.game.download.assets.platform.modrinth.models.MonetizationStatus
3130
import com.movtery.zalithlauncher.game.download.assets.platform.modrinth.models.mapModrinthCategory
@@ -76,7 +75,7 @@ class ModrinthSearchResult(
7675
* 项目类型 **required**
7776
*/
7877
@SerialName("project_type")
79-
val projectType: ModrinthProjectType,
78+
val projectType: String,
8079

8180
/**
8281
* 项目简洁字符串标识符 **un-required**

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/download/assets/platform/modrinth/models/ModrinthProjectType.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ enum class ModrinthProjectType(val platform: PlatformClasses?) {
3535

3636
@SerialName("shader")
3737
SHADER(PlatformClasses.SHADERS),
38+
}
3839

39-
@SerialName("minecraft_java_server")
40-
SERVER(null),
40+
fun String.mapModrinthType(): ModrinthProjectType? = when (this) {
41+
"mod" -> ModrinthProjectType.MOD
42+
"modpack" -> ModrinthProjectType.MODPACK
43+
"resourcepack" -> ModrinthProjectType.RESOURCEPACK
44+
"shader" -> ModrinthProjectType.SHADER
45+
else -> null
4146
}

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/download/assets/platform/modrinth/models/ModrinthSingleProject.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ModrinthSingleProject(
9191

9292
/** 项目的项目类型 */
9393
@SerialName("project_type")
94-
val projectType: ModrinthProjectType,
94+
val projectType: String,
9595

9696
/** 项目的下载总数 */
9797
@SerialName("downloads")
@@ -244,7 +244,9 @@ class ModrinthSingleProject(
244244

245245
override fun platformId(): String = id
246246

247-
override fun platformClasses(defaultClasses: PlatformClasses): PlatformClasses = projectType.platform ?: defaultClasses
247+
override fun platformClasses(defaultClasses: PlatformClasses): PlatformClasses {
248+
return projectType.mapModrinthType()?.platform ?: defaultClasses
249+
}
248250

249251
override fun platformSlug(): String = slug
250252

@@ -269,7 +271,7 @@ class ModrinthSingleProject(
269271
}
270272

271273
override fun checkClasses() {
272-
if (projectType.platform == null) throw UnsupportedClassesException(projectType.name)
274+
if (projectType.mapModrinthType() == null) throw UnsupportedClassesException(projectType)
273275
}
274276

275277
override fun platformCategories(classes: PlatformClasses): List<PlatformFilterCode>? {
@@ -283,7 +285,7 @@ class ModrinthSingleProject(
283285
}
284286

285287
override fun platformUrls(defaultClasses: PlatformClasses): PlatformProject.Urls {
286-
val classes = projectType.platform ?: defaultClasses
288+
val classes = projectType.mapModrinthType()?.platform ?: defaultClasses
287289
return PlatformProject.Urls(
288290
projectUrl = "https://modrinth.com/${classes.modrinth!!.facetValue()}/${slug}",
289291
sourceUrl = sourceUrl,

0 commit comments

Comments
 (0)