2023-01-17 08:11:55 +01:00
|
|
|
function ase_cel(_layer, _data, _file) constructor {
|
|
|
|
data = _data;
|
|
|
|
file = _file;
|
|
|
|
layerTarget = _layer;
|
|
|
|
|
|
|
|
static checkSurface = function() {
|
|
|
|
var width = data[? "Width"];
|
|
|
|
var height = data[? "Height"];
|
2023-02-28 09:43:01 +01:00
|
|
|
data[? "Surface"] = surface_verify(data[? "Surface"], width, height);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
var color = file[? "Color depth"];
|
|
|
|
if(color == 32) {//rgba
|
|
|
|
buffer_set_surface(data[? "Buffer"], data[? "Surface"], 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var size = width * height;
|
|
|
|
var buff = buffer_create(size * 4, buffer_fixed, 1);
|
|
|
|
buffer_seek(buff, buffer_seek_start, 0);
|
|
|
|
buffer_seek(data[? "Buffer"], buffer_seek_start, 0);
|
|
|
|
|
|
|
|
if(color == 16) { //grey
|
|
|
|
repeat(size) {
|
|
|
|
var bin = buffer_read(data[? "Buffer"], buffer_u16);
|
|
|
|
buffer_write(buff, buffer_u8, bin);
|
|
|
|
buffer_write(buff, buffer_u8, bin);
|
|
|
|
buffer_write(buff, buffer_u8, bin);
|
|
|
|
buffer_write(buff, buffer_u8, bin >> 8);
|
|
|
|
}
|
|
|
|
} else if(color == 8) { //index
|
|
|
|
var palet = file[? "Palette"];
|
|
|
|
|
|
|
|
repeat(size) {
|
|
|
|
var bin = buffer_read(data[? "Buffer"], buffer_u8);
|
|
|
|
var cc = array_safe_get(palet, bin);
|
|
|
|
for( var i = 0; i < 4; i++ )
|
|
|
|
buffer_write(buff, buffer_u8, cc[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer_set_surface(buff, data[? "Surface"], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSurface = function() {
|
|
|
|
var type = data[? "Cel type"];
|
|
|
|
|
|
|
|
if(type == 0) {
|
|
|
|
|
|
|
|
} else if(type == 1) {
|
|
|
|
var frTarget = data[? "Frame position"];
|
|
|
|
var cel = layerTarget.getCel(frTarget);
|
|
|
|
if(!cel) return noone;
|
|
|
|
return cel.getSurface();
|
|
|
|
} else if(type == 2) {
|
|
|
|
checkSurface();
|
|
|
|
return data[? "Surface"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return noone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ase_layer(name) constructor {
|
|
|
|
self.name = name;
|
|
|
|
cels = [];
|
|
|
|
tag = noone;
|
|
|
|
|
2024-02-25 11:02:10 +01:00
|
|
|
static setFrameCel = function(index, cel) { INLINE cels[index] = cel; }
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static getCel = function(index = CURRENT_FRAME) {
|
2023-01-17 08:11:55 +01:00
|
|
|
var ind;
|
|
|
|
|
|
|
|
if(tag != noone) {
|
|
|
|
var st = tag[? "Frame start"];
|
|
|
|
var ed = tag[? "Frame end"];
|
2023-02-20 10:16:31 +01:00
|
|
|
ind = st + safe_mod(index, ed - st + 1);
|
2023-01-17 08:11:55 +01:00
|
|
|
} else
|
2023-02-20 10:16:31 +01:00
|
|
|
ind = safe_mod(index, array_length(cels));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
return array_safe_get(cels, ind);
|
|
|
|
}
|
|
|
|
}
|