Pixel-Composer/scripts/Tweener/Tweener.gml

55 lines
1.2 KiB
Text
Raw Normal View History

2023-03-26 07:13:36 +02:00
enum TWEEN_TYPE {
linear,
log
}
enum TWEEN_VALUE {
number,
color
}
2023-03-28 06:58:28 +02:00
function Tween(value, valType = TWEEN_VALUE.number, twType = TWEEN_TYPE.log, twSpeed = 2) constructor {
2023-03-26 07:13:36 +02:00
array_push(TWEEN_VALUES, self);
realVal = value;
showVal = value;
self.valType = valType;
tweenType = twType;
tweenSpeed = twSpeed;
colTrans = 0;
static set = function(value) {
2023-03-28 06:58:28 +02:00
if(valType == TWEEN_VALUE.color) {
2023-03-26 07:13:36 +02:00
showVal = get();
colTrans = 0;
}
realVal = value;
}
2023-05-08 10:50:42 +02:00
static get = function() {
2023-03-28 06:58:28 +02:00
if(valType == TWEEN_VALUE.color)
2023-03-26 07:13:36 +02:00
return colTrans == 1? realVal : merge_color(showVal, realVal, colTrans);
else
return showVal;
}
static step = function() {
2023-03-28 06:58:28 +02:00
if(valType == TWEEN_VALUE.color) {
2023-03-26 07:13:36 +02:00
if(tweenType == TWEEN_TYPE.linear)
colTrans = lerp_linear(colTrans, 1, 1 / tweenSpeed);
else if(tweenType == TWEEN_TYPE.log)
colTrans = lerp_float(colTrans, 1, tweenSpeed);
if(colTrans == 1)
showVal = realVal;
2023-03-28 06:58:28 +02:00
} else if(valType == TWEEN_VALUE.number) {
2023-03-26 07:13:36 +02:00
if(tweenType == TWEEN_TYPE.linear)
showVal = lerp_linear(showVal, realVal, 1 / tweenSpeed);
else if(tweenType == TWEEN_TYPE.log)
showVal = lerp_float(showVal, realVal, tweenSpeed);
}
}
static destroy = function() { array_remove(TWEEN_VALUES, self); }
}