Fix color data

This commit is contained in:
Tanasart 2023-03-23 12:57:31 +07:00
parent c11be36a74
commit f68652c6b3
9 changed files with 119 additions and 65 deletions

View file

@ -76,6 +76,7 @@
{"name":"group","order":6,"path":"folders/nodes/data/group.yy",},
{"name":"iterate","order":10,"path":"folders/nodes/data/iterate.yy",},
{"name":"for each","order":1,"path":"folders/nodes/data/iterate/for each.yy",},
{"name":"for filter","order":3,"path":"folders/nodes/data/iterate/for filter.yy",},
{"name":"lua","order":17,"path":"folders/nodes/data/lua.yy",},
{"name":"node","order":11,"path":"folders/nodes/data/node.yy",},
{"name":"render","order":2,"path":"folders/nodes/data/render.yy",},
@ -135,7 +136,6 @@
{"name":"sprites","order":12,"path":"folders/sprites.yy",},
{"name":"gameframe","order":2,"path":"folders/sprites/gameframe.yy",},
{"name":"widgets","order":5,"path":"folders/widgets.yy",},
{"name":"for filter","order":3,"path":"folders/nodes/data/iterate/for filter.yy",},
],
"ResourceOrderSettings": [
{"name":"s_node_corner","order":14,"path":"sprites/s_node_corner/s_node_corner.yy",},
@ -501,7 +501,7 @@
{"name":"o_dialog_drag_folder","order":2,"path":"objects/o_dialog_drag_folder/o_dialog_drag_folder.yy",},
{"name":"node_VFX_effect_repel","order":9,"path":"scripts/node_VFX_effect_repel/node_VFX_effect_repel.yy",},
{"name":"s_node_alpha_cut","order":1,"path":"sprites/s_node_alpha_cut/s_node_alpha_cut.yy",},
{"name":"node_iterator_length","order":3,"path":"scripts/node_iterator_length/node_iterator_length.yy",},
{"name":"node_iterator_length","order":4,"path":"scripts/node_iterator_length/node_iterator_length.yy",},
{"name":"node_VFX_effect_attract","order":8,"path":"scripts/node_VFX_effect_attract/node_VFX_effect_attract.yy",},
{"name":"s_node_text_splice","order":6,"path":"sprites/s_node_text_splice/s_node_text_splice.yy",},
{"name":"__atlas","order":6,"path":"scripts/__atlas/__atlas.yy",},

View file

@ -96,6 +96,7 @@
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"IO","folderPath":"folders/nodes/data/IO.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"iterate","folderPath":"folders/nodes/data/iterate.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"for each","folderPath":"folders/nodes/data/iterate/for each.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"for filter","folderPath":"folders/nodes/data/iterate/for filter.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"for","folderPath":"folders/nodes/data/iterate/for.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"lua","folderPath":"folders/nodes/data/lua.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"node","folderPath":"folders/nodes/data/node.yy",},
@ -166,7 +167,6 @@
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"Steamworks","folderPath":"folders/Steamworks.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"UGC","folderPath":"folders/Steamworks/UGC.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"widgets","folderPath":"folders/widgets.yy",},
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"for filter","folderPath":"folders/nodes/data/iterate/for filter.yy",},
],
"IncludedFiles": [
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"ApolloHelp.html","CopyToMask":-1,"filePath":"datafiles",},

View file

@ -470,11 +470,11 @@ event_inherited();
#endregion
#region search
search_string = "";
search_list = ds_list_create();
keyboard_lastchar = "";
KEYBOARD_STRING = "";
keyboard_lastkey = -1;
search_string = "";
search_list = ds_list_create();
keyboard_lastchar = "";
KEYBOARD_STRING = "";
keyboard_lastkey = -1;
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) {
search_string = string(str);
@ -488,10 +488,10 @@ event_inherited();
ds_list_clear(search_list);
var pr_list = ds_priority_create();
var cnt = PANEL_GRAPH.getCurrentContext();
var context = cnt == noone? "" : instanceof(cnt);
var cnt = PANEL_GRAPH.getCurrentContext();
var context = cnt == noone? "" : instanceof(cnt);
var search_lower = string_lower(search_string);
var search_map = ds_map_create();
var search_map = ds_map_create();
for(var i = 0; i < ds_list_size(NODE_CATEGORY); i++) {
var cat = NODE_CATEGORY[| i];
@ -527,9 +527,8 @@ event_inherited();
searchCollection(pr_list, search_string, false);
repeat(ds_priority_size(pr_list)) {
repeat(ds_priority_size(pr_list))
ds_list_add(search_list, ds_priority_delete_max(pr_list));
}
ds_priority_destroy(pr_list);
}
@ -537,14 +536,30 @@ event_inherited();
search_pane = new scrollPane(dialog_w - ui(32), dialog_h - ui(66), function(_y, _m) {
draw_clear_alpha(c_white, 0);
var amo = ds_list_size(search_list);
var hh = 0;
var _hover = sHOVER && search_pane.hover;
var equation = string_char_at(search_string, 0) == "=";
var amo = ds_list_size(search_list);
var hh = 0;
var _hover = sHOVER && search_pane.hover;
var grid_size = ui(64);
var grid_width = ui(80);
var grid_space = ui(16);
if(equation) {
var eq = string_replace(search_string, "=", "");
draw_set_text(f_h5, fa_center, fa_bottom, COLORS._main_text_sub);
draw_text_ext(search_pane.w / 2, search_pane.h / 2 - ui(8), "Create equation: " + eq, -1, search_pane.w - ui(32));
draw_set_text(f_p0, fa_center, fa_top, COLORS._main_text_sub);
draw_text(search_pane.w / 2, search_pane.h / 2 - ui(4), "Press Enter to create equation node.");
if(keyboard_check_pressed(vk_enter))
buildNode(ALL_NODES[? "Node_Equation"], eq);
return hh;
}
if(PREF_MAP[? "dialog_add_node_view"] == 0) { //grid view
var grid_size = ui(64);
var grid_width = ui(80);
var grid_space = ui(16);
var col = floor(search_pane.surface_w / (grid_width + grid_space));
var yy = _y + grid_space;
var index = 0;

View file

@ -14,7 +14,7 @@
else
DIRECTORY = string(home_dir) + "/PixelComposer/";
}
show_debug_message(DIRECTORY);
show_debug_message("Current working directory: " + string(DIRECTORY));
if(!directory_exists(DIRECTORY))
directory_create(DIRECTORY);

View file

@ -4,8 +4,10 @@ function Node_Color_Data(_x, _y, _group = noone) : Node_Processor(_x, _y, _group
w = 96;
inputs[| 0] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
inputs[| 0].setVisible(true, true);
inputs[| 0] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white)
.setVisible(true, true);
inputs[| 1] = nodeValue("Normalize", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
outputs[| 0] = nodeValue("Red", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0);
outputs[| 1] = nodeValue("Green", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0);
@ -19,22 +21,27 @@ function Node_Color_Data(_x, _y, _group = noone) : Node_Processor(_x, _y, _group
function process_data(_output, _data, _output_index, _array_index = 0) {
var c = _data[0];
var n = _data[1];
var val = 0;
switch(_output_index) {
case 0 : return color_get_red(c) / 255;
case 1 : return color_get_green(c) / 255;
case 2 : return color_get_blue(c) / 255;
case 0 : val = color_get_red(c); break;
case 1 : val = color_get_green(c); break;
case 2 : val = color_get_blue(c); break;
case 3 : return color_get_hue(c) / 255;
case 4 : return color_get_saturation(c) / 255;
case 5 : return color_get_value(c) / 255;
case 3 : val = color_get_hue(c); break;
case 4 : val = color_get_saturation(c); break;
case 5 : val = color_get_value(c); break;
case 6 :
var r = color_get_red(c) / 255;
var g = color_get_green(c) / 255;
var b = color_get_blue(c) / 255;
return 0.299 * r + 0.587 * g + 0.224 * b;
var r = color_get_red(c);
var g = color_get_green(c);
var b = color_get_blue(c);
val = 0.2126 * r + 0.7152 * g + 0.0722 * b;
break;
}
return n? val / 255 : val;
}
PATCH_STATIC

View file

@ -1,3 +1,33 @@
function Node_create_Equation(_x, _y, _group = noone, _param = "") {
var node = new Node_Equation(_x, _y, _group);
if(_param == "") return node;
node.inputs[| 0].setValue(_param);
var ind = 1;
var amo = string_length(_param);
var str = "";
var pres = global.EQUATION_PRES;
var vars = [];
for( var ind = 1; ind <= amo; ind++ ) {
var ch = string_char_at(_param, ind);
if(ds_map_exists(pres, ch) || ch == "(" || ch == ")") {
if(str != "" && str != toNumber(str))
array_push_unique(vars, str);
str = "";
} else
str += ch;
}
if(str != "" && str != toNumber(str))
array_push_unique(vars, str);
for( var i = 0; i < array_length(vars); i++ )
node.inputs[| 1 + i * 2].setValue(vars[i]);
return node;
}
function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Equation";
color = COLORS.node_blend_number;
@ -5,7 +35,6 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
w = 96;
inputs[| 0] = nodeValue("Equation", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "");
static createNewInput = function() {
@ -53,15 +82,14 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
});
argument_renderer.register = function(parent = noone) {
for( var i = input_fix_len; i < ds_list_size(inputs); i++ ) {
for( var i = input_fix_len; i < ds_list_size(inputs); i++ )
inputs[| i].editWidget.register(parent);
}
}
input_display_list = [
["Function", false], 0,
["Arguments", false], argument_renderer,
["Inputs", true],
["Inputs", true],
]
input_fix_len = ds_list_size(inputs);
@ -79,10 +107,13 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
array_resize(input_display_list, input_display_len);
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
if(inputs[| i].getValue() != "") {
var varName = inputs[| i].getValue();
if(varName != "") {
ds_list_add(_in, inputs[| i + 0]);
ds_list_add(_in, inputs[| i + 1]);
inputs[| i + 1].editWidget.interactable = true;
inputs[| i + 1].editWidget.setInteract(true);
inputs[| i + 1].name = varName;
array_push(input_display_list, i + 1);
} else {
@ -101,12 +132,10 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
}
static onValueUpdate = function(index = 0) {
if(index < input_fix_len) return;
if(LOADING || APPENDING) return;
if(safe_mod(index - input_fix_len, data_length) == 0) { //Variable name
if(safe_mod(index - input_fix_len, data_length) == 0) //Variable name
inputs[| index + 1].name = inputs[| index].getValue();
}
refreshDynamicInput();
}

View file

@ -5,7 +5,7 @@
"isCompatibility": false,
"isDnD": false,
"parent": {
"name": "for",
"path": "folders/nodes/data/iterate/for.yy",
"name": "iterate",
"path": "folders/nodes/data/iterate.yy",
},
}

View file

@ -417,7 +417,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
ds_list_add(values, "Numbers");
addNodeObject(values, "Number", s_node_number, "Node_Number", [1, Node_Number]);
addNodeObject(values, "Math", s_node_math, "Node_Math", [0, Node_create_Math], [ "add", "subtract", "multiply", "divide", "power", "modulo", "round", "ceiling", "floor", "sin", "cos", "tan", "abs" ]);
addNodeObject(values, "Equation", s_node_equation, "Node_Equation", [1, Node_Equation],, "Evaluate string of equation. With an option for setting variables.");
addNodeObject(values, "Equation", s_node_equation, "Node_Equation", [0, Node_create_Equation],, "Evaluate string of equation. With an option for setting variables.");
addNodeObject(values, "Random", s_node_random, "Node_Random", [1, Node_Random]);
addNodeObject(values, "Statistic", s_node_statistic, "Node_Statistic", [0, Node_create_Statistic], ["sum", "average", "mean", "median", "min", "max"]);
addNodeObject(values, "Vector2", s_node_vec2, "Node_Vector2", [1, Node_Vector2]);
@ -438,7 +438,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
ds_list_add(values, "Arrays");
addNodeObject(values, "Array", s_node_array, "Node_Array", [1, Node_Array]);
addNodeObject(values, "Array Range", s_node_array_range, "Node_Array_Range", [1, Node_Array_Range],, "Create array of number in range by setting start, end and step size.");
addNodeObject(values, "Array Range", s_node_array_range, "Node_Array_Range", [1, Node_Array_Range],, "Create array of numbers by setting start, end and step length.");
addNodeObject(values, "Array Add", s_node_array_add, "Node_Array_Add", [1, Node_Array_Add], ["add array"]);
addNodeObject(values, "Array Length", s_node_array_length, "Node_Array_Length", [1, Node_Array_Length]);
addNodeObject(values, "Array Get", s_node_array_get, "Node_Array_Get", [1, Node_Array_Get], ["get array"]);
@ -451,7 +451,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
addNodeObject(values, "Array Zip", s_node_array_zip, "Node_Array_Zip", [1, Node_Array_Zip]).setVersion(1138);
addNodeObject(values, "Sort Array", s_node_array_sort, "Node_Array_Sort", [1, Node_Array_Sort], ["array sort"]).setVersion(1120);
addNodeObject(values, "Shuffle Array", s_node_array_shuffle, "Node_Array_Shuffle", [1, Node_Array_Shuffle], ["array shuffle"]).setVersion(1120);
addNodeObject(values, "Loop Array", s_node_loop_array, "Node_Iterate_Each", [1, Node_Iterate_Each], ["iterate each", "for each", "array loop"], "Create group that iterate to each member in an array.");
addNodeObject(values, "Filter Array", s_node_filter_array, "Node_Iterate_Filter", [1, Node_Iterate_Filter], "Filter array using condition.").setVersion(1140);
ds_list_add(values, "Paths");
addNodeObject(values, "Path", s_node_path, "Node_Path", [1, Node_Path]);
addNodeObject(values, "Path Array", s_node_path_array, "Node_Path_Array", [1, Node_Path_Array]).setVersion(1137);
@ -522,8 +524,8 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
addNodeObject(node, "Feedback", s_node_feedback, "Node_Feedback", [1, Node_Feedback],, "Create group that reuse output from last frame to the current one.");
addNodeObject(node, "Loop", s_node_loop, "Node_Iterate", [1, Node_Iterate], ["iterate", "for"], "Create group that reuse output as input repeatedly in one frame.");
addNodeObject(node, "Loop Array", s_node_loop_array, "Node_Iterate_Each", [1, Node_Iterate_Each], ["iterate each", "for each", "array loop"], "Create group that iterate to each member in an array.");
addNodeObject(node, "Filter Array", s_node_filter_array,"Node_Iterate_Filter", [1, Node_Iterate_Filter], "Filter array using condition.");
addNodeObject(node, "Filter Array", s_node_filter_array,"Node_Iterate_Filter", [1, Node_Iterate_Filter], "Filter array using condition.").setVersion(1140);
ds_list_add(node, "Lua");
addNodeObject(node, "Lua Global", s_node_lua_global, "Node_Lua_Global", [1, Node_Lua_Global]).setVersion(1090);
addNodeObject(node, "Lua Surface", s_node_lua_surface, "Node_Lua_Surface", [1, Node_Lua_Surface]).setVersion(1090);

View file

@ -1,27 +1,28 @@
#region evaluator
global.EQUATION_PRES = ds_map_create();
global.EQUATION_PRES[? "+"] = 1;
global.EQUATION_PRES[? "-"] = 1;
global.EQUATION_PRES[? "*"] = 2;
global.EQUATION_PRES[? "/"] = 2;
global.EQUATION_PRES[? "^"] = 3;
global.EQUATION_PRES[? "sin"] = 5;
global.EQUATION_PRES[? "cos"] = 5;
global.EQUATION_PRES[? "tan"] = 5;
global.EQUATION_PRES[? "abs"] = 5;
global.EQUATION_PRES[? "round"] = 5;
global.EQUATION_PRES[? "ceil"] = 5;
global.EQUATION_PRES[? "floor"] = 5;
function evaluateFunction(fx, params = {}) {
static pres = ds_map_create();
pres[? "+"] = 1;
pres[? "-"] = 1;
pres[? "*"] = 2;
pres[? "/"] = 2;
pres[? "^"] = 3;
pres[? "sin"] = 5;
pres[? "cos"] = 5;
pres[? "tan"] = 5;
pres[? "abs"] = 5;
pres[? "round"] = 5;
pres[? "ceil"] = 5;
pres[? "floor"] = 5;
var vl = ds_stack_create();
var op = ds_stack_create();
var pres = global.EQUATION_PRES;
var vl = ds_stack_create();
var op = ds_stack_create();
fx = string_replace_all(fx, " ", "");
fx = string_replace_all(fx, "\n", "");
var len = string_length(fx);
var l = 1;
var l = 1;
var ch, cch;
while(l <= len) {