Pixel-Composer/scripts/action_object/action_object.gml

66 lines
1.1 KiB
Text
Raw Normal View History

2023-08-02 19:11:57 +02:00
function actionStep() constructor {
type = "";
data = {};
2024-07-15 10:43:30 +02:00
static trigger = function() {}
2023-08-02 19:11:57 +02:00
2024-07-15 10:43:30 +02:00
static serialize = function() { return { type, data }; }
2023-08-02 19:11:57 +02:00
static deserialize = function(map) {
type = map.type;
data = map.data;
return self;
}
}
function actionObject() constructor {
name = "";
spr = noone;
isPlaying = false;
playStep = 0;
actions = [];
static step = function() {
actions[playStep].trigger();
playStep++;
if(playStep == array_length(actions)) {
isPlaying = false;
return true;
}
return false;
}
static play = function() {
if(isPlaying) return;
isPlaying = true;
playStep = 0;
}
static serialize = function() {
var map = {};
map.name = name;
map.actions = [];
for( var i = 0, n = array_length(actions); i < n; i++ )
map.actions[i] = actions[i].serialize();
return map;
}
static deserialize = function(map) {
name = map.name;
actions = [];
for( var i = 0, n = array_length(map.actions); i < n; i++ )
actions[i] = new actionStep().deserialize(map.actions[i]);
return self;
}
}