/
example-map-complex-02.kt
49 lines (43 loc) · 1.05 KB
/
example-map-complex-02.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This file was automatically generated from maps.md by Knit tool. Do not edit.
@file:Suppress("PackageDirectoryMismatch", "unused")
package dev.adamko.kxstsgen.example.exampleMapComplex02
import kotlinx.serialization.*
import dev.adamko.kxstsgen.*
@Serializable
data class Colour(
val r: UByte,
val g: UByte,
val b: UByte,
val a: UByte,
)
/**
* Encode a [Colour] as an 8-character string
*
* Red, green, blue, and alpha are encoded as base-16 strings.
*/
@Serializable
@JvmInline
value class ColourMapKey(private val rgba: String) {
constructor(colour: Colour) : this(
listOf(
colour.r,
colour.g,
colour.b,
colour.a,
).joinToString("") {
it.toString(16).padStart(2, '0')
}
)
fun toColour(): Colour {
val (r, g, b, a) = rgba.chunked(2).map { it.toUByte(16) }
return Colour(r, g, b, a)
}
}
@Serializable
data class CanvasProperties(
val colourNames: Map<ColourMapKey, String>
)
fun main() {
val tsGenerator = KxsTsGenerator()
println(tsGenerator.generate(CanvasProperties.serializer()))
}