Skip to content

Commit

Permalink
Start to rename Animate to Tween for PropertyComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
jobe-m committed Feb 16, 2024
1 parent 01a16f9 commit 041464a
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import kotlinx.serialization.Serializable

/**
* Generalized Animate Component Property data class. It is used for animating properties of other components
* via the [TweenSequence] components and one of the systems in AnimateSystems.kt file.
* via the [TweenSequenceComponent] components and one of the systems in AnimateSystems.kt file.
*
* value: This is set to the previous or initial value
* change: Value with which last value needs to be changed to reach the target value of the animation step
*
* In case of single switch: This value is set when easing > 0.5
*/
@Serializable
@SerialName("TweenComponent")
data class TweenComponent (
@SerialName("TweenPropertyComponent")
data class TweenPropertyComponent (
var property: TweenProperty,

@Serializable(with = AnySerializer::class)
Expand All @@ -32,8 +32,8 @@ data class TweenComponent (
var timeProgress: Float = 0f, // in seconds
@Serializable(with = EasingSerializer::class)
var easing: Easing = Easing.LINEAR // Changing function
) : Component<TweenComponent>, SerializeBase {
override fun type(): ComponentType<TweenComponent> = property.type
) : Component<TweenPropertyComponent>, SerializeBase {
override fun type(): ComponentType<TweenPropertyComponent> = property.type

companion object {
// TODO update unit test for this mapping from enum to here
Expand All @@ -44,7 +44,7 @@ data class TweenComponent (
val AnimateSpriteDestroyOnPlayingFinished = TweenProperty.SpriteDestroyOnPlayingFinished.type
val AnimateSpriteAnimName = TweenProperty.SpriteAnimName.type

val AnimateAppearanceAlpha = TweenProperty.AppearanceAlpha.type
val TweenAppearanceAlphaComponent = TweenProperty.AppearanceAlpha.type
val AnimateAppearanceTint = TweenProperty.AppearanceTint.type
val AnimateAppearanceVisible = TweenProperty.AppearanceVisible.type

Expand All @@ -55,8 +55,8 @@ data class TweenComponent (

val AnimateLifeCycleHealthCounter = TweenProperty.LifeCycleHealthCounter.type

val AnimatePositionShapeX = TweenProperty.PositionShapeX.type
val AnimatePositionShapeY = TweenProperty.PositionShapeY.type
val TweenPositionShapeXComponent = TweenProperty.PositionShapeX.type
val TweenPositionShapeYComponent = TweenProperty.PositionShapeY.type

val AnimateOffsetX = TweenProperty.OffsetX.type
val AnimateOffsetY = TweenProperty.OffsetY.type
Expand All @@ -80,45 +80,45 @@ data class TweenComponent (

/**
* All final [TweenProperty] names are organized in this enum. This is done to easily serialize the
* [property](TweenComponent.property) of the base [TweenComponent] data class.
* [property](TweenComponent.property) of the base [TweenPropertyComponent] data class.
*/
enum class TweenProperty(val type: ComponentType<TweenComponent>) {
SpriteIsPlaying(componentTypeOf<TweenComponent>()),
SpriteForwardDirection(componentTypeOf<TweenComponent>()),
SpriteLoop(componentTypeOf<TweenComponent>()),
SpriteDestroyOnPlayingFinished(componentTypeOf<TweenComponent>()),
SpriteAnimName(componentTypeOf<TweenComponent>()),

AppearanceAlpha(componentTypeOf<TweenComponent>()),
AppearanceTint(componentTypeOf<TweenComponent>()),
AppearanceVisible(componentTypeOf<TweenComponent>()),

SpawnerNumberOfObjects(componentTypeOf<TweenComponent>()),
SpawnerInterval(componentTypeOf<TweenComponent>()),
SpawnerTimeVariation(componentTypeOf<TweenComponent>()),
SpawnerPositionVariation(componentTypeOf<TweenComponent>()),
enum class TweenProperty(val type: ComponentType<TweenPropertyComponent>) {
SpriteIsPlaying(componentTypeOf<TweenPropertyComponent>()),
SpriteForwardDirection(componentTypeOf<TweenPropertyComponent>()),
SpriteLoop(componentTypeOf<TweenPropertyComponent>()),
SpriteDestroyOnPlayingFinished(componentTypeOf<TweenPropertyComponent>()),
SpriteAnimName(componentTypeOf<TweenPropertyComponent>()),

AppearanceAlpha(componentTypeOf<TweenPropertyComponent>()),
AppearanceTint(componentTypeOf<TweenPropertyComponent>()),
AppearanceVisible(componentTypeOf<TweenPropertyComponent>()),

SpawnerNumberOfObjects(componentTypeOf<TweenPropertyComponent>()),
SpawnerInterval(componentTypeOf<TweenPropertyComponent>()),
SpawnerTimeVariation(componentTypeOf<TweenPropertyComponent>()),
SpawnerPositionVariation(componentTypeOf<TweenPropertyComponent>()),

// TODO not used yet in animation system
LifeCycleHealthCounter(componentTypeOf<TweenComponent>()),
LifeCycleHealthCounter(componentTypeOf<TweenPropertyComponent>()),

PositionShapeX(componentTypeOf<TweenComponent>()),
PositionShapeY(componentTypeOf<TweenComponent>()),
PositionShapeX(componentTypeOf<TweenPropertyComponent>()),
PositionShapeY(componentTypeOf<TweenPropertyComponent>()),

OffsetX(componentTypeOf<TweenComponent>()),
OffsetY(componentTypeOf<TweenComponent>()),
OffsetX(componentTypeOf<TweenPropertyComponent>()),
OffsetY(componentTypeOf<TweenPropertyComponent>()),

LayoutCenterX(componentTypeOf<TweenComponent>()),
LayoutCenterY(componentTypeOf<TweenComponent>()),
LayoutOffsetX(componentTypeOf<TweenComponent>()),
LayoutOffsetY(componentTypeOf<TweenComponent>()),
LayoutCenterX(componentTypeOf<TweenPropertyComponent>()),
LayoutCenterY(componentTypeOf<TweenPropertyComponent>()),
LayoutOffsetX(componentTypeOf<TweenPropertyComponent>()),
LayoutOffsetY(componentTypeOf<TweenPropertyComponent>()),

SwitchLayerVisibilityOnVariance(componentTypeOf<TweenComponent>()),
SwitchLayerVisibilityOffVariance(componentTypeOf<TweenComponent>()),
SwitchLayerVisibilityOnVariance(componentTypeOf<TweenPropertyComponent>()),
SwitchLayerVisibilityOffVariance(componentTypeOf<TweenPropertyComponent>()),

SoundStartTrigger(componentTypeOf<TweenComponent>()),
SoundStopTrigger(componentTypeOf<TweenComponent>()),
SoundPosition(componentTypeOf<TweenComponent>()),
SoundVolume(componentTypeOf<TweenComponent>()),
SoundStartTrigger(componentTypeOf<TweenPropertyComponent>()),
SoundStopTrigger(componentTypeOf<TweenPropertyComponent>()),
SoundPosition(componentTypeOf<TweenPropertyComponent>()),
SoundVolume(componentTypeOf<TweenPropertyComponent>()),

ConfigureFunction(componentTypeOf<TweenComponent>())
ConfigureFunction(componentTypeOf<TweenPropertyComponent>())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.serialization.Serializable
* This component holds all needed details to animate properties of components of entities.
*/
@Serializable @SerialName("TweenSequence")
data class TweenSequence(
data class TweenSequenceComponent(
var tweens: List<TweenBase> = listOf(),

// Internal runtime data
Expand All @@ -21,8 +21,8 @@ data class TweenSequence(
var waitTime: Float = 0f,
var executed: Boolean = false,
var initialized: Boolean = false
) : Component<TweenSequence>, SerializeBase {
override fun type(): ComponentType<TweenSequence> = TweenSequence
) : Component<TweenSequenceComponent>, SerializeBase {
override fun type(): ComponentType<TweenSequenceComponent> = TweenSequenceComponent

/**
* Initialize internal waitTime property with delay value of first tweens if available.
Expand All @@ -36,7 +36,7 @@ data class TweenSequence(

override fun World.onRemove(entity: Entity) { /* not used here */ }

companion object : ComponentType<TweenSequence>()
companion object : ComponentType<TweenSequenceComponent>()
}

interface TweenBase {
Expand All @@ -51,20 +51,20 @@ interface TweenBase {
*/
@Serializable @SerialName("SpawnNewTweenSequence")
data class SpawnNewTweenSequence(
val tweens: List<TweenBase> = listOf(), // tween objects which contain entity and its properties to be animated in sequence
val tweens: List<TweenBase> = listOf(), // tween objects which contain entity and its properties to be animated in sequence

override var entity: Entity = invalidEntity, // not used
override var delay: Float? = null,
override var duration: Float? = null,
@Serializable(with = EasingSerializer::class)
override var easing: Easing? = null // not used
override var easing: Easing? = null // not used
) : TweenBase

@Serializable @SerialName("ParallelTweens")
data class ParallelTweens(
val tweens: List<TweenBase> = listOf(), // tween objects which contain entity and its properties to be animated in parallel

override var entity: Entity = invalidEntity, // not used here
override var entity: Entity = invalidEntity, // not used here
override var delay: Float? = 0f, // in seconds
override var duration: Float? = 0f, // in seconds
@Serializable(with = EasingSerializer::class)
Expand All @@ -74,10 +74,10 @@ data class ParallelTweens(
@Serializable @SerialName("TweenSequence.Wait")
data class Wait(
override var entity: Entity = invalidEntity, // not used
override var delay: Float? = null, // Not used
override var delay: Float? = null, // Not used
override var duration: Float? = 0f,
@Serializable(with = EasingSerializer::class)
override var easing: Easing? = null // not used
override var easing: Easing? = null // not used
) : TweenBase


Expand All @@ -89,7 +89,7 @@ data class DeleteEntity(
val healthCounter: Int = 0, // set healthCounter to zero to delete the entity immediately

override var entity: Entity,
override var delay: Float? = null, // not used
override var delay: Float? = null,
override var duration: Float? = 0f, // not used - 0f for immediately
@Serializable(with = EasingSerializer::class)
override var easing: Easing? = null // not used
Expand All @@ -102,7 +102,7 @@ data class SpawnEntity(
var x: Float = 0.0f, // position where entity will be spawned
var y: Float = 0.0f,

override var entity: Entity = invalidEntity, // when entity is not given (=nullEntity) than it will be created
override var entity: Entity = invalidEntity, // when entity is not given (=invalidEntity) than it will be created
override var delay: Float? = null,
override var duration: Float? = 0f, // not used - 0f for immediately
@Serializable(with = EasingSerializer::class)
Expand All @@ -122,7 +122,7 @@ data class ExecuteConfigFunction(
) : TweenBase

// Following component classes are for triggering tweens on specific properties of components
@Serializable @SerialName("TweenSequence.TweenAppearance")
@Serializable @SerialName("TweenAppearance")
data class TweenAppearance(
val alpha: Float? = null,
val tint: Rgb? = null,
Expand All @@ -135,7 +135,7 @@ data class TweenAppearance(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenPositionShape")
@Serializable @SerialName("TweenPositionShape")
data class TweenPositionShape(
val x: Float? = null,
val y: Float? = null,
Expand All @@ -147,7 +147,7 @@ data class TweenPositionShape(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenOffset")
@Serializable @SerialName("TweenOffset")
data class TweenOffset(
val x: Float? = null,
val y: Float? = null,
Expand All @@ -159,7 +159,7 @@ data class TweenOffset(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenLayout")
@Serializable @SerialName("TweenLayout")
data class TweenLayout(
val centerX: Boolean? = null,
val centerY: Boolean? = null,
Expand All @@ -173,7 +173,7 @@ data class TweenLayout(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenSprite")
@Serializable @SerialName("TweenSprite")
data class TweenSprite(
var animationName: String? = null,
var isPlaying: Boolean? = null,
Expand All @@ -188,7 +188,7 @@ data class TweenSprite(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenSwitchLayerVisibility")
@Serializable @SerialName("TweenSwitchLayerVisibility")
data class TweenSwitchLayerVisibility(
var offVariance: Float? = null,
var onVariance: Float? = null,
Expand All @@ -201,7 +201,7 @@ data class TweenSwitchLayerVisibility(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenSpawner")
@Serializable @SerialName("TweenSpawner")
data class TweenSpawner(
var numberOfObjects: Int? = null,
var interval: Int? = null,
Expand All @@ -215,7 +215,7 @@ data class TweenSpawner(
override var easing: Easing? = null
) : TweenBase

@Serializable @SerialName("TweenSequence.TweenSound")
@Serializable @SerialName("TweenSound")
data class TweenSound(
var startTrigger: Boolean? = null,
var stopTrigger: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object FireAndDustEffect {
entity.getOrAdd(Appearance) { Appearance() }
entity.getOrAdd(LifeCycle) { LifeCycle() }
if (effectConfig.fadeOutDuration > 0f) {
entity.getOrAdd(TweenSequence) { TweenSequence() }.also {
entity.getOrAdd(TweenSequenceComponent) { TweenSequenceComponent() }.also {
it.tweens = listOf(
// Fade out effect objects
TweenAppearance(entity = entity, alpha = 0.0f, duration = effectConfig.fadeOutDuration)
Expand Down
Loading

0 comments on commit 041464a

Please sign in to comment.