[ASE File read] Fix freeze when selecting a tag with linked frame outside the tag range.

This commit is contained in:
Tanasart 2024-09-20 10:06:20 +07:00
parent dbc6a49e05
commit 933dab87ec
2 changed files with 42 additions and 17 deletions

View File

@ -50,7 +50,9 @@ function ase_cel(_layer, _data, _file) constructor {
} else if(type == 1) {
var frTarget = data[$ "Frame position"];
var cel = layerTarget.getCel(frTarget);
// print($"Get frame {frTarget}")
var cel = layerTarget.getCelRaw(frTarget);
if(!cel) return noone;
return cel.getSurface();
@ -61,6 +63,19 @@ function ase_cel(_layer, _data, _file) constructor {
return noone;
}
function toStr() {
return {
type: data[$ "Cel type"],
link: data[$ "Frame position"]
};
}
function toString() {
var st = json_stringify(toStr());
return $"[ase cel] {st}";
}
}
function ase_layer(name, type = 0) constructor {
@ -71,16 +86,27 @@ function ase_layer(name, type = 0) constructor {
static setFrameCel = function(index, cel) { cels[index] = cel; }
static getCel = function(index = CURRENT_FRAME) {
var ind;
static getCelRaw = function(index = CURRENT_FRAME) {
ind = safe_mod(index, array_length(cels));
return array_safe_get_fast(cels, ind);
}
if(tag != noone) {
var st = tag[$ "Frame start"];
var ed = tag[$ "Frame end"];
ind = st + safe_mod(index, ed - st + 1);
} else
ind = safe_mod(index, array_length(cels));
static getCel = function(index = CURRENT_FRAME) {
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);
return array_safe_get_fast(cels, ind);
}
function toString() {
var st = json_stringify({
type,
cels : array_map(cels, function(cel) /*=>*/ {return cel.toStr()}),
});
return $"[ase layer] {st}";
}
}

View File

@ -107,6 +107,7 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
var _yy = by + ui(4) + i * hh;
var tag = tags[i];
var _tagName = tag[$ "Name"];
var cc = tag[$ "Color"];
var st = tag[$ "Frame start"];
var ed = tag[$ "Frame end"];
@ -137,11 +138,8 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
if(_hover && point_in_rectangle(_m[0], _m[1], _x + 8, _yy, _x + _w - 8, _yy + hh)) {
draw_sprite_stretched_add(THEME.ui_panel, 0, _x + 8, _tgy, _w - 16, _tgh, c_white, 0.1);
if(mouse_press(mb_left, _focus)) {
var _currTag = getInputData(2);
var _tagName = tag[$ "Name"];
inputs[2].setValue(_currTag == _tagName? "" : _tagName);
}
if(mouse_press(mb_left, _focus))
inputs[2].setValue(current_tag == _tagName? "" : _tagName);
}
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
@ -370,14 +368,15 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
blend_temp_surface = temp_surface[2];
for( var i = 0, n = array_length(layers); i < n; i++ ) {
// print($"{i}: {layers[i]}");
layers[i].tag = tag;
var cel = layers[i].getCel(CURRENT_FRAME - _tag_delay);
if(!cel) continue;
if(!array_safe_get_fast(vis, i, true)) continue;
var _inSurf = cel.getSurface();
if(!is_surface(_inSurf))
continue;
if(!is_surface(_inSurf)) continue;
var xx = cel.data[$ "X"];
var yy = cel.data[$ "Y"];