Pixel-Composer/scripts/animation_controller/animation_controller.gml

119 lines
2.5 KiB
Plaintext
Raw Normal View History

2023-05-22 20:31:55 +02:00
#region global
global.FLAG.keyframe_override = true;
2023-07-06 19:49:16 +02:00
enum ANIMATOR_END {
loop,
stop
}
2023-07-25 20:12:40 +02:00
#macro ANIMATION_STATIC !(PROJECT.animator.is_playing || PROJECT.animator.frame_progress)
2023-05-22 20:31:55 +02:00
#endregion
#region animation class
2022-12-10 05:06:01 +01:00
function AnimationManager() constructor {
2023-03-07 14:29:47 +01:00
frames_total = 30;
current_frame = 0;
real_frame = 0;
2023-01-01 02:06:02 +01:00
time_since_last_frame = 0;
2023-03-07 14:29:47 +01:00
framerate = 30;
is_playing = false;
frame_progress = false;
play_freeze = 0;
2022-12-10 05:06:01 +01:00
2022-12-23 04:45:52 +01:00
rendering = false;
2022-12-10 05:06:01 +01:00
playback = ANIMATOR_END.loop;
static setFrame = function(frame) {
2023-04-10 20:02:59 +02:00
//if(frame == 0) resetAnimation();
2022-12-12 09:08:03 +01:00
var _c = current_frame;
2023-02-14 02:51:14 +01:00
frame = clamp(frame, 0, frames_total);
2022-12-10 05:06:01 +01:00
real_frame = frame;
current_frame = round(frame);
2022-12-12 09:08:03 +01:00
2023-02-14 02:51:14 +01:00
if(current_frame == frames_total) {
2023-06-04 12:38:40 +02:00
if(rendering) {
2023-02-14 02:51:14 +01:00
is_playing = false;
rendering = false;
2023-06-04 12:38:40 +02:00
setFrame(0);
} else if(playback == ANIMATOR_END.stop)
is_playing = false;
else
2023-02-14 02:51:14 +01:00
setFrame(0);
}
if(_c != current_frame) {
2022-12-12 09:08:03 +01:00
frame_progress = true;
2023-02-14 02:51:14 +01:00
time_since_last_frame = 0;
2023-03-31 06:59:08 +02:00
UPDATE |= RENDER_TYPE.full;
2023-03-02 07:59:14 +01:00
} else
frame_progress = false;
2022-12-10 05:06:01 +01:00
}
2023-04-10 20:02:59 +02:00
static resetAnimation = function() {
2023-07-06 19:49:16 +02:00
var _key = ds_map_find_first(PROJECT.nodeMap);
var amo = ds_map_size(PROJECT.nodeMap);
2023-04-10 20:02:59 +02:00
repeat(amo) {
2023-07-06 19:49:16 +02:00
var _node = PROJECT.nodeMap[? _key];
2023-04-10 20:02:59 +02:00
_node.resetAnimation();
2023-07-06 19:49:16 +02:00
_key = ds_map_find_next(PROJECT.nodeMap, _key);
2023-04-10 20:02:59 +02:00
}
}
2023-05-16 21:28:16 +02:00
static render = function() {
2023-07-25 20:12:40 +02:00
setFrame(0);
2023-05-16 21:28:16 +02:00
is_playing = true;
rendering = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-05-16 21:28:16 +02:00
}
2023-06-04 12:38:40 +02:00
static toggle = function() {
2023-07-06 19:49:16 +02:00
is_playing = !is_playing;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-06-04 12:38:40 +02:00
}
2023-05-16 21:28:16 +02:00
static pause = function() {
2023-07-06 19:49:16 +02:00
is_playing = false;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-05-16 21:28:16 +02:00
}
2023-05-22 20:31:55 +02:00
static play = function() {
2023-07-25 20:12:40 +02:00
setFrame(0);
2023-07-06 19:49:16 +02:00
is_playing = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-05-22 20:31:55 +02:00
}
2023-05-16 21:28:16 +02:00
static resume = function() {
2023-07-06 19:49:16 +02:00
is_playing = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-05-16 21:28:16 +02:00
}
static stop = function() {
setFrame(0);
2023-07-25 20:12:40 +02:00
is_playing = false;
time_since_last_frame = 0;
}
static step = function() {
if(is_playing && play_freeze == 0) {
time_since_last_frame += framerate * (delta_time / 1000000);
if(time_since_last_frame >= 1)
setFrame(real_frame + 1);
} else {
frame_progress = false;
//setFrame(real_frame);
time_since_last_frame = 0;
}
play_freeze = max(0, play_freeze - 1);
2023-05-16 21:28:16 +02:00
}
2022-12-10 05:06:01 +01:00
}
#endregion