[go: nahoru, domu]

Skip to content

Commit

Permalink
1.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
izhangzhihao committed Aug 27, 2021
1 parent 3c8c7c9 commit 1255375
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ idea {
dependencies {
implementation('io.timeandspace:cron-scheduler:0.1')
implementation('javazoom:jlayer:1.0.1')
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.+") {
exclude module: "kotlin-stdlib"
exclude module: "kotlin-stdlib-common"
exclude module: "kotlin-stdlib-jdk7"
exclude module: "kotlin-stdlib-jdk8"
exclude module: "kotlin-reflect"
}
}

sourceCompatibility = javaVersion
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ kotlinVersion=1.4.21
kotlinLanguageVersion=1.4
kotlinTargetVersion=1.4
version=1.3.4
publishChannels=Stable
publishChannels=Stable
kotlin.stdlib.default.dependency=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.izhangzhihao.rainbow.fart

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.github.izhangzhihao.rainbow.fart.BuildInContributes.buildInContributes
import com.github.izhangzhihao.rainbow.fart.BuildInContributes.cron
Expand Down Expand Up @@ -31,30 +31,32 @@ class ResourcesLoader : StartupActivity {
}
val customVoicePackage = RainbowFartSettings.instance.customVoicePackage
val current =
if (customVoicePackage != "") {
resolvePath(customVoicePackage + File.separator + "manifest.json").readText()
} else {
ResourcesLoader::class.java.getResource("/build-in-voice-chinese/manifest.json").readText()
}

val mapper = jacksonObjectMapper()
if (customVoicePackage != "") {
resolvePath(customVoicePackage + File.separator + "manifest.json").readText()
} else {
ResourcesLoader::class.java.getResource("/build-in-voice-chinese/manifest.json").readText()
}

mapper.registerModule(KotlinModule(nullToEmptyCollection = true, nullToEmptyMap = true, nullIsSameAsDefault = true))
/***
* https://github.com/FasterXML/jackson-module-kotlin#usage
*/
val mapper = JsonMapper.builder().addModule(KotlinModule(nullIsSameAsDefault = true)).build()

mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)

val manifest: Manifest = mapper.readValue(current)

val contributes: List<Contribute> =
if (manifest.contributes != null) {
manifest.contributes
} else if (customVoicePackage != "") {
val contText = resolvePath(customVoicePackage + File.separator + "contributes.json").readText()
mapper.readValue<Contributes>(contText).contributes
} else {
val contText = ResourcesLoader::class.java.getResource("/build-in-voice-chinese/contributes.json").readText()
mapper.readValue<Contributes>(contText).contributes
}
if (manifest.contributes != null) {
manifest.contributes
} else if (customVoicePackage != "") {
val contText = resolvePath(customVoicePackage + File.separator + "contributes.json").readText()
mapper.readValue<Contributes>(contText).contributes
} else {
val contText =
ResourcesLoader::class.java.getResource("/build-in-voice-chinese/contributes.json").readText()
mapper.readValue<Contributes>(contText).contributes
}

contributes.forEach {
it.keywords.forEach { keyword ->
Expand Down Expand Up @@ -128,10 +130,19 @@ class ResourcesLoader : StartupActivity {
}
}

data class Manifest(val name: String = "", @JsonProperty("display-name") val displayName: String = "",
val avatar: String = "", @JsonProperty("avatar-dark") val avatarDark: String = "",
val version: String = "1.0.0", val description: String = "", val languages: List<String> = emptyList(),
val author: String = "No one", val gender: String = "female", val locale: String = "zh", val contributes: List<Contribute>?)
data class Manifest(
val name: String = "",
@JsonProperty("display-name") val displayName: String = "",
val avatar: String = "",
@JsonProperty("avatar-dark") val avatarDark: String = "",
val version: String = "1.0.0",
val description: String = "",
val languages: List<String> = emptyList(),
val author: String = "No one",
val gender: String = "female",
val locale: String = "zh",
val contributes: List<Contribute>?
)

data class Contribute(val keywords: List<String>, val voices: List<String>)

Expand Down

0 comments on commit 1255375

Please sign in to comment.