-- anim.lua

--[[
Code to test reading and parsing animations
--]]

--[[
Format:

varName = {
	repeatCount = 0, -- optional integer, number of times to repeat tween (default 1, 0 = loop forever)
	autoRewind = true, -- optional, determines if tween returns to frame 0 on end (default false)
	orientToPath = true, -- optional, determines if object rotates to follow path (default false)
	autoPlay = true, -- optional, determines if animation plays automatically (default false)

 	-- optional, determines the point from which transformations like scale and skew perform.
	-- These values represent an image percent from 0 to 1, or pixels if transformPointInPixels is true
	-- Default value is { x = 0, y = 0}.
	transformationPoint = {x = 0, y = 0},

	-- optional, determines if values in transformationPoint represent a percent (false) or pixels (true)
	-- Default value is false (percent).
	transformPointInPixels = true,

	-- Allows applying transformations to the animation position only (scale and rotation will remain the same).
	positionMatrix = {x = 0, y = 0, scaleX = 1, scaleY = 1, rotation = 0},

	-- list of keyframes (at least two)
	keyframes = {
		{
			index = 0, -- required integer, placement of the keyframe in time (frame)
			label = "label" -- optional, keyframe name (allows seeking easily later)
			x = 0, -- optional, x position (place only properties being tweened)
			y = 0, -- optional, y position (place only properties being tweened)
			scaleX = 0, -- optional, x scale from 0 to 1 (place only properties being tweened)
			scaleY = 0, -- optional, y scale from 0 to 1 (place only properties being tweened)

			sourceRect = {x1 = 0, y1 = 0, x2 = 1, y2 = 1},   -- Allows mask animation (values represent an image percentage)

			-- For normal rotation use the same value for skewX and skewY (in degrees)
			skewX = 0, -- optional, x skew (place only properties being tweened)
			skewY = 0, -- optional, y skew (place only properties being tweened)

			-- optional, determines the transparency of the object (0 = totally tranparent, 1 = opaque)
			alpha = 1,

			-- optional integer, rotation direction
			-- ROTATION_DIRECTION_AUTO = 0 (default)
			-- ROTATION_DIRECTION_CW = 1
			-- ROTATION_DIRECTION_CCW = 2
			rotateDirection = ROTATION_DIRECTION_AUTO,

			-- optional integer, number of times to rotate in addition to skew settings (default 0)
			rotateTimes = 0,

			-- optional, determines the way the image blends with other content
			-- BLEND_MODE_NORMAL = 0
			-- BLEND_MODE_ADD = 2
			-- BLEND_MODE_SUBTRACT = 3
			-- BLEND_MODE_MULTIPLY = 4
			-- defaults to NORMAL
			blendMode = BLEND_MODE_NORMAL,

			-- optional, determines visibility of the object in this keyframe
			-- if true, keyframe will be blank and object will be invisible
			-- all that until the next keyframe starts.
			blank = false,

			-- optional, to allow color animation
			color = {
				red = 1, -- red value from 0 to 1
				green = 1, -- green value from 0 to 1
				blue = 1, -- blue value from 0 to 1
			},

			-- Tweens are created only when animation is desired between this keyframe
			-- and the next. Last keyframe doesn't need this property
			tweens = {
				-- FunctionEase tween: uses a function to calculate animation
				{
					-- Required type to determine tween type
					type = "FunctionEase",

					-- Optional integer, determines which properties the tween affects (default TWEEN_ALL)
					-- TWEEN_ALL = 0
					-- TWEEN_X = 1
					-- TWEEN_Y = 2
					-- TWEEN_POSITION = 3
					-- TWEEN_SCALE = 4
					-- TWEEN_SCALEX = 5
					-- TWEEN_SCALEY = 6
					-- TWEEN_ROTATION = 7
					-- TWEEN_SKEWX = 8
					-- TWEEN_SKEWY = 9
					-- TWEEN_ALPHA = 10
					-- TWEEN_COLOR = 11
					-- TWEEN_RECT = 12
					target = TWEEN_ALL,

					-- Required, function to be used to calculate animation. Valid functions are:

					-- Back: animates fast past the desired point for a while and then it comes back.
					-- Bounce: animates using a bounce effect.
					-- Circular: animates normally using Circular calculations.
					-- Cubic: animates normally using Cubic calculations.
					-- Elastic: animates using an elastic effect.
					-- Exponential: animates normally using Exponential calculations.
					-- Linear: animates normally without any acceleration (linear movement).
					-- Quadratic: animates normally using Quadratic calculations.
					-- Quartic: animates normally using Quartic calculations.
					-- Quintic: animates normally using Quintic calculations.
					-- Sine: animates normally using Sine calculations.
					functionName = "Elastic",

					-- Optional, determines if the effect is used at the beginning "easeIn"
					-- at the end "easeOut" or at both ends "easeInOut".
					easingMethod = "easeOut",

					-- Optional, Amount of overshoot, use it only with the "Bounce" function
					overshootAmount=5,

					-- Optional, use them only with the "Elastic" function to control the elasticity effect
					sineWavePeriod = 5,
					sineWaveAmplitude = 10,
				},

				-- SimpleEase tween: uses a simple acceleration system
				{
					-- Required type to determine tween type
					type = "SimpleEase",

					-- Optional integer, determines which properties the tween affects (default TWEEN_ALL)
					-- TWEEN_ALL = 0
					-- TWEEN_X = 1
					-- TWEEN_Y = 2
					-- TWEEN_POSITION = 3
					-- TWEEN_SCALE = 4
					-- TWEEN_SCALEX = 5
					-- TWEEN_SCALEY = 6
					-- TWEEN_ROTATION = 7
					-- TWEEN_SKEWX = 8
					-- TWEEN_SKEWY = 9
					-- TWEEN_ALPHA = 10
					-- TWEEN_COLOR = 11
					-- TWEEN_RECT = 12
					target = TWEEN_ALL,

					-- Optional (-1 to 1), determines acceleration (-1) or deceleration(1),
					-- defaults to (0) linear movement.
					ease = 0,
				},

				-- CustomEase tween: uses a an acceleration system based on bezier curves
				{
					-- Required type to determine tween type
					type = "CustomEase",

					-- Optional integer, determines which properties the tween affects (default TWEEN_ALL)
					-- TWEEN_ALL = 0
					-- TWEEN_X = 1
					-- TWEEN_Y = 2
					-- TWEEN_POSITION = 3
					-- TWEEN_SCALE = 4
					-- TWEEN_SCALEX = 5
					-- TWEEN_SCALEY = 6
					-- TWEEN_ROTATION = 7
					-- TWEEN_SKEWX = 8
					-- TWEEN_SKEWY = 9
					-- TWEEN_ALPHA = 10
					-- TWEEN_COLOR = 11
					-- TWEEN_RECT = 12
					target = TWEEN_ALL,

					-- The points defining the curve. Each segment contains 4 points (point, control point, control point, point)
					-- The first and last points cannot be change so you don't need to add them here.
					-- For example for a path with two segments you need 3 points and 4 control points.
					-- But because the first and last points are not added you need: (3 + 4 - 2) 5 points.
					-- The x coordinate is the time and the y coordinate is the percent of change in that time.
					points = {
						{x = 0.456, y = 0.678},
						{x = 0.656, y = 0.5676},
						{x = 0.856, y = 0.238},
					},
				},
			},
		},
		{
			-- create other keyframes as desired
		},
	},
}

--]]

-- animation constats

ROTATION_DIRECTION_AUTO = 0;
ROTATION_DIRECTION_CW = 1;
ROTATION_DIRECTION_CCW = 2;

TWEEN_ALL = 0;
TWEEN_X = 1;
TWEEN_Y = 2;
TWEEN_POSITION = 3;
TWEEN_SCALE = 4;
TWEEN_SCALEX = 5;
TWEEN_SCALEY = 6;
TWEEN_ROTATION = 7;
TWEEN_SKEWX = 8;
TWEEN_SKEWY = 9;
TWEEN_ALPHA = 10;
TWEEN_COLOR = 11;
TWEEN_RECT = 12;
