Ayfri
12/17/2021, 2:39 PMDominaezzz
12/17/2021, 2:46 PMAyfri
12/17/2021, 2:52 PMinterface Template {
@Composable
fun Content()
}
abstract class VanillaCraft : Template
class ItemTemplate : VanillaTemplate() {
val id = mutableStateOf("")
val tag = mutableStateOf("")
override fun Content() { /* ... */ }
}
Dominaezzz
12/17/2021, 2:53 PMItemTemplate
with @Serializable
and annotate id
and tag
with a small custom serializer to do the wrap/unwrap for you.Ayfri
12/17/2021, 3:05 PM@Serializable
abstract class CookingRecipeSingle(
type: RecipeType,
) : RecipeTemplate() {
@SerialName("cookingtime")
val cookingTime = mutableStateOf(0)
val experience = mutableStateOf(0.0)
val group = mutableStateOf("")
val ingredient = mutableStateOf(ItemTemplate())
val result = mutableStateOf("")
init {
this.type.value = type
}
override fun Content() { /* ... */ }
}
This class is used by multiple other classes
RecipeType is an enum
Exemple :
@Serializable
class BlastingRecipeSingleTemplate : CookingRecipeSingle(RecipeType.BLASTING) {
init {
cookingTime.value = 100
}
}
but the @Serializable annotation doesn't work as it gives me this error
This class is not serializable automatically because it has primary constructor parameters that are not properties
So how can I do ?Dominaezzz
12/17/2021, 3:08 PMAyfri
12/17/2021, 3:12 PM