UNPKG

@dcl/ecs

Version:
153 lines (152 loc) 4.59 kB
import { Tween } from '../generated/index.gen'; const TweenHelper = { Move(move) { return { $case: 'move', move }; }, MoveContinuous(moveContinuous) { return { $case: 'moveContinuous', moveContinuous }; }, Rotate(rotate) { return { $case: 'rotate', rotate }; }, RotateContinuous(rotateContinuous) { return { $case: 'rotateContinuous', rotateContinuous }; }, Scale(scale) { return { $case: 'scale', scale }; }, TextureMove(textureMove) { return { $case: 'textureMove', textureMove }; }, TextureMoveContinuous(textureMoveContinuous) { return { $case: 'textureMoveContinuous', textureMoveContinuous }; } }; export function defineTweenComponent(engine) { const theComponent = Tween(engine); return { ...theComponent, Mode: TweenHelper, setMove(entity, start, end, duration, easingFunction = 0 /* EasingFunction.EF_LINEAR */) { theComponent.createOrReplace(entity, { mode: { $case: 'move', move: { start, end } }, duration, easingFunction, playing: true }); }, setScale(entity, start, end, duration, easingFunction = 0 /* EasingFunction.EF_LINEAR */) { theComponent.createOrReplace(entity, { mode: { $case: 'scale', scale: { start, end } }, duration, easingFunction, playing: true }); }, setRotate(entity, start, end, duration, easingFunction = 0 /* EasingFunction.EF_LINEAR */) { theComponent.createOrReplace(entity, { mode: { $case: 'rotate', rotate: { start, end } }, duration, easingFunction, playing: true }); }, setTextureMove(entity, start, end, duration, movementType = 0 /* TextureMovementType.TMT_OFFSET */, easingFunction = 0 /* EasingFunction.EF_LINEAR */) { theComponent.createOrReplace(entity, { mode: { $case: 'textureMove', textureMove: { start, end, movementType } }, duration, easingFunction, playing: true }); }, setMoveContinuous(entity, direction, speed, duration = 0) { theComponent.createOrReplace(entity, { mode: { $case: 'moveContinuous', moveContinuous: { direction, speed } }, duration, easingFunction: 0 /* EasingFunction.EF_LINEAR */, playing: true }); }, setRotateContinuous(entity, direction, speed, duration = 0) { theComponent.createOrReplace(entity, { mode: { $case: 'rotateContinuous', rotateContinuous: { direction, speed } }, duration, easingFunction: 0 /* EasingFunction.EF_LINEAR */, playing: true }); }, setTextureMoveContinuous(entity, direction, speed, movementType = 0 /* TextureMovementType.TMT_OFFSET */, duration = 0) { theComponent.createOrReplace(entity, { mode: { $case: 'textureMoveContinuous', textureMoveContinuous: { direction, speed, movementType } }, duration, easingFunction: 0 /* EasingFunction.EF_LINEAR */, playing: true }); } }; }