@@ -13,8 +13,9 @@ import dev.icerock.gradle.generator.ios.IosMRGenerator.Companion.ASSETS_DIR_NAME
1313import dev.icerock.gradle.utils.ArgbColor
1414import dev.icerock.gradle.utils.parseRgbaColor
1515import kotlinx.serialization.json.JsonObject
16- import kotlinx.serialization.json.json
17- import kotlinx.serialization.json.jsonArray
16+ import kotlinx.serialization.json.buildJsonArray
17+ import kotlinx.serialization.json.buildJsonObject
18+ import kotlinx.serialization.json.put
1819import org.gradle.api.file.FileTree
1920import java.io.File
2021
@@ -43,6 +44,7 @@ class IosColorsGenerator(
4344 val colorContentObj = if (colorNode.isThemed()) {
4445 @Suppress(" MagicNumber" )
4546 val lightColor = parseRgbaColor(colorNode.lightColor!! .toLong(16 ))
47+
4648 @Suppress(" MagicNumber" )
4749 val darkColor = parseRgbaColor(colorNode.darkColor!! .toLong(16 ))
4850
@@ -54,53 +56,55 @@ class IosColorsGenerator(
5456 val lightColorObj = buildAppearancesIdiomJsonBlock(" light" , lightColor)
5557 val darkColorObj = buildAppearancesIdiomJsonBlock(" dark" , darkColor)
5658
57- jsonArray {
58- + anyColor
59- + lightColorObj
60- + darkColorObj
59+ buildJsonArray {
60+ add( anyColor)
61+ add( lightColorObj)
62+ add( darkColorObj)
6163 }
6264 } else {
6365 @Suppress(" MagicNumber" )
6466 val singleColor = parseRgbaColor(colorNode.singleColor!! .toLong(16 ))
65- jsonArray { + buildColorIdiomJsonObj(singleColor) }
67+ buildJsonArray {
68+ add(buildColorIdiomJsonObj(singleColor))
69+ }
6670 }
6771
68- val resultObj = json {
69- " colors" to colorContentObj
70- " info" to json {
71- " author" to " xcode"
72- " version" to 1
73- }
72+ val resultObj = buildJsonObject {
73+ put( " colors" , colorContentObj)
74+ put( " info" , buildJsonObject {
75+ put( " author" , " xcode" )
76+ put( " version" , 1 )
77+ })
7478 }
7579 contentsFile.writeText(resultObj.toString())
7680 }
7781 }
7882
79- private fun buildColorJsonObj (argbColor : ArgbColor ): JsonObject = json {
80- " color-space" to " srgb"
81- " components" to json {
82- " alpha" to argbColor.a
83- " red" to argbColor.r
84- " green" to argbColor.g
85- " blue" to argbColor.b
86- }
83+ private fun buildColorJsonObj (argbColor : ArgbColor ): JsonObject = buildJsonObject {
84+ put( " color-space" , " srgb" )
85+ put( " components" , buildJsonObject {
86+ put( " alpha" , argbColor.a)
87+ put( " red" , argbColor.r)
88+ put( " green" , argbColor.g)
89+ put( " blue" , argbColor.b)
90+ })
8791 }
8892
89- private fun buildColorIdiomJsonObj (argbColor : ArgbColor ): JsonObject = json {
90- " color" to buildColorJsonObj(argbColor)
91- " idiom" to " universal"
93+ private fun buildColorIdiomJsonObj (argbColor : ArgbColor ): JsonObject = buildJsonObject {
94+ put( " color" , buildColorJsonObj(argbColor) )
95+ put( " idiom" , " universal" )
9296 }
9397
9498 private fun buildAppearancesIdiomJsonBlock (valueTag : String , argbColor : ArgbColor ): JsonObject {
95- return json {
96- " appearances" to jsonArray {
97- + json {
98- " appearance" to " luminosity"
99- " value" to valueTag
100- }
101- }
102- " color" to buildColorJsonObj(argbColor)
103- " idiom" to " universal"
99+ return buildJsonObject {
100+ put( " appearances" , buildJsonArray {
101+ add(buildJsonObject {
102+ put( " appearance" , " luminosity" )
103+ put( " value" , valueTag)
104+ })
105+ })
106+ put( " color" , buildColorJsonObj(argbColor) )
107+ put( " idiom" , " universal" )
104108 }
105109 }
106110}
0 commit comments