Description

A task is a function executed at the beginning of addAnimations, before selector and properties information is processed, and has the following goals:

  • Setup: A setup allows to prepare elements for further processing.
    An example is text splitting. text splitting prepares DOM for individual character manipulation.
    Setup tasks can stop the processing of a addAnimations, and might not require a selector..

  • Wrapping: Only addAnimations can be stored in a JSON file or sent for remote rendering. In this case, methods such as addStills and scene transitions need to be wrapped in a task.
    Wrapping tasks can stop the processing of a addAnimations, and might not require a selector.

  • Asset creation: A task can create an asset avoiding the need of loading external assets such as svg shape files.

  • Complex animations: A task can simplify the creation of a complex animation.

F/X

If you just want to do a single-shot animation, use scene.addAnimations, but if you want to reuse the animation or want to break down the complexity into multiple parts, the best is to create a task.

A task implementation is a function with the following syntax:

function myTaskFunc(anime: Animation, wkTask: WorkTask,
  params: FactoryTaskParams, stage?: uint, args?: ABeamerArgs): TaskResult;

And add this task to ABeamer using ABeamer.pluginManager.addTasks([['my-task', myTaskFunc]]);.

If the task just uses plain DOM, the simplest is to:
- inject DOM by using the animation selector, and then

switch (stage) {
   case TS_INIT:  
     const adapters = args.scene.getElementAdapters(anime.selector);
     elAdapters.forEach((elAdapter, elIndex) => {
       const html = elAdapter.getProp('html', args);
       const myPiece = '<div>Hello</div>';
       elAdapter.setProp('html', html + myPiece, args);
     });
}
  • inject animation properties into the pipeline by:
switch (stage) {
   case TS_INIT:  
     anime.props.push({ prop: 'text', value: ['hello'] });
}
 

API

TaskResult

public export type

export type TaskResult = 0 | 1 | 2;

TaskFunc

public export type

export type TaskFunc = (anime: Animation, wkTask: WorkTask,
    params?: AnyParams, stage?: uint, args?: ABeamerArgs) => TaskResult;

TaskHandler

public export type

export type TaskHandler = TaskName | TaskFunc;

TaskName

public export type

export type TaskName = string
    | GeneralTaskName
    | TextTaskName
    | ShapeTaskName
    | AttackTaskName;

TaskParams

public export type

export type TaskParams = AnyParams
    | GeneralTaskParams
    | TextTaskParams
    | ShapeTaskParams
    | AttackTaskParams;
 

Task

public export interface

export interface Task{ }

Parameters provided by the user during an addAnimation.

Task.handler

public property [Task]

handler: TaskHandler;

Task Name, Expression or Input Function defined by the user.

Task.params

public property [Task]

params?: TaskParams;

Parameters passed to the task function

 

WorkTask

public export interface

export interface WorkTask{ }

Parameters passed to a task during the execution.

WorkTask.name

public property [WorkTask]

name: string;

WorkTask.params

public property [WorkTask]

params: TaskParams;

WorkTask.animeIndex

public property [WorkTask]

animeIndex: uint;

GeneralTaskName

public export type

export type GeneralTaskName =
    /** @see TaskFactoryParams */
    | 'factory';

GeneralTaskParams

public export type

export type GeneralTaskParams =
    | FactoryTaskParams;

FactoryTaskAttr

public export type

export type FactoryTaskAttr = string | ExprString | number | string[] | number[];
 

FactoryTaskParams

public export interface

export interface FactoryTaskParams extends AnyParams{ }

FactoryTaskParams.count

public property [FactoryTaskParams]

count: uint | ExprString;

FactoryTaskParams.tag

public property [FactoryTaskParams]

tag?: string;

FactoryTaskParams.content

public property [FactoryTaskParams]

content?: FactoryTaskAttr;

FactoryTaskParams.isContentFormatted

public property [FactoryTaskParams]

isContentFormatted?: boolean;

FactoryTaskParams.attrs

public property [FactoryTaskParams]

attrs?: {
      name: string;