From 4bd4997f23cd578d33d72e8166fd665c270f4fc3 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Fri, 5 Jul 2024 13:00:00 +0700 Subject: [PATCH] - [ASE File In] Now detect group separately from image layer --- scripts/ase_object/ase_object.gml | 40 +-- scripts/ase_reader/ase_reader.gml | 246 ++++++++---------- .../node_ase_file_read/node_ase_file_read.gml | 101 +++---- scripts/node_ase_layer/node_ase_layer.gml | 37 +-- 4 files changed, 200 insertions(+), 224 deletions(-) diff --git a/scripts/ase_object/ase_object.gml b/scripts/ase_object/ase_object.gml index 25656a986..02ef9f76e 100644 --- a/scripts/ase_object/ase_object.gml +++ b/scripts/ase_object/ase_object.gml @@ -4,75 +4,79 @@ function ase_cel(_layer, _data, _file) constructor { layerTarget = _layer; static checkSurface = function() { - var width = data[? "Width"]; - var height = data[? "Height"]; - data[? "Surface"] = surface_verify(data[? "Surface"], width, height); + var width = data[$ "Width"]; + var height = data[$ "Height"]; + data[$ "Surface"] = surface_verify(data[$ "Surface"], width, height); - var color = file[? "Color depth"]; + var color = file[$ "Color depth"]; if(color == 32) {//rgba - buffer_set_surface(data[? "Buffer"], data[? "Surface"], 0); + 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); + buffer_seek(data[$ "Buffer"], buffer_seek_start, 0); if(color == 16) { //grey repeat(size) { - var _bin = buffer_read(data[? "Buffer"], buffer_u16); + 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"]; + var palet = file[$ "Palette"]; repeat(size) { - var _bin = buffer_read(data[? "Buffer"], buffer_u8); - var cc = array_safe_get_fast(palet, _bin); + var _bin = buffer_read(data[$ "Buffer"], buffer_u8); + var cc = array_safe_get_fast(palet, _bin); + for( var i = 0; i < 4; i++ ) buffer_write(buff, buffer_u8, cc[i]); } } - buffer_set_surface(buff, data[? "Surface"], 0); + buffer_set_surface(buff, data[$ "Surface"], 0); } static getSurface = function() { - var type = data[? "Cel type"]; + var type = data[$ "Cel type"]; if(type == 0) { } else if(type == 1) { - var frTarget = data[? "Frame position"]; + 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 data[$ "Surface"]; } return noone; } } -function ase_layer(name) constructor { +function ase_layer(name, type = 0) constructor { self.name = name; + self.type = type; cels = []; tag = noone; - static setFrameCel = function(index, cel) { INLINE cels[index] = cel; } + static setFrameCel = function(index, cel) { cels[index] = cel; } static getCel = function(index = CURRENT_FRAME) { var ind; if(tag != noone) { - var st = tag[? "Frame start"]; - var ed = tag[? "Frame end"]; + 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)); diff --git a/scripts/ase_reader/ase_reader.gml b/scripts/ase_reader/ase_reader.gml index 7e59211be..0bbbc43bd 100644 --- a/scripts/ase_reader/ase_reader.gml +++ b/scripts/ase_reader/ase_reader.gml @@ -45,8 +45,7 @@ enum _BIN_TYPE { //Subtract = 17 //Divide = 18 -globalvar __ase_format_header; -__ase_format_header = [ +globalvar __ase_format_header; __ase_format_header = [ [_BIN_TYPE.dword, "File size"], [_BIN_TYPE.word, "Magic number"], [_BIN_TYPE.word, "Frame amount"], @@ -69,8 +68,7 @@ __ase_format_header = [ [_BIN_TYPE.byte, "Unused", 84], ]; -globalvar __ase_format_frame; -__ase_format_frame = [ +globalvar __ase_format_frame; __ase_format_frame = [ [_BIN_TYPE.dword, "Length"], [_BIN_TYPE.word, "Magic number"], [_BIN_TYPE.word, "Chunk amount"], //If 0xFFFF, use "Chunk amount new" @@ -79,26 +77,22 @@ __ase_format_frame = [ [_BIN_TYPE.dword, "Chunk amount new"], ]; -globalvar __ase_format_chunk; -__ase_format_chunk = [ +globalvar __ase_format_chunk; __ase_format_chunk = [ [_BIN_TYPE.dword, "Length"], [_BIN_TYPE.word, "Type"], ]; -globalvar __ase_format_chunk_old_palette; -__ase_format_chunk_old_palette = [ +globalvar __ase_format_chunk_old_palette; __ase_format_chunk_old_palette = [ [_BIN_TYPE.word, "Packet amount"], ]; -globalvar __ase_format_chunk_old_palette_packet; -__ase_format_chunk_old_palette_packet = [ +globalvar __ase_format_chunk_old_palette_packet; __ase_format_chunk_old_palette_packet = [ [_BIN_TYPE.byte, "Entries skip index"], [_BIN_TYPE.byte, "Color amount"], [_BIN_TYPE.color, "Colors", "Color amount"], ]; -globalvar __ase_format_chunk_layer; -__ase_format_chunk_layer = [ +globalvar __ase_format_chunk_layer; __ase_format_chunk_layer = [ [_BIN_TYPE.word, "Flag"], //1: Visible, 2: Editable, 4:Lock, 8:BG [_BIN_TYPE.word, "Layer type"], //0: Normal, 1: Group, 2: Tilemap [_BIN_TYPE.word, "Child level"], @@ -108,11 +102,10 @@ __ase_format_chunk_layer = [ [_BIN_TYPE.byte, "Opacity"], [_BIN_TYPE.byte, "Unused", 3], [_BIN_TYPE.string, "Name"], - [_BIN_TYPE.dword, "Tileset index", 1, function(chunk) { return chunk[? "Layer type"] == 2; }], + [_BIN_TYPE.dword, "Tileset index", 1, function(chunk) { return chunk[$ "Layer type"] == 2; }], ]; -globalvar __ase_format_chunk_cel; -__ase_format_chunk_cel = [ +globalvar __ase_format_chunk_cel; __ase_format_chunk_cel = [ [_BIN_TYPE.word, "Layer index"], [_BIN_TYPE.short, "X"], [_BIN_TYPE.short, "Y"], @@ -121,27 +114,23 @@ __ase_format_chunk_cel = [ [_BIN_TYPE.byte, "Unused", 7], ]; -globalvar __ase_format_chunk_cel_raw_image; -__ase_format_chunk_cel_raw_image = [ +globalvar __ase_format_chunk_cel_raw_image; __ase_format_chunk_cel_raw_image = [ [_BIN_TYPE.word, "Width"], [_BIN_TYPE.word, "Height"], - [_BIN_TYPE.pixel, "Pixels", function(chunk) { return chunk[? "Width"] * chunk[? "Width"]; }], + [_BIN_TYPE.pixel, "Pixels", function(chunk) { return chunk[$ "Width"] * chunk[$ "Width"]; }], ]; -globalvar __ase_format_chunk_cel_linked; -__ase_format_chunk_cel_linked = [ +globalvar __ase_format_chunk_cel_linked; __ase_format_chunk_cel_linked = [ [_BIN_TYPE.word, "Frame position"], ]; -globalvar __ase_format_chunk_cel_compress_image; -__ase_format_chunk_cel_compress_image = [ +globalvar __ase_format_chunk_cel_compress_image; __ase_format_chunk_cel_compress_image = [ [_BIN_TYPE.word, "Width"], [_BIN_TYPE.word, "Height"], - //[_BIN_TYPE.long, "Raw cel", function(chunk) { return chunk[? "Width"] * chunk[? "Width"]; }], + //[_BIN_TYPE.long, "Raw cel", function(chunk) { return chunk[$ "Width"] * chunk[$ "Width"]; }], ]; -globalvar __ase_format_chunk_cel_compress_tilemap; -__ase_format_chunk_cel_compress_tilemap = [ +globalvar __ase_format_chunk_cel_compress_tilemap; __ase_format_chunk_cel_compress_tilemap = [ [_BIN_TYPE.word, "Width"], [_BIN_TYPE.word, "Height"], [_BIN_TYPE.word, "Bits per tile"], @@ -150,11 +139,10 @@ __ase_format_chunk_cel_compress_tilemap = [ [_BIN_TYPE.dword, "Y flip"], [_BIN_TYPE.dword, "90CW rotation"], [_BIN_TYPE.byte, "Unused", 10], - //[_BIN_TYPE.tile, "Tiles", function(chunk) { return chunk[? "Width"] * chunk[? "Width"]; }], + //[_BIN_TYPE.tile, "Tiles", function(chunk) { return chunk[$ "Width"] * chunk[$ "Width"]; }], ]; -globalvar __ase_format_chunk_cel_extra; -__ase_format_chunk_cel_extra = [ +globalvar __ase_format_chunk_cel_extra; __ase_format_chunk_cel_extra = [ [_BIN_TYPE.dword, "Flag"], [_BIN_TYPE.fixed, "X"], [_BIN_TYPE.fixed, "Y"], @@ -163,38 +151,33 @@ __ase_format_chunk_cel_extra = [ [_BIN_TYPE.byte, "Unused", 16], ]; -globalvar __ase_format_chunk_color_profile; -__ase_format_chunk_color_profile = [ +globalvar __ase_format_chunk_color_profile; __ase_format_chunk_color_profile = [ [_BIN_TYPE.word, "Type"], //0: no profile, 1: sRGB, 2: ICC [_BIN_TYPE.word, "Flag"], //1: Fix gamma [_BIN_TYPE.fixed, "Fixed gamma"], [_BIN_TYPE.byte, "Unused", 8], - [_BIN_TYPE.dword, "ICC Data length", 1, function(chunk) { return chunk[? "Type"] == 2; }], - [_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(chunk) { return chunk[? "Type"] == 2; }], + [_BIN_TYPE.dword, "ICC Data length", 1, function(chunk) { return chunk[$ "Type"] == 2; }], + [_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(chunk) { return chunk[$ "Type"] == 2; }], ]; -globalvar __ase_format_chunk_file; -__ase_format_chunk_file = [ +globalvar __ase_format_chunk_file; __ase_format_chunk_file = [ [_BIN_TYPE.dword, "Entries"], [_BIN_TYPE.byte, "Unused", 8], ]; -globalvar __ase_format_chunk_file_entry; -__ase_format_chunk_file_entry = [ +globalvar __ase_format_chunk_file_entry; __ase_format_chunk_file_entry = [ [_BIN_TYPE.dword, "ID"], [_BIN_TYPE.byte, "File type"], //0: External palette, 1: External tileset, 2: Extension anme [_BIN_TYPE.byte, "Unused", 7], [_BIN_TYPE.string, "File name"], ]; -globalvar __ase_format_chunk_tag; -__ase_format_chunk_tag = [ +globalvar __ase_format_chunk_tag; __ase_format_chunk_tag = [ [_BIN_TYPE.word, "Tag amount"], [_BIN_TYPE.byte, "Unused", 8], ]; -globalvar __ase_format_chunk_tag_entry; -__ase_format_chunk_tag_entry = [ +globalvar __ase_format_chunk_tag_entry; __ase_format_chunk_tag_entry = [ [_BIN_TYPE.word, "Frame start"], [_BIN_TYPE.word, "Frame end"], [_BIN_TYPE.byte, "Loop"], //0: Forward, 1: Backward, 2: Ping pong, 3: Ping pong reverse @@ -205,52 +188,46 @@ __ase_format_chunk_tag_entry = [ [_BIN_TYPE.string, "Name"], ] -globalvar __ase_format_chunk_palette; -__ase_format_chunk_palette = [ +globalvar __ase_format_chunk_palette; __ase_format_chunk_palette = [ [_BIN_TYPE.dword, "Color amount"], [_BIN_TYPE.dword, "First index"], [_BIN_TYPE.dword, "Last index"], [_BIN_TYPE.byte, "Unused", 8], ]; -globalvar __ase_format_chunk_palette_entry; -__ase_format_chunk_palette_entry = [ +globalvar __ase_format_chunk_palette_entry; __ase_format_chunk_palette_entry = [ [_BIN_TYPE.word, "Flag"], //1: Has name [_BIN_TYPE.byte, "Red"], [_BIN_TYPE.byte, "Green"], [_BIN_TYPE.byte, "Blue"], [_BIN_TYPE.byte, "Alpha"], - [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[? "Flag"] & (1 << 0); }], + [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], ]; -globalvar __ase_format_chunk_user_data; -__ase_format_chunk_user_data = [ +globalvar __ase_format_chunk_user_data; __ase_format_chunk_user_data = [ [_BIN_TYPE.dword, "Flag"], //1: Text, 2: Color, 4: Properties - [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[? "Flag"] & (1 << 0); }], - [_BIN_TYPE.byte, "Red", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Green", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Blue", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Alpha", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], + [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], + [_BIN_TYPE.byte, "Red", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.byte, "Green", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.byte, "Blue", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.byte, "Alpha", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], ]; -globalvar __ase_format_chunk_user_data_prop; -__ase_format_chunk_user_data_prop = [ +globalvar __ase_format_chunk_user_data_prop; __ase_format_chunk_user_data_prop = [ [_BIN_TYPE.dword, "Length"], [_BIN_TYPE.dword, "Prop amount"], ] /* TODO: Use data read */ -globalvar __ase_format_chunk_slice; -__ase_format_chunk_slice = [ +globalvar __ase_format_chunk_slice; __ase_format_chunk_slice = [ [_BIN_TYPE.dword, "Slice key amount"], [_BIN_TYPE.dword, "Flag"], //1: 9 slice, 2: pivot [_BIN_TYPE.dword, "Reserved"], [_BIN_TYPE.string, "Name"], ]; -globalvar __ase_format_chunk_slice_key; -__ase_format_chunk_slice_key = [ +globalvar __ase_format_chunk_slice_key; __ase_format_chunk_slice_key = [ [_BIN_TYPE.dword, "Frame number"], [_BIN_TYPE.long, "X"], [_BIN_TYPE.long, "Y"], @@ -258,22 +235,19 @@ __ase_format_chunk_slice_key = [ [_BIN_TYPE.dword, "Height"], ]; -globalvar __ase_format_chunk_slice_nine; -__ase_format_chunk_slice_nine = [ +globalvar __ase_format_chunk_slice_nine; __ase_format_chunk_slice_nine = [ [_BIN_TYPE.long, "Center X"], [_BIN_TYPE.long, "Center Y"], [_BIN_TYPE.dword, "Center width"], [_BIN_TYPE.dword, "Center height"], ]; -globalvar __ase_format_chunk_slice_pivot; -__ase_format_chunk_slice_pivot = [ +globalvar __ase_format_chunk_slice_pivot; __ase_format_chunk_slice_pivot = [ [_BIN_TYPE.long, "Pivot X"], [_BIN_TYPE.long, "Pivot Y"], ]; -globalvar __ase_format_chunk_tileset; -__ase_format_chunk_tileset = [ +globalvar __ase_format_chunk_tileset; __ase_format_chunk_tileset = [ [_BIN_TYPE.dword, "ID"], [_BIN_TYPE.dword, "Flag"], //1: Link to external file, 2: Include tile in this file, 4: Use ID 0 as empty tiles. [_BIN_TYPE.dword, "Tile amount"], @@ -282,10 +256,10 @@ __ase_format_chunk_tileset = [ [_BIN_TYPE.short, "Base index"], [_BIN_TYPE.byte, "Reserved", 14], [_BIN_TYPE.string, "Name"], - [_BIN_TYPE.dword, "ID of external file", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], - [_BIN_TYPE.dword, "Tileset ID", 1, function(chunk) { return chunk[? "Flag"] & (1 << 1); }], - [_BIN_TYPE.dword, "Data length", 1, function(chunk) { return chunk[? "Flag"] & (1 << 2); }], - [_BIN_TYPE.pixel, "Compressed image", "Data length", function(chunk) { return chunk[? "Flag"] & (1 << 2); }], + [_BIN_TYPE.dword, "ID of external file", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.dword, "Tileset ID", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.dword, "Data length", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], + [_BIN_TYPE.pixel, "Compressed image", "Data length", function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], ]; function read_format_type(_bin, datType, outMap) { @@ -306,10 +280,9 @@ function read_format_type(_bin, datType, outMap) { case _BIN_TYPE.size: return bin_read_size(_bin); case _BIN_TYPE.rect: return bin_read_rect(_bin); case _BIN_TYPE.color: return bin_read_color(_bin); - case _BIN_TYPE.pixel: return bin_read_pixel(_bin, outMap[? "Color depth"]); + case _BIN_TYPE.pixel: return bin_read_pixel(_bin, outMap[$ "Color depth"]); } - return 0; } @@ -317,124 +290,123 @@ function read_format(_bin, format, outMap) { var datType = array_safe_get_fast(format, 0, 0); var key = array_safe_get_fast(format, 1, ""); var amount = array_safe_get_fast(format, 2, 1); - if(is_string(amount)) - amount = ds_map_exists(outMap, amount)? outMap[? amount] : 1; - else if(is_method(amount)) - amount = amount(outMap); + + if(is_string(amount)) amount = struct_has(outMap, amount)? outMap[$ amount] : 1; + else if(is_method(amount)) amount = amount(outMap); if(amount == 1) { var val = read_format_type(_bin, datType, outMap); - outMap[? key] = val; + outMap[$ key] = val; return val; + } else { var a = array_create(amount); for( var i = 0; i < amount; i++ ) a[i] = read_format_type(_bin, datType, outMap); - outMap[? key] = a; + outMap[$ key] = a; return a; } } function read_format_array(_bin, formatArr, outMap) { for( var i = 0, n = array_length(formatArr); i < n; i++ ) { - if(array_length(formatArr[i]) >= 4 && !formatArr[i][3](outMap)) + var _form = formatArr[i]; + if(array_length(_form) >= 4 && !_form[3](outMap)) continue; + var pos = file_bin_position(_bin); - var val = read_format(_bin, formatArr[i], outMap); + var val = read_format(_bin, _form, outMap); //printIf(global.FLAG.ase_import, "Pos " + dec_to_hex(pos) + " - " + dec_to_hex(file_bin_position(_bin))); - if(formatArr[i][1] == "Type") - printIf(global.FLAG.ase_import, "\t" + formatArr[i][1] + ":\t 0x" + dec_to_hex(val, 4)); - else - printIf(global.FLAG.ase_import, "\t" + formatArr[i][1] + ":\t " + string(val)); + if(_form[1] == "Type") printIf(global.FLAG.ase_import, $"\t{_form[1]}:\t 0x{dec_to_hex(val, 4)}"); + else printIf(global.FLAG.ase_import, $"\t{_form[1]}:\t {string(val)}"); } } -function read_ase(path, fileMap) { +function read_ase(path) { //// MAIN READ printIf(global.FLAG.ase_import, $"===== Reading: {path} ====="); - var file = file_bin_open(path, 0); - if(file < 0) { - noti_warning($"ASE file read error.") - return noone; - } + var file = file_bin_open(path, 0); + if(file < 0) { noti_warning($"ASE file read error."); return noone; } file_bin_seek(file, 0); - ds_map_clear(fileMap); + fileMap = {}; read_format_array(file, __ase_format_header, fileMap); - var frames = []; - var frameAmo = ds_map_exists(fileMap, "Frame amount")? fileMap[? "Frame amount"] : 0; + var frames = []; + var frameAmo = struct_try_get(fileMap, "Frame amount", 0); + for( var i = 0; i < frameAmo; i++ ) { - printIf(global.FLAG.ase_import, "\n=== Reading frame " + string(i) + " ==="); + printIf(global.FLAG.ase_import, $"\n=== Reading frame {i} ==="); array_push(frames, read_ase_frame(file)); } - fileMap[? "Frames"] = frames; + fileMap[$ "Frames"] = frames; file_bin_close(file); return fileMap; } function read_ase_frame(file) { - var frame = ds_map_create(); + var frame = {}; read_format_array(file, __ase_format_frame, frame); - var chunks = []; - var chunkAmo = ds_map_exists(frame, "Chunk amount")? frame[? "Chunk amount"] : 0; - if(chunkAmo == 65535) - chunkAmo = ds_map_exists(frame, "Chunk amount new")? frame[? "Chunk amount new"] : chunkAmo; + var chunks = []; + var chunkAmo = struct_try_get(frame, "Chunk amount", 0); + + if(chunkAmo == 0xFFFF) + chunkAmo = struct_try_get(frame, "Chunk amount new", chunkAmo); for( var i = 0; i < chunkAmo; i++ ) { - printIf(global.FLAG.ase_import, "\n=== Reading chunk " + string(i) + " ==="); + printIf(global.FLAG.ase_import, $"\n=== Reading chunk {i} ==="); array_push(chunks, read_ase_chunk(file)); } - frame[? "Chunks"] = chunks; + + frame[$ "Chunks"] = chunks; return frame; } function read_ase_chunk(file) { - var chunk = ds_map_create(); + var chunk = {}; var startPos = file_bin_position(file); read_format_array(file, __ase_format_chunk, chunk); - var skipPos = startPos + chunk[? "Length"]; + var skipPos = startPos + chunk[$ "Length"]; - switch(chunk[? "Type"]) { + switch(chunk[$ "Type"]) { case 0x0004: //old palette case 0x0011: //old palette printIf(global.FLAG.ase_import, "\n -- Reading chunk [Old palette] -- "); read_format_array(file, __ase_format_chunk_old_palette, chunk); var cc = []; - for( var i = 0; i < chunk[? "Packet amount"]; i++ ) { - cc[i] = ds_map_create(); + for( var i = 0; i < chunk[$ "Packet amount"]; i++ ) { + cc[i] = {}; read_format_array(file, __ase_format_chunk_old_palette_packet, cc[i]); } - chunk[? "Packets"] = cc; + chunk[$ "Packets"] = cc; break; + case 0x2004: //layer printIf(global.FLAG.ase_import, "\n -- Reading chunk [Layer] -- "); read_format_array(file, __ase_format_chunk_layer, chunk); break; + case 0x2005: //cel printIf(global.FLAG.ase_import, "\n -- Reading chunk [Cel] -- "); read_format_array(file, __ase_format_chunk_cel, chunk); - var type = chunk[? "Cel type"]; + var type = chunk[$ "Cel type"]; switch(type) { - case 0 : - read_format_array(file, __ase_format_chunk_cel_raw_image, chunk); - break; - case 1 : - read_format_array(file, __ase_format_chunk_cel_linked, chunk); - break; + case 0 : read_format_array(file, __ase_format_chunk_cel_raw_image, chunk); break; + case 1 : read_format_array(file, __ase_format_chunk_cel_linked, chunk); break; + case 2 : read_format_array(file, __ase_format_chunk_cel_compress_image, chunk); - chunk[? "Surface"] = noone; + chunk[$ "Surface"] = noone; var compressLength = (skipPos - file_bin_position(file)); var _compBuff = buffer_create(compressLength * buffer_sizeof(buffer_u8), buffer_grow, 1); @@ -446,58 +418,58 @@ function read_ase_chunk(file) { } var _rawBuff = buffer_decompress(_compBuff); - if(_rawBuff != -1) chunk[? "Buffer"] = _rawBuff; - printIf(global.FLAG.ase_import, " Buffer size: " + string(compressLength)); - + if(_rawBuff != -1) chunk[$ "Buffer"] = _rawBuff; + printIf(global.FLAG.ase_import, $" Buffer size: {compressLength}"); buffer_delete(_compBuff); break; + case 3 : read_format_array(file, __ase_format_chunk_cel_compress_tilemap, chunk); //TILE READ break; } break; - case 0x2006: //cel extra - break; + + case 0x2006: break; //cel extra + case 0x2007: //color profile printIf(global.FLAG.ase_import, "\n -- Reading chunk [Color profile] -- "); read_format_array(file, __ase_format_chunk_color_profile, chunk); break; - case 0x2008: //external file - break; - case 0x2009: //mask DEPRECATED - break; - case 0x2017: //path - break; + + case 0x2008: break; //external file + case 0x2009: break; //mask DEPRECATED + case 0x2017: break; //path + case 0x2018: //tag printIf(global.FLAG.ase_import, "\n -- Reading chunk [Tag] -- "); read_format_array(file, __ase_format_chunk_tag, chunk); - var amo = chunk[? "Tag amount"] + var amo = chunk[$ "Tag amount"] var tags = []; repeat(amo) { - var m = ds_map_create(); + var m = {}; read_format_array(file, __ase_format_chunk_tag_entry, m); array_push(tags, m); } - chunk[? "Tags"] = tags; + chunk[$ "Tags"] = tags; break; + case 0x2019: //palette printIf(global.FLAG.ase_import, "\n -- Reading chunk [Palette] -- "); read_format_array(file, __ase_format_chunk_palette, chunk); var cc = []; - for( var i = 0; i < chunk[? "Color amount"]; i++ ) { - cc[i] = ds_map_create(); + for( var i = 0; i < chunk[$ "Color amount"]; i++ ) { + cc[i] = {}; read_format_array(file, __ase_format_chunk_palette_entry, cc[i]); } - chunk[? "Palette"] = cc; - break; - case 0x2020: //user data - break; - case 0x2022: //slice - break; - case 0x2023: //tileset + chunk[$ "Palette"] = cc; break; + + case 0x2020: break; //user data + case 0x2022: break; //slice + case 0x2023: break; //tileset } + file_bin_seek(file, skipPos - file_bin_position(file)); return chunk; diff --git a/scripts/node_ase_file_read/node_ase_file_read.gml b/scripts/node_ase_file_read/node_ase_file_read.gml index aeac3e364..bfe900b99 100644 --- a/scripts/node_ase_file_read/node_ase_file_read.gml +++ b/scripts/node_ase_file_read/node_ase_file_read.gml @@ -65,21 +65,26 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const draw_line(_x + 16, _yy - 2, _x + _w - 16, _yy - 2); } - var vis = array_safe_get_fast(_vis, i, true); var _bx = _x + 24; - if(point_in_circle(_m[0], _m[1], _bx, _yy + hh / 2, 12)) { - draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _yy + hh / 2, 1, c_white); - - if(mouse_press(mb_left, _focus)) - hold_visibility = !_vis[i]; + + if(_layer.type == 0) { + var vis = array_safe_get_fast(_vis, i, true); + if(point_in_circle(_m[0], _m[1], _bx, _yy + hh / 2, 12)) { + draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _yy + hh / 2, 1, c_white); - if(mouse_click(mb_left, _focus) && _vis[i] != hold_visibility) { - _vis[@ i] = hold_visibility; - update(); - } - } else - draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _yy + hh / 2, 1, COLORS._main_icon, 0.5 + 0.5 * vis); - + if(mouse_press(mb_left, _focus)) + hold_visibility = !_vis[i]; + + if(mouse_click(mb_left, _focus) && _vis[i] != hold_visibility) { + _vis[@ i] = hold_visibility; + update(); + } + } else + draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _yy + hh / 2, 1, COLORS._main_icon, 0.5 + 0.5 * vis); + + } else if(_layer.type == 1) + draw_sprite_ui_uniform(THEME.folder_16, 0, _bx, _yy + hh / 2, 1, COLORS._main_icon); + draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text); draw_text(_bx + 16, _yy + hh / 2, _layer.name); } @@ -102,9 +107,9 @@ 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 cc = tag[? "Color"]; - var st = tag[? "Frame start"]; - var ed = tag[? "Frame end"]; + var cc = tag[$ "Color"]; + var st = tag[$ "Frame start"]; + var ed = tag[$ "Frame end"]; var rn = ed - st + 1; var progFr = safe_mod(CURRENT_FRAME - _tag_delay, rn) + 1; @@ -114,7 +119,7 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const var _tgy = _yy + ui(2); var _tgh = hh - ui(4); - if(tag[? "Name"] == current_tag) { + if(tag[$ "Name"] == current_tag) { draw_sprite_stretched_ext(THEME.timeline_node, 0, _x + 8, _tgy, _w - 16, _tgh, cc, 0.5); draw_sprite_stretched_ext(THEME.timeline_node, 0, _x + 8, _tgy, (_w - 16) * prog, _tgh, cc, 0.85); @@ -134,14 +139,14 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const if(mouse_press(mb_left, _focus)) { var _currTag = getInputData(2); - var _tagName = tag[? "Name"]; + var _tagName = tag[$ "Name"]; inputs[| 2].setValue(_currTag == _tagName? "" : _tagName); } } draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text); draw_set_alpha(1); - draw_text_add(_x + 28, _yy + hh / 2, tag[? "Name"]); + draw_text_add(_x + 28, _yy + hh / 2, tag[$ "Name"]); draw_set_halign(fa_right); draw_set_alpha(0.4); @@ -167,7 +172,7 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; }, new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]); - content = ds_map_create(); + content = noone; layers = []; tags = []; _tag_delay = 0; @@ -192,6 +197,8 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const var lvs = []; for( var i = 0, n = array_length(layers); i < n; i++ ) { var _layer = layers[i]; + if(_layer.type != 0) continue; + var _name = _layer.name; var _node = noone; @@ -230,46 +237,48 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const if(ext != ".ase" && ext != ".aseprite") return false; - read_ase(path, content); + content = read_ase(path); + if(content == noone) return false; + // print(json_stringify(content)); layers = []; var vis = attributes.layer_visible; - var frames = content[? "Frames"]; + var frames = content[$ "Frames"]; + if(array_empty(frames)) return false; for( var i = 0, n = array_length(frames); i < n; i++ ) { var frame = frames[i]; - var chunks = frame[? "Chunks"]; + var chunks = frame[$ "Chunks"]; for( var j = 0; j < array_length(chunks); j++ ) { var chunk = chunks[j]; - switch(chunk[? "Type"]) { + switch(chunk[$ "Type"]) { case 0x2019: //palette - var pck = chunk[? "Palette"]; - var plt = []; - for( var k = 0; k < array_length(pck); k++ ) { - var r = pck[k][? "Red"]; - var g = pck[k][? "Green"]; - var b = pck[k][? "Blue"]; - var a = pck[k][? "Alpha"]; - array_push(plt, [r, g, b, a]); - } - content[? "Palette"] = plt; + var pals = chunk[$ "Palette"]; + var plt = []; + + for( var k = 0; k < array_length(pals); k++ ) + array_push(plt, [ pals[k][$ "Red"], pals[k][$ "Green"], pals[k][$ "Blue"], pals[k][$ "Alpha"] ]); + + content[$ "Palette"] = plt; var p_arr = []; for( var k = 0; k < array_length(plt); k++ ) array_push(p_arr, make_color_rgb(plt[k][0], plt[k][1], plt[k][2])); + outputs[| 3].setValue(p_arr); break; case 0x2004: //layer - var name = chunk[? "Name"]; - array_push(layers, new ase_layer(name)); + var name = chunk[$ "Name"]; + + array_push(layers, new ase_layer(name, chunk[$ "Layer type"])); array_push(vis, true); break; case 0x2005: //cel - var _layer = chunk[? "Layer index"]; + var _layer = chunk[$ "Layer index"]; var cel = new ase_cel(layers[_layer], chunk, content); layers[_layer].setFrameCel(i, cel); break; @@ -278,12 +287,12 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const } tags = []; - var chunks = content[? "Frames"][0][? "Chunks"]; + var chunks = frames[0][$ "Chunks"]; for( var j = 0; j < array_length(chunks); j++ ) { var chunk = chunks[j]; - if(chunk[? "Type"] != 0x2018) continue; - tags = chunk[? "Tags"]; + if(chunk[$ "Type"] != 0x2018) continue; + tags = chunk[$ "Tags"]; } update_on_frame = false; @@ -323,11 +332,11 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const outputs[| 2].setValue(path); if(path_current != path) updatePaths(path); - if(ds_map_empty(content)) return; + if(content == noone) return; var tag = noone; for( var i = 0, n = array_length(tags); i < n; i++ ) { - if(tags[i][? "Name"] == current_tag) { + if(tags[i][$ "Name"] == current_tag) { tag = tags[i]; break; } @@ -341,8 +350,8 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const } var vis = attributes.layer_visible; - var ww = content[? "Width"]; - var hh = content[? "Height"]; + var ww = content[$ "Width"]; + var hh = content[$ "Height"]; var surf = outputs[| 0].getValue(); surf = surface_verify(surf, ww, hh); @@ -361,8 +370,8 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const if(!is_surface(_inSurf)) continue; - var xx = cel.data[? "X"]; - var yy = cel.data[? "Y"]; + var xx = cel.data[$ "X"]; + var yy = cel.data[$ "Y"]; draw_surface_safe(_inSurf, xx, yy); } diff --git a/scripts/node_ase_layer/node_ase_layer.gml b/scripts/node_ase_layer/node_ase_layer.gml index d60be7cf4..b216a8171 100644 --- a/scripts/node_ase_layer/node_ase_layer.gml +++ b/scripts/node_ase_layer/node_ase_layer.gml @@ -15,7 +15,7 @@ function Node_ASE_layer(_x, _y, _group = noone) : Node(_x, _y, _group) construct static onValueFromUpdate = function(index) { findLayer(); } - static findLayer = function() { #region + static findLayer = function() { layer_object = noone; var data = getInputData(0); @@ -25,9 +25,9 @@ function Node_ASE_layer(_x, _y, _group = noone) : Node(_x, _y, _group) construct if(data.layers[i].name == display_name) layer_object = data.layers[i]; } - } #endregion + } - static update = function(frame = CURRENT_FRAME) { #region + static update = function(frame = CURRENT_FRAME) { findLayer(); if(layer_object == noone) return; @@ -35,33 +35,24 @@ function Node_ASE_layer(_x, _y, _group = noone) : Node(_x, _y, _group) construct var cel = layer_object.getCel(CURRENT_FRAME - data._tag_delay); var celDim = getInputData(1); - var ww = data.content[? "Width"]; - var hh = data.content[? "Height"]; - var cw = cel? cel.data[? "Width"] : 1; - var ch = cel? cel.data[? "Height"] : 1; + var ww = data.content[$ "Width"]; + var hh = data.content[$ "Height"]; + var cw = cel? cel.data[$ "Width"] : 1; + var ch = cel? cel.data[$ "Height"] : 1; var surf = outputs[| 0].getValue(); if(celDim) surf = surface_verify(surf, cw, ch); else surf = surface_verify(surf, ww, hh); outputs[| 0].setValue(surf); - if(cel == 0) { - surface_set_target(surf); - DRAW_CLEAR - surface_reset_target(); - return; - } + if(cel == 0) { surface_clear(surf); return; } var _inSurf = cel.getSurface(); + var xx = celDim? 0 : cel.data[$ "X"]; + var yy = celDim? 0 : cel.data[$ "Y"]; - var xx = celDim? 0 : cel.data[? "X"]; - var yy = celDim? 0 : cel.data[? "Y"]; - - surface_set_target(surf); - DRAW_CLEAR - BLEND_OVERRIDE; - draw_surface_safe(_inSurf, xx, yy); - BLEND_NORMAL; - surface_reset_target(); - } #endregion + surface_set_shader(surf, noone); + draw_surface_safe(_inSurf, xx, yy); + surface_reset_shader(); + } } \ No newline at end of file