Pixel-Composer/scripts/load_palette/load_palette.gml

33 lines
877 B
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
function loadPalette(path) {
var pal = [];
if(path != "" && file_exists(path)) {
var _t = file_text_open_read(path);
var _index = 0;
var ext = filename_ext(path);
while(!file_text_eof(_t)) {
var _w = file_text_readln(_t);
if(_w != "") {
switch(ext) {
case ".hex" :
var _r = string_hexadecimal(string_copy(_w, 1, 2));
var _g = string_hexadecimal(string_copy(_w, 3, 2));
var _b = string_hexadecimal(string_copy(_w, 5, 2));
pal[_index++] = make_color_rgb(_r, _g, _b);
break;
case ".gpl" :
case ".pal" :
if(string_char_at(_w, 1) == "#") break;
var _c = string_splice(_w, " ");
if(array_length(_c) >= 3) {
pal[_index++] = make_color_rgb(string_decimal(_c[0]), string_decimal(_c[1]), string_decimal(_c[2]));
}
break;
}
}
}
file_text_close(_t);
}
return pal;
}