mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-02-03 00:35:14 +01:00
Add array spreading options
This commit is contained in:
parent
edd2a86779
commit
6c3247a8b0
12 changed files with 51 additions and 33 deletions
|
@ -40,7 +40,7 @@ function array_safe_get(arr, index, def = 0, overflow = ARRAY_OVERFLOW._default)
|
||||||
|
|
||||||
function array_exists(arr, val) {
|
function array_exists(arr, val) {
|
||||||
for( var i = 0; i < array_length(arr); i++ ) {
|
for( var i = 0; i < array_length(arr); i++ ) {
|
||||||
if(arr[i] == val) return true;
|
if(isEqual(arr[i], val)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ function array_empty(arr) {
|
||||||
|
|
||||||
function array_find(arr, val) {
|
function array_find(arr, val) {
|
||||||
for( var i = 0; i < array_length(arr); i++ ) {
|
for( var i = 0; i < array_length(arr); i++ ) {
|
||||||
if(arr[i] == val) return i;
|
if(isEqual(arr[i], val)) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Any", "Surface", "Number", "Color", "Text" ])
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Any", "Surface", "Number", "Color", "Text" ])
|
||||||
.rejectArray();
|
.rejectArray();
|
||||||
|
|
||||||
|
inputs[| 1] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
|
||||||
|
.rejectArray();
|
||||||
|
|
||||||
array_adjust_tool = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
array_adjust_tool = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
||||||
var _h = ui(48);
|
var _h = ui(48);
|
||||||
|
|
||||||
|
@ -53,7 +56,7 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
return _h;
|
return _h;
|
||||||
});
|
});
|
||||||
|
|
||||||
input_display_list = [ 0, array_adjust_tool ];
|
input_display_list = [ 0, 1, array_adjust_tool ];
|
||||||
|
|
||||||
input_fix_len = ds_list_size(inputs);
|
input_fix_len = ds_list_size(inputs);
|
||||||
input_display_list_len = array_length(input_display_list);
|
input_display_list_len = array_length(input_display_list);
|
||||||
|
@ -64,12 +67,6 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
attributes[? "size"] = 1;
|
attributes[? "size"] = 1;
|
||||||
attributes[? "spread_value"] = false;
|
attributes[? "spread_value"] = false;
|
||||||
|
|
||||||
array_push(attributeEditors, "Node");
|
|
||||||
array_push(attributeEditors, ["Spread array", "spread_value",
|
|
||||||
new checkBox(function() {
|
|
||||||
attributes[? "spread_value"] = !attributes[? "spread_value"];
|
|
||||||
})]);
|
|
||||||
|
|
||||||
static getType = function() {
|
static getType = function() {
|
||||||
var _type = inputs[| 0].getValue();
|
var _type = inputs[| 0].getValue();
|
||||||
|
|
||||||
|
@ -159,11 +156,12 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
outputs[| 0].type = _typ;
|
outputs[| 0].type = _typ;
|
||||||
var res = [];
|
var res = [];
|
||||||
var ind = 0;
|
var ind = 0;
|
||||||
|
var spd = inputs[| 1].getValue();
|
||||||
|
|
||||||
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
||||||
var val = inputs[| i].getValue();
|
var val = inputs[| i].getValue();
|
||||||
|
|
||||||
if(is_array(val) && attributes[? "spread_value"])
|
if(is_array(val) && spd)
|
||||||
array_append(res, val);
|
array_append(res, val);
|
||||||
else
|
else
|
||||||
array_push(res, val);
|
array_push(res, val);
|
||||||
|
@ -194,13 +192,4 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static attributeSerialize = function() {
|
|
||||||
var att = ds_map_create();
|
|
||||||
ds_map_override(att, attributes);
|
|
||||||
return att;
|
|
||||||
}
|
|
||||||
|
|
||||||
static attributeDeserialize = function(attr) {
|
|
||||||
ds_map_override(attributes, attr);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -9,6 +9,9 @@ function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
||||||
.setVisible(true, true);
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
inputs[| 1] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
|
||||||
|
.rejectArray();
|
||||||
|
|
||||||
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
|
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
|
||||||
|
|
||||||
input_fix_len = ds_list_size(inputs);
|
input_fix_len = ds_list_size(inputs);
|
||||||
|
@ -60,6 +63,8 @@ function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
|
|
||||||
if(!is_array(_arr)) return;
|
if(!is_array(_arr)) return;
|
||||||
var _type = inputs[| 0].value_from.type;
|
var _type = inputs[| 0].value_from.type;
|
||||||
|
var spd = inputs[| 1].getValue();
|
||||||
|
|
||||||
inputs[| 0].type = _type;
|
inputs[| 0].type = _type;
|
||||||
outputs[| 0].type = _type;
|
outputs[| 0].type = _type;
|
||||||
|
|
||||||
|
@ -68,7 +73,7 @@ function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
var _val = inputs[| i].getValue();
|
var _val = inputs[| i].getValue();
|
||||||
inputs[| i].type = _type;
|
inputs[| i].type = _type;
|
||||||
|
|
||||||
if(is_array(_val))
|
if(is_array(_val) && spd)
|
||||||
array_append(_out, _val);
|
array_append(_out, _val);
|
||||||
else
|
else
|
||||||
array_push(_out, _val);
|
array_push(_out, _val);
|
||||||
|
|
|
@ -14,6 +14,9 @@ function Node_Array_Insert(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
inputs[| 2] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
inputs[| 2] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
||||||
.setVisible(true, true);
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
inputs[| 3] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
|
||||||
|
.rejectArray();
|
||||||
|
|
||||||
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
||||||
|
|
||||||
static update = function(frame = ANIMATOR.current_frame) {
|
static update = function(frame = ANIMATOR.current_frame) {
|
||||||
|
@ -27,6 +30,7 @@ function Node_Array_Insert(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
|
|
||||||
var index = inputs[| 1].getValue();
|
var index = inputs[| 1].getValue();
|
||||||
var value = inputs[| 2].getValue();
|
var value = inputs[| 2].getValue();
|
||||||
|
var spred = inputs[| 3].getValue();
|
||||||
var _len = array_length(_arr);
|
var _len = array_length(_arr);
|
||||||
|
|
||||||
if(inputs[| 0].value_from != noone) {
|
if(inputs[| 0].value_from != noone) {
|
||||||
|
@ -46,7 +50,7 @@ function Node_Array_Insert(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
} else {
|
} else {
|
||||||
if(index < 0) index = array_length(arr) + index;
|
if(index < 0) index = array_length(arr) + index;
|
||||||
|
|
||||||
if(is_array(value)) {
|
if(is_array(value) && spred) {
|
||||||
for( var i = 0; i < array_length(value); i++ )
|
for( var i = 0; i < array_length(value); i++ )
|
||||||
array_insert(arr, index + i, value[i]);
|
array_insert(arr, index + i, value[i]);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,6 +18,9 @@ function Node_Array_Remove(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
inputs[| 3] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
inputs[| 3] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
||||||
.setVisible(true, true);
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
inputs[| 4] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
|
||||||
|
.rejectArray();
|
||||||
|
|
||||||
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
||||||
|
|
||||||
static step = function() {
|
static step = function() {
|
||||||
|
@ -47,6 +50,7 @@ function Node_Array_Remove(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
var type = inputs[| 1].getValue();
|
var type = inputs[| 1].getValue();
|
||||||
var index = inputs[| 2].getValue();
|
var index = inputs[| 2].getValue();
|
||||||
var value = inputs[| 3].getValue();
|
var value = inputs[| 3].getValue();
|
||||||
|
var spred = inputs[| 4].getValue();
|
||||||
|
|
||||||
var arr = array_clone(_arr);
|
var arr = array_clone(_arr);
|
||||||
|
|
||||||
|
@ -59,7 +63,7 @@ function Node_Array_Remove(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
array_delete(arr, index[i], 1);
|
array_delete(arr, index[i], 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!is_array(value)) value = [ value ];
|
if(!spred || !is_array(value)) value = [ value ];
|
||||||
|
|
||||||
for( var i = 0; i < array_length(value); i++ )
|
for( var i = 0; i < array_length(value); i++ )
|
||||||
array_remove(arr, value[i]);
|
array_remove(arr, value[i]);
|
||||||
|
|
|
@ -36,7 +36,10 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group
|
||||||
attributes[? "fill_iteration"] = -1;
|
attributes[? "fill_iteration"] = -1;
|
||||||
array_push(attributeEditors, "Algorithm");
|
array_push(attributeEditors, "Algorithm");
|
||||||
array_push(attributeEditors, ["Fill iteration", "fill_iteration",
|
array_push(attributeEditors, ["Fill iteration", "fill_iteration",
|
||||||
new textBox(TEXTBOX_INPUT.number, function(val) { attributes[? "fill_iteration"] = val; })]);
|
new textBox(TEXTBOX_INPUT.number, function(val) {
|
||||||
|
attributes[? "fill_iteration"] = val;
|
||||||
|
triggerRender();
|
||||||
|
})]);
|
||||||
|
|
||||||
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
||||||
inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
|
inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
|
||||||
|
|
|
@ -46,9 +46,9 @@ function Node_Iterate_Filter(_x, _y, _group = noone) : Node_Collection(_x, _y, _
|
||||||
surface_array_free(arrOut);
|
surface_array_free(arrOut);
|
||||||
outputs[| 0].setValue([])
|
outputs[| 0].setValue([])
|
||||||
|
|
||||||
LOG("Loop begin");
|
LOG_LINE_IF(global.RENDER_LOG, "Loop begin");
|
||||||
var _val = outputs[| 0].getValue();
|
var _val = outputs[| 0].getValue();
|
||||||
LOG("Output original value " + string(_val));
|
LOG_LINE_IF(global.RENDER_LOG, "Output original value " + string(_val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static getIterationCount = function() {
|
static getIterationCount = function() {
|
||||||
|
|
|
@ -78,7 +78,7 @@ function Node_Iterator_Filter_Output(_x, _y, _group = noone) : Node(_x, _y, _gro
|
||||||
array_push(_val, _new_val);
|
array_push(_val, _new_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG("Value " + string(val) + " filter result " + string(res) + " to array " + string(_val));
|
LOG_IF(global.RENDER_LOG, "Value " + string(val) + " filter result " + string(res) + " to array " + string(_val));
|
||||||
|
|
||||||
group.outputs[| 0].setValue(_val);
|
group.outputs[| 0].setValue(_val);
|
||||||
group.iterationUpdate();
|
group.iterationUpdate();
|
||||||
|
|
|
@ -21,7 +21,11 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
|
|
||||||
array_push(attributeEditors, "Array processor");
|
array_push(attributeEditors, "Array processor");
|
||||||
array_push(attributeEditors, [ "Array process type", "array_process",
|
array_push(attributeEditors, [ "Array process type", "array_process",
|
||||||
new scrollBox([ "Loop", "Hold", "Expand", "Expand inverse" ], function(val) { attributes[? "array_process"] = val; }, false) ]);
|
new scrollBox([ "Loop", "Hold", "Expand", "Expand inverse" ],
|
||||||
|
function(val) {
|
||||||
|
attributes[? "array_process"] = val;
|
||||||
|
triggerRender();
|
||||||
|
}, false) ]);
|
||||||
|
|
||||||
static process_data = function(_outSurf, _data, _output_index, _array_index = 0) { return _outSurf; }
|
static process_data = function(_outSurf, _data, _output_index, _array_index = 0) { return _outSurf; }
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,10 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
|
|
||||||
attributes[? "max_shape"] = 32;
|
attributes[? "max_shape"] = 32;
|
||||||
array_push(attributeEditors, ["Maximum shapes", "max_shape",
|
array_push(attributeEditors, ["Maximum shapes", "max_shape",
|
||||||
new textBox(TEXTBOX_INPUT.number, function(val) { attributes[? "max_shape"] = val; })]);
|
new textBox(TEXTBOX_INPUT.number, function(val) {
|
||||||
|
attributes[? "max_shape"] = val;
|
||||||
|
triggerRender();
|
||||||
|
})]);
|
||||||
|
|
||||||
function get_color_buffer(_x, _y) {
|
function get_color_buffer(_x, _y) {
|
||||||
buffer_seek(surface_buffer, buffer_seek_start, (surface_w * _y + _x) * 4);
|
buffer_seek(surface_buffer, buffer_seek_start, (surface_w * _y + _x) * 4);
|
||||||
|
|
|
@ -55,7 +55,10 @@ function Node_Mesh_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
||||||
|
|
||||||
attributes[? "iteration"] = 4;
|
attributes[? "iteration"] = 4;
|
||||||
array_push(attributeEditors, ["Iteration", "iteration",
|
array_push(attributeEditors, ["Iteration", "iteration",
|
||||||
new textBox(TEXTBOX_INPUT.number, function(val) { attributes[? "iteration"] = val; })]);
|
new textBox(TEXTBOX_INPUT.number, function(val) {
|
||||||
|
attributes[? "iteration"] = val;
|
||||||
|
triggerRender();
|
||||||
|
})]);
|
||||||
|
|
||||||
tools = [
|
tools = [
|
||||||
new NodeTool( "Add / Remove (+ Shift) control point", THEME.control_add ),
|
new NodeTool( "Add / Remove (+ Shift) control point", THEME.control_add ),
|
||||||
|
|
|
@ -3,9 +3,9 @@ function Panel_Graph() : PanelContent() constructor {
|
||||||
context_str = "Graph";
|
context_str = "Graph";
|
||||||
icon = THEME.panel_graph;
|
icon = THEME.panel_graph;
|
||||||
|
|
||||||
scale = [ 0.25, 0.33, 0.5, 0.65, 0.8, 1, 1.2, 1.35, 1.5];
|
scale = [ 0.01, 0.02, 0.05, 0.10, 0.15, 0.20, 0.25, 0.33, 0.5, 0.65, 0.8, 1, 1.2, 1.35, 1.5, 2.0];
|
||||||
graph_s_index = 5;
|
graph_s_index = array_find(scale, 1);
|
||||||
graph_s = ui(scale[graph_s_index]);
|
graph_s = 1;
|
||||||
graph_s_to = graph_s;
|
graph_s_to = graph_s;
|
||||||
graph_line_s = 32;
|
graph_line_s = 32;
|
||||||
grid_color = c_white;
|
grid_color = c_white;
|
||||||
|
@ -348,9 +348,12 @@ function Panel_Graph() : PanelContent() constructor {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawGrid() {
|
function drawGrid() {
|
||||||
|
var gls = graph_line_s;
|
||||||
|
if(graph_s <= 0.15) gls *= 10;
|
||||||
|
|
||||||
var gr_x = graph_x * graph_s;
|
var gr_x = graph_x * graph_s;
|
||||||
var gr_y = graph_y * graph_s;
|
var gr_y = graph_y * graph_s;
|
||||||
var gr_ls = graph_line_s * graph_s;
|
var gr_ls = gls * graph_s;
|
||||||
var xx = -gr_ls, xs = safe_mod(gr_x, gr_ls);
|
var xx = -gr_ls, xs = safe_mod(gr_x, gr_ls);
|
||||||
var yy = -gr_ls, ys = safe_mod(gr_y, gr_ls);
|
var yy = -gr_ls, ys = safe_mod(gr_y, gr_ls);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue