2023-01-17 08:11:55 +01:00
|
|
|
function ase_cel(_layer, _data, _file) constructor {
|
|
|
|
data = _data;
|
|
|
|
file = _file;
|
|
|
|
layerTarget = _layer;
|
|
|
|
|
|
|
|
static checkSurface = function() {
|
2024-07-05 08:00:00 +02:00
|
|
|
var width = data[$ "Width"];
|
|
|
|
var height = data[$ "Height"];
|
|
|
|
data[$ "Surface"] = surface_verify(data[$ "Surface"], width, height);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-05 08:00:00 +02:00
|
|
|
var color = file[$ "Color depth"];
|
2023-01-17 08:11:55 +01:00
|
|
|
if(color == 32) {//rgba
|
2024-07-05 08:00:00 +02:00
|
|
|
buffer_set_surface(data[$ "Buffer"], data[$ "Surface"], 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var size = width * height;
|
|
|
|
var buff = buffer_create(size * 4, buffer_fixed, 1);
|
|
|
|
buffer_seek(buff, buffer_seek_start, 0);
|
2024-07-05 08:00:00 +02:00
|
|
|
buffer_seek(data[$ "Buffer"], buffer_seek_start, 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
if(color == 16) { //grey
|
|
|
|
repeat(size) {
|
2024-07-05 08:00:00 +02:00
|
|
|
var _bin = buffer_read(data[$ "Buffer"], buffer_u16);
|
2024-07-04 02:07:02 +02:00
|
|
|
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);
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
2024-07-05 08:00:00 +02:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
} else if(color == 8) { //index
|
2024-07-05 08:00:00 +02:00
|
|
|
var palet = file[$ "Palette"];
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
repeat(size) {
|
2024-07-05 08:00:00 +02:00
|
|
|
var _bin = buffer_read(data[$ "Buffer"], buffer_u8);
|
|
|
|
var cc = array_safe_get_fast(palet, _bin);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
for( var i = 0; i < 4; i++ )
|
|
|
|
buffer_write(buff, buffer_u8, cc[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 08:00:00 +02:00
|
|
|
buffer_set_surface(buff, data[$ "Surface"], 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static getSurface = function() {
|
2024-07-05 08:00:00 +02:00
|
|
|
var type = data[$ "Cel type"];
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
if(type == 0) {
|
|
|
|
|
|
|
|
} else if(type == 1) {
|
2024-07-05 08:00:00 +02:00
|
|
|
var frTarget = data[$ "Frame position"];
|
2024-09-20 05:06:20 +02:00
|
|
|
// print($"Get frame {frTarget}")
|
|
|
|
|
|
|
|
var cel = layerTarget.getCelRaw(frTarget);
|
2023-01-17 08:11:55 +01:00
|
|
|
if(!cel) return noone;
|
|
|
|
return cel.getSurface();
|
2024-07-05 08:00:00 +02:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
} else if(type == 2) {
|
|
|
|
checkSurface();
|
2024-07-05 08:00:00 +02:00
|
|
|
return data[$ "Surface"];
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return noone;
|
|
|
|
}
|
2024-09-20 05:06:20 +02:00
|
|
|
|
|
|
|
function toStr() {
|
|
|
|
return {
|
|
|
|
type: data[$ "Cel type"],
|
|
|
|
link: data[$ "Frame position"]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function toString() {
|
|
|
|
var st = json_stringify(toStr());
|
|
|
|
|
|
|
|
return $"[ase cel] {st}";
|
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
2024-07-05 08:00:00 +02:00
|
|
|
function ase_layer(name, type = 0) constructor {
|
2023-01-17 08:11:55 +01:00
|
|
|
self.name = name;
|
2024-07-05 08:00:00 +02:00
|
|
|
self.type = type;
|
2023-01-17 08:11:55 +01:00
|
|
|
cels = [];
|
|
|
|
tag = noone;
|
|
|
|
|
2024-07-05 08:00:00 +02:00
|
|
|
static setFrameCel = function(index, cel) { cels[index] = cel; }
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-09-20 05:06:20 +02:00
|
|
|
static getCelRaw = function(index = CURRENT_FRAME) {
|
|
|
|
ind = safe_mod(index, array_length(cels));
|
|
|
|
return array_safe_get_fast(cels, ind);
|
|
|
|
}
|
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static getCel = function(index = CURRENT_FRAME) {
|
2024-09-20 05:06:20 +02:00
|
|
|
if(tag == noone) return getCelRaw(index);
|
|
|
|
|
|
|
|
var st = tag[$ "Frame start"];
|
|
|
|
var ed = tag[$ "Frame end"];
|
|
|
|
var ind = st + safe_mod(index, ed - st + 1);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
return array_safe_get_fast(cels, ind);
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
2024-09-20 05:06:20 +02:00
|
|
|
|
|
|
|
function toString() {
|
|
|
|
var st = json_stringify({
|
|
|
|
type,
|
|
|
|
cels : array_map(cels, function(cel) /*=>*/ {return cel.toStr()}),
|
|
|
|
});
|
|
|
|
|
|
|
|
return $"[ase layer] {st}";
|
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|