-
Notifications
You must be signed in to change notification settings - Fork 0
Cloneable Component
Marko Koschak edited this page Aug 9, 2024
·
2 revisions
KorGE-Fleks is using a slightly expanded version of Fleks Components. Components need to be cloneable for the SnapshotSerializerSystem. Thus, KorGE-Fleks Components are derived from CloneableComponent.
For saving some time to write Component
data classes and also to make that process less error prone it is possible to use live templates in Intellij IDEA. Just open in Intellij Settings -> Live Templates. In the list choose Kotlin
and press the +
button at the top of the list box. Fill in below mentioned fields:
- Abbreviation:
flekscomponent
- Description:
creates a new Component data class for a Korge-fleks game
- Template text:
import com.github.quillraven.fleks.*
import korlibs.korge.fleks.utils.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable @SerialName("$FLEKS_COMPONENT$")
data class $FLEKS_COMPONENT$(
val name: String = ""
) : CloneableComponent<$FLEKS_COMPONENT$>() {
override fun type() = $FLEKS_COMPONENT$
companion object : ComponentType<$FLEKS_COMPONENT$>()
// Author's hint: Check if deep copy is needed on any change in the component!
override fun clone(): $FLEKS_COMPONENT$ =
this.copy()
}
Then click on Define
and choose Kotlin from the drop-down menu. Finally press the Apply
button to save the changes.