mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 22:16:17 +01:00
Websocket update
This commit is contained in:
parent
a7bb431b86
commit
c009bfa555
13 changed files with 240 additions and 156 deletions
|
@ -639,6 +639,7 @@
|
|||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_control_pin.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_control_remove.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_control_unpin.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_crop_tool.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_mesh_delete.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_mesh_edit.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"s_path_tools_add.png","CopyToMask":-1,"filePath":"datafiles/data/themes/default/graphics/tool",},
|
||||
|
|
Binary file not shown.
|
@ -58,6 +58,8 @@ event_inherited();
|
|||
var menu = [
|
||||
menuItem(fav? __txtx("add_node_remove_favourite", "Remove from favourite") : __txtx("add_node_add_favourite", "Add to favourite"),
|
||||
function() {
|
||||
if(!is_array(global.FAV_NODES)) global.FAV_NODES = [];
|
||||
|
||||
if(array_exists(global.FAV_NODES, node_menu_selecting.node))
|
||||
array_remove(global.FAV_NODES, node_menu_selecting.node);
|
||||
else
|
||||
|
@ -305,7 +307,7 @@ event_inherited();
|
|||
case "Action" :
|
||||
case "Custom" :
|
||||
case "Extra" :
|
||||
cc = COLORS._main_text_sub;
|
||||
cc = merge_color(COLORS._main_text_inner, COLORS._main_text_sub, 0.75);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -267,6 +267,8 @@
|
|||
IMAGE_FETCH_MAP = ds_map_create();
|
||||
|
||||
asyncInit();
|
||||
|
||||
network_set_config(network_config_use_non_blocking_socket, 0);
|
||||
#endregion
|
||||
|
||||
#region steam
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/// @description
|
||||
var port = async_load[? "port"];
|
||||
var _id = async_load[? "id"];
|
||||
|
||||
if(!ds_map_exists(PORT_MAP, port)) exit;
|
||||
var nodeTarget = PORT_MAP[? port];
|
||||
for( var i = 0, n = array_length(nodeTarget); i < n; i++ ) {
|
||||
if(is_struct(nodeTarget[i]) && nodeTarget[i].active)
|
||||
nodeTarget[i].asyncPackets(async_load);
|
||||
}
|
||||
if(!ds_map_exists(PORT_MAP, _id)) exit;
|
||||
var nodeTarget = PORT_MAP[? _id];
|
||||
nodeTarget.asyncPackets(async_load);
|
|
@ -27,6 +27,7 @@ function _loadColor(theme = "default", replace = false) {
|
|||
|
||||
var clrs = json_load_struct(path);
|
||||
var oclr = file_exists(pathO)? json_load_struct(pathO) : {};
|
||||
print(clrs);
|
||||
|
||||
var valkeys = variable_struct_get_names(clrs.values);
|
||||
if(replace) THEME_VALUE = clrs.values;
|
||||
|
|
|
@ -14,11 +14,6 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
array_adjust_tool = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
||||
var _h = ui(48);
|
||||
|
||||
draw_set_color(COLORS._main_icon);
|
||||
draw_set_alpha(0.75);
|
||||
//draw_line_width(_x + ui(8), _y + _h, _x + _w - ui(16), _y + _h, 2);
|
||||
draw_set_alpha(1);
|
||||
|
||||
var bw = _w / 2 - ui(4);
|
||||
var bh = ui(36);
|
||||
var bx = _x;
|
||||
|
@ -95,10 +90,9 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
var lastNode = noone;
|
||||
|
||||
for( var i = 0; i < ds_list_size(inputs); i++ ) {
|
||||
|
||||
if(i < input_fix_len || i < amo || inputs[| i].value_from)
|
||||
ds_list_add(_l, inputs[| i]);
|
||||
else
|
||||
delete inputs[| i];
|
||||
}
|
||||
|
||||
var _add = amo - (ds_list_size(_l) - input_fix_len);
|
||||
|
@ -121,20 +115,12 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
ds_list_destroy(inputs);
|
||||
inputs = _l;
|
||||
|
||||
if(extra)
|
||||
lastNode = createNewInput();
|
||||
print($"Refresh inputs [{ds_list_size(inputs)}]: {input_display_list}");
|
||||
if(extra) lastNode = createNewInput();
|
||||
} #endregion
|
||||
|
||||
static onValueUpdate = function(index = 0) { #region
|
||||
if(index != 0) return;
|
||||
|
||||
var ls = ds_list_create();
|
||||
ls[| 0] = inputs[| 0];
|
||||
ls[| 1] = inputs[| 1];
|
||||
ds_list_destroy(inputs);
|
||||
inputs = ls;
|
||||
|
||||
input_display_list = [ 0, array_adjust_tool, 1 ];
|
||||
if(index < input_fix_len) return;
|
||||
|
||||
refreshDynamicInput();
|
||||
} #endregion
|
||||
|
@ -156,10 +142,8 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
||||
var val = getInputData(i);
|
||||
|
||||
if(is_array(val) && spd)
|
||||
array_append(res, val);
|
||||
else
|
||||
array_push(res, val);
|
||||
if(is_array(val) && spd) array_append(res, val);
|
||||
else array_push(res, val);
|
||||
|
||||
inputs[| i].setType(inputs[| i].value_from? inputs[| i].value_from.type : _typ);
|
||||
|
||||
|
@ -168,6 +152,14 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
}
|
||||
|
||||
outputs[| 0].setValue(res);
|
||||
|
||||
if(outputs[| 0].type == VALUE_TYPE.surface) {
|
||||
w = 128;
|
||||
previewable = true;
|
||||
} else {
|
||||
w = 96;
|
||||
previewable = false;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static doApplyDeserialize = function() { #region
|
||||
|
|
|
@ -19,14 +19,14 @@ function Node_Crop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
|
|||
|
||||
attribute_surface_depth();
|
||||
|
||||
drag_side = -1;
|
||||
drag_side = noone;
|
||||
drag_mx = 0;
|
||||
drag_my = 0;
|
||||
drag_sv = 0;
|
||||
|
||||
static getPreviewValues = function() { return getInputData(0); }
|
||||
|
||||
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
||||
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny, params) { #region
|
||||
if(array_length(current_data) < 2) return;
|
||||
|
||||
var _inSurf = current_data[0];
|
||||
|
@ -43,87 +43,132 @@ function Node_Crop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
|
|||
var sp_t = _y + _splice[1] * _s;
|
||||
var sp_b = _y + (dim[1] - _splice[3]) * _s;
|
||||
|
||||
var ww = WIN_W;
|
||||
var hh = WIN_H;
|
||||
|
||||
var _out = outputs[| 0].getValue();
|
||||
draw_surface_ext_safe(_out, sp_l, sp_t, _s, _s);
|
||||
|
||||
draw_set_color(COLORS._main_accent);
|
||||
draw_line(sp_r, -hh, sp_r, hh);
|
||||
draw_line(sp_l, -hh, sp_l, hh);
|
||||
draw_line(-ww, sp_t, ww, sp_t);
|
||||
draw_line(-ww, sp_b, ww, sp_b);
|
||||
draw_set_alpha(0.50);
|
||||
draw_line(sp_r, 0, sp_r, params.h);
|
||||
draw_line(sp_l, 0, sp_l, params.h);
|
||||
draw_line(0, sp_t, params.w, sp_t);
|
||||
draw_line(0, sp_b, params.w, sp_b);
|
||||
draw_set_alpha(1);
|
||||
|
||||
if(drag_side > -1) {
|
||||
draw_line_width(sp_r, sp_t - 1, sp_r, sp_b + 1, 2);
|
||||
draw_line_width(sp_l, sp_t - 1, sp_l, sp_b + 1, 2);
|
||||
draw_line_width(sp_l - 1, sp_t, sp_r + 1, sp_t, 2);
|
||||
draw_line_width(sp_l - 1, sp_b, sp_r + 1, sp_b, 2);
|
||||
|
||||
var _hov = noone;
|
||||
|
||||
if(drag_side != noone) {
|
||||
var vv;
|
||||
|
||||
if(drag_side == 0) vv = value_snap(drag_sv - (_mx - drag_mx) / _s, _snx);
|
||||
else if(drag_side == 2) vv = value_snap(drag_sv + (_mx - drag_mx) / _s, _snx);
|
||||
else if(drag_side == 1) vv = value_snap(drag_sv + (_my - drag_my) / _s, _sny);
|
||||
else vv = value_snap(drag_sv - (_my - drag_my) / _s, _sny);
|
||||
if(drag_side < 4) {
|
||||
if(drag_side == 0) vv = value_snap(drag_sv - (_mx - drag_mx) / _s, _snx);
|
||||
else if(drag_side == 1) vv = value_snap(drag_sv + (_my - drag_my) / _s, _sny);
|
||||
else if(drag_side == 2) vv = value_snap(drag_sv + (_mx - drag_mx) / _s, _snx);
|
||||
else if(drag_side == 3) vv = value_snap(drag_sv - (_my - drag_my) / _s, _sny);
|
||||
|
||||
_splice[drag_side] = vv;
|
||||
} else if(drag_side < 8) {
|
||||
if(drag_side == 4) {
|
||||
_splice[2] = value_snap(drag_sv[2] + (_mx - drag_mx) / _s, _snx);
|
||||
_splice[1] = value_snap(drag_sv[1] + (_my - drag_my) / _s, _sny);
|
||||
} else if(drag_side == 5) {
|
||||
_splice[0] = value_snap(drag_sv[0] - (_mx - drag_mx) / _s, _snx);
|
||||
_splice[1] = value_snap(drag_sv[1] + (_my - drag_my) / _s, _sny);
|
||||
} else if(drag_side == 6) {
|
||||
_splice[2] = value_snap(drag_sv[2] + (_mx - drag_mx) / _s, _snx);
|
||||
_splice[3] = value_snap(drag_sv[3] - (_my - drag_my) / _s, _sny);
|
||||
} else if(drag_side == 7) {
|
||||
_splice[0] = value_snap(drag_sv[0] - (_mx - drag_mx) / _s, _snx);
|
||||
_splice[3] = value_snap(drag_sv[3] - (_my - drag_my) / _s, _sny);
|
||||
}
|
||||
} else if(drag_side == 8) {
|
||||
_splice[0] = value_snap(drag_sv[0] - (_mx - drag_mx) / _s, _snx);
|
||||
_splice[1] = value_snap(drag_sv[1] + (_my - drag_my) / _s, _sny);
|
||||
_splice[2] = value_snap(drag_sv[2] + (_mx - drag_mx) / _s, _snx);
|
||||
_splice[3] = value_snap(drag_sv[3] - (_my - drag_my) / _s, _sny);
|
||||
}
|
||||
|
||||
_splice[drag_side] = vv;
|
||||
if(inputs[| 1].setValue(_splice))
|
||||
UNDO_HOLDING = true;
|
||||
|
||||
if(mouse_release(mb_left, active)) {
|
||||
drag_side = -1;
|
||||
drag_side = noone;
|
||||
UNDO_HOLDING = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(distance_to_line_infinite(_mx, _my, sp_r, -hh, sp_r, hh) < 12) {
|
||||
draw_line_width(sp_r, -hh, sp_r, hh, 3);
|
||||
draw_set_color(merge_color(c_white, COLORS._main_accent, 0.5));
|
||||
|
||||
if(drag_side == 4 || point_in_circle(_mx, _my, sp_l, sp_t, 12)) {
|
||||
draw_line_width(sp_l, 0, sp_l, params.h, 4);
|
||||
draw_line_width(0, sp_t, params.w, sp_t, 4);
|
||||
draw_sprite_colored(THEME.anchor_selector, 1, sp_l, sp_t);
|
||||
_hov = 4;
|
||||
} else if(drag_side == 5 || point_in_circle(_mx, _my, sp_r, sp_t, 12)) {
|
||||
draw_line_width(sp_r, 0, sp_r, params.h, 4);
|
||||
draw_line_width(0, sp_t, params.w, sp_t, 4);
|
||||
draw_sprite_colored(THEME.anchor_selector, 1, sp_r, sp_t);
|
||||
_hov = 5;
|
||||
} else if(drag_side == 6 || point_in_circle(_mx, _my, sp_l, sp_b, 12)) {
|
||||
draw_line_width(sp_l, 0, sp_l, params.h, 4);
|
||||
draw_line_width(0, sp_b, params.w, sp_b, 4);
|
||||
draw_sprite_colored(THEME.anchor_selector, 1, sp_l, sp_b);
|
||||
_hov = 6;
|
||||
} else if(drag_side == 7 || point_in_circle(_mx, _my, sp_r, sp_b, 12)) {
|
||||
draw_line_width(sp_r, 0, sp_r, params.h, 4);
|
||||
draw_line_width(0, sp_b, params.w, sp_b, 4);
|
||||
draw_sprite_colored(THEME.anchor_selector, 1, sp_r, sp_b);
|
||||
_hov = 7;
|
||||
} else if(drag_side == 0 || distance_to_line(_mx, _my, sp_r, 0, sp_r, params.h) < 12) {
|
||||
draw_line_width(sp_r, 0, sp_r, params.h, 4);
|
||||
_hov = 0;
|
||||
} else if(drag_side == 1 || distance_to_line(_mx, _my, 0, sp_t, params.w, sp_t) < 12) {
|
||||
draw_line_width(0, sp_t, params.w, sp_t, 4);
|
||||
_hov = 1;
|
||||
} else if(drag_side == 2 || distance_to_line(_mx, _my, sp_l, 0, sp_l, params.h) < 12) {
|
||||
draw_line_width(sp_l, 0, sp_l, params.h, 4);
|
||||
_hov = 2;
|
||||
} else if(drag_side == 3 || distance_to_line(_mx, _my, 0, sp_b, params.w, sp_b) < 12) {
|
||||
draw_line_width(0, sp_b, params.w, sp_b, 4);
|
||||
_hov = 3;
|
||||
} else if(drag_side == 8 || point_in_rectangle(_mx, _my, sp_l, sp_t, sp_r, sp_b)) {
|
||||
draw_line_width(sp_r, sp_t - 1, sp_r, sp_b + 1, 4);
|
||||
draw_line_width(sp_l, sp_t - 1, sp_l, sp_b + 1, 4);
|
||||
draw_line_width(sp_l - 1, sp_t, sp_r + 1, sp_t, 4);
|
||||
draw_line_width(sp_l - 1, sp_b, sp_r + 1, sp_b, 4);
|
||||
_hov = 8;
|
||||
}
|
||||
|
||||
if(_hov != 4) draw_sprite_colored(THEME.anchor_selector, 0, sp_l, sp_t);
|
||||
if(_hov != 5) draw_sprite_colored(THEME.anchor_selector, 0, sp_r, sp_t);
|
||||
if(_hov != 6) draw_sprite_colored(THEME.anchor_selector, 0, sp_l, sp_b);
|
||||
if(_hov != 7) draw_sprite_colored(THEME.anchor_selector, 0, sp_r, sp_b);
|
||||
|
||||
if(drag_side == noone && _hov != noone) {
|
||||
if(mouse_press(mb_left, active)) {
|
||||
drag_side = 0;
|
||||
drag_side = _hov;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_sv = _splice[0];
|
||||
}
|
||||
} else if(distance_to_line_infinite(_mx, _my, -ww, sp_t, ww, sp_t) < 12) {
|
||||
draw_line_width(-ww, sp_t, ww, sp_t, 3);
|
||||
if(mouse_press(mb_left, active)) {
|
||||
drag_side = 1;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_sv = _splice[1];
|
||||
}
|
||||
} else if(distance_to_line_infinite(_mx, _my, sp_l, -hh, sp_l, hh) < 12) {
|
||||
draw_line_width(sp_l, -hh, sp_l, hh, 3);
|
||||
if(mouse_press(mb_left, active)) {
|
||||
drag_side = 2;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_sv = _splice[2];
|
||||
}
|
||||
} else if(distance_to_line_infinite(_mx, _my, -ww, sp_b, ww, sp_b) < 12) {
|
||||
draw_line_width(-ww, sp_b, ww, sp_b, 3);
|
||||
if(mouse_press(mb_left, active)) {
|
||||
drag_side = 3;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_sv = _splice[3];
|
||||
drag_sv = _hov < 4? _splice[_hov] : _splice;
|
||||
}
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
||||
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
|
||||
var _inSurf = _data[0];
|
||||
var _crop = _data[1];
|
||||
var _dim = [ surface_get_width_safe(_inSurf) - _crop[0] - _crop[2], surface_get_height_safe(_inSurf) - _crop[1] - _crop[3] ];
|
||||
|
||||
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
|
||||
|
||||
surface_set_target(_outSurf);
|
||||
DRAW_CLEAR
|
||||
BLEND_OVERRIDE;
|
||||
|
||||
surface_set_shader(_outSurf, noone);
|
||||
draw_surface_safe(_inSurf, -_crop[2], -_crop[1]);
|
||||
|
||||
BLEND_NORMAL;
|
||||
surface_reset_target();
|
||||
surface_reset_shader();
|
||||
|
||||
return _outSurf;
|
||||
}
|
||||
} #endregion
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
function Node_create_Image_Animated(_x, _y, _group = noone) {
|
||||
function Node_create_Image_Animated(_x, _y, _group = noone) { #region
|
||||
var path = "";
|
||||
if(!LOADING && !APPENDING && !CLONING) {
|
||||
path = get_open_filenames_compat(".png", "");
|
||||
|
@ -11,19 +11,17 @@ function Node_create_Image_Animated(_x, _y, _group = noone) {
|
|||
node.inputs[| 0].setValue(paths);
|
||||
node.doUpdate();
|
||||
|
||||
//ds_list_add(PANEL_GRAPH.nodes_list, node);
|
||||
return node;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
function Node_create_Image_Animated_path(_x, _y, _path) {
|
||||
function Node_create_Image_Animated_path(_x, _y, _path) { #region
|
||||
var node = new Node_Image_Animated(_x, _y, PANEL_GRAPH.getCurrentContext());
|
||||
|
||||
node.inputs[| 0].setValue(_path);
|
||||
node.doUpdate();
|
||||
|
||||
//ds_list_add(PANEL_GRAPH.nodes_list, node);
|
||||
return node;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
enum ANIMATION_END {
|
||||
loop,
|
||||
|
@ -65,11 +63,15 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
|||
inputs[| 6] = nodeValue("Custom frame order", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
||||
|
||||
inputs[| 7] = nodeValue("Frame", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
|
||||
|
||||
|
||||
inputs[| 8] = nodeValue("Canvas size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2)
|
||||
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "First", "Minimum", "Maximum" ])
|
||||
.rejectArray();
|
||||
|
||||
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
||||
|
||||
input_display_list = [
|
||||
["Image", false], 0, 1,
|
||||
["Image", false], 0, 1, 8,
|
||||
["Animation", false], 5, 4, 6, 7, 2, 3,
|
||||
];
|
||||
|
||||
|
@ -168,8 +170,28 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
|||
var _len = array_length(spr);
|
||||
var _drw = true;
|
||||
|
||||
var ww = sprite_get_width(spr[0]);
|
||||
var hh = sprite_get_height(spr[0]);
|
||||
var _siz = getInputData(8);
|
||||
var sw = sprite_get_width(spr[0]);
|
||||
var sh = sprite_get_height(spr[0]);
|
||||
|
||||
if(_siz) {
|
||||
for( var i = 1, n = array_length(spr); i < n; i++ ) {
|
||||
var _sw = sprite_get_width(spr[i]);
|
||||
var _sh = sprite_get_height(spr[i]);
|
||||
|
||||
if(_siz == 1) {
|
||||
sw = min(_sw, sw);
|
||||
sh = min(_sh, sh);
|
||||
} else if(_siz == 2) {
|
||||
sw = max(_sw, sw);
|
||||
sh = max(_sh, sh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ww = sw;
|
||||
var hh = sh;
|
||||
|
||||
ww += _pad[0] + _pad[2];
|
||||
hh += _pad[1] + _pad[3];
|
||||
|
||||
|
@ -200,8 +222,8 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
|||
|
||||
var curr_w = sprite_get_width(spr[_frame]);
|
||||
var curr_h = sprite_get_height(spr[_frame]);
|
||||
var curr_x = _pad[2] + (ww - curr_w) / 2;
|
||||
var curr_y = _pad[1] + (hh - curr_h) / 2;
|
||||
var curr_x = _pad[2] + (sw - curr_w) / 2;
|
||||
var curr_y = _pad[1] + (sh - curr_h) / 2;
|
||||
|
||||
surface_set_shader(surfs);
|
||||
if(_drw) draw_sprite(spr[_frame], 0, curr_x, curr_y);
|
||||
|
|
|
@ -223,6 +223,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { #regio
|
|||
global.__currPage = "";
|
||||
var favPath = DIRECTORY + "Nodes/fav.json";
|
||||
global.FAV_NODES = file_exists(favPath)? json_load_struct(favPath) : [];
|
||||
if(!is_array(global.FAV_NODES)) global.FAV_NODES = [];
|
||||
|
||||
var recPath = DIRECTORY + "Nodes/recent.json";
|
||||
global.RECENT_NODES = file_exists(recPath)? json_load_struct(recPath) : [];
|
||||
|
|
|
@ -97,7 +97,7 @@ function Node_Stack(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
|
||||
surface_set_target(_outSurf);
|
||||
DRAW_CLEAR
|
||||
BLEND_ALPHA;
|
||||
BLEND_ALPHA_MULP
|
||||
|
||||
var sx = 0, sy = 0;
|
||||
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
||||
|
|
|
@ -19,7 +19,7 @@ function Node_Websocket_Receiver(_x, _y, _group = noone) : Node(_x, _y, _group)
|
|||
port = 0;
|
||||
socket = noone;
|
||||
|
||||
function setPort(newPort) {
|
||||
function setPort(newPort) { #region
|
||||
if(ds_map_exists(PORT_MAP, port))
|
||||
array_remove(PORT_MAP[? port], self);
|
||||
|
||||
|
@ -28,27 +28,27 @@ function Node_Websocket_Receiver(_x, _y, _group = noone) : Node(_x, _y, _group)
|
|||
PORT_MAP[? port] = [];
|
||||
array_push(PORT_MAP[? port], self);
|
||||
|
||||
if(ds_map_exists(NETWORK_SERVERS, newPort))
|
||||
if(ds_map_exists(NETWORK_SERVERS, port))
|
||||
return;
|
||||
|
||||
if(socket >= 0) network_destroy(socket);
|
||||
socket = network_create_server_raw(network_socket_ws, newPort, 16)
|
||||
socket = network_create_server_raw(network_socket_ws, port, 16)
|
||||
if(socket < 0) return;
|
||||
|
||||
NETWORK_SERVERS[? newPort] = socket;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
insp1UpdateTooltip = __txt("Refresh Server");
|
||||
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
|
||||
|
||||
static onInspector1Update = function() {
|
||||
static onInspector1Update = function() { #region
|
||||
var _port = getInputData(0);
|
||||
|
||||
setPort(_port);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
network_trigger = 0;
|
||||
static asyncPackets = function(_async_load) {
|
||||
static asyncPackets = function(_async_load) { #region
|
||||
if(!active) return;
|
||||
|
||||
var _active = getInputData(1);
|
||||
|
@ -78,9 +78,9 @@ function Node_Websocket_Receiver(_x, _y, _group = noone) : Node(_x, _y, _group)
|
|||
network_trigger = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static step = function() {
|
||||
static step = function() { #region
|
||||
if(network_trigger == 1) {
|
||||
outputs[| 1].setValue(1);
|
||||
network_trigger = -1;
|
||||
|
@ -88,17 +88,17 @@ function Node_Websocket_Receiver(_x, _y, _group = noone) : Node(_x, _y, _group)
|
|||
outputs[| 1].setValue(0);
|
||||
network_trigger = 0;
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static update = function(frame = CURRENT_FRAME) {
|
||||
static update = function(frame = CURRENT_FRAME) { #region
|
||||
if(CLONING) return;
|
||||
var _port = getInputData(0);
|
||||
|
||||
if(port != _port)
|
||||
setPort(_port);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
||||
var _active = getInputData(1);
|
||||
var bbox = drawGetBbox(xx, yy, _s);
|
||||
var network = ds_map_try_get(NETWORK_SERVERS, port, noone);
|
||||
|
@ -119,5 +119,5 @@ function Node_Websocket_Receiver(_x, _y, _group = noone) : Node(_x, _y, _group)
|
|||
draw_set_alpha(1);
|
||||
|
||||
draw_sprite_fit(THEME.node_websocket_receive, 0, bbox.xc, (_y0 + _y1) / 2, bbox.w, _y1 - _y0, cc, aa);
|
||||
}
|
||||
} #endregion
|
||||
}
|
|
@ -24,111 +24,128 @@ function Node_Websocket_Sender(_x, _y, _group = noone) : Node(_x, _y, _group) co
|
|||
|
||||
input_display_list = [ 5, 0, 1, 2, 3, 4, 6 ];
|
||||
|
||||
port = 0;
|
||||
url = "";
|
||||
port = 0;
|
||||
url = "";
|
||||
connected = false;
|
||||
socket = noone;
|
||||
|
||||
static connectTo = function(newPort, newUrl) {
|
||||
callbackMap = {};
|
||||
|
||||
attributes.network_timeout = 1000;
|
||||
array_push(attributeEditors, "Network");
|
||||
array_push(attributeEditors, [ "Connection timeout", function() { return attributes.network_timeout; },
|
||||
new textBox(TEXTBOX_INPUT.number, function(val) {
|
||||
attributes.network_timeout = val;
|
||||
network_set_config(network_config_connect_timeout, val);
|
||||
}) ]);
|
||||
|
||||
static connectTo = function(newPort, newUrl, params) { #region
|
||||
//print($"Connecting to {newUrl}:{newPort}");
|
||||
|
||||
if(ds_map_exists(PORT_MAP, port))
|
||||
array_remove(PORT_MAP[? port], self);
|
||||
|
||||
port = newPort;
|
||||
url = newUrl;
|
||||
|
||||
if(!ds_map_exists(PORT_MAP, port))
|
||||
PORT_MAP[? port] = [];
|
||||
array_push(PORT_MAP[? port], self);
|
||||
if(ds_map_exists(NETWORK_CLIENTS, port))
|
||||
network_destroy(NETWORK_CLIENTS[? port]);
|
||||
|
||||
if(ds_map_exists(NETWORK_CLIENTS, newPort))
|
||||
var socket = network_create_socket(network_socket_ws);
|
||||
if(socket < 0) {
|
||||
noti_warning("Websocket sender: Fail to create new socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(socket >= 0) network_destroy(socket);
|
||||
socket = network_create_socket(network_socket_ws);
|
||||
if(socket < 0) return;
|
||||
var _conId = network_connect_raw_async(socket, url, port);
|
||||
PORT_MAP[? _conId] = self;
|
||||
callbackMap[$ _conId] = params;
|
||||
NETWORK_CLIENTS[? _conId] = socket;
|
||||
|
||||
network_connect_raw_async(socket, newUrl, newPort);
|
||||
connected = false;
|
||||
NETWORK_CLIENTS[? newPort] = socket;
|
||||
}
|
||||
//print($"Connecting to {newUrl}:{newPort} complete");
|
||||
} #endregion
|
||||
|
||||
insp1UpdateTooltip = __txt("Reconnect");
|
||||
insp1UpdateTooltip = __txt("Resend");
|
||||
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
|
||||
|
||||
static onInspector1Update = function() {
|
||||
var _port = getInputData(0);
|
||||
var _url = getInputData(5);
|
||||
connectTo(_port, _url);
|
||||
static onInspector1Update = function() { #region
|
||||
triggerRender();
|
||||
} #endregion
|
||||
|
||||
static sendCall = function(ID, params) {
|
||||
var network = ds_map_try_get(NETWORK_CLIENTS, ID, noone);
|
||||
if(network < 0) {
|
||||
noti_warning("Websocket sender: No client.");
|
||||
return;
|
||||
}
|
||||
|
||||
var content = params.content;
|
||||
var res = network_send_raw(network, content, buffer_get_size(content), network_send_text);
|
||||
if(res < 0) noti_warning("Websocket sender: Send error.");
|
||||
}
|
||||
|
||||
static asyncPackets = function(_async_load) {
|
||||
static asyncPackets = function(_async_load) { #region
|
||||
if(!active) return;
|
||||
|
||||
var aid = async_load[? "id"];
|
||||
var type = async_load[? "type"];
|
||||
|
||||
switch(type) {
|
||||
case network_type_non_blocking_connect :
|
||||
noti_status($"Websocket client: Connected at port {port} on node {display_name}");
|
||||
connected = true;
|
||||
break;
|
||||
if(type == network_type_non_blocking_connect) {
|
||||
noti_status($"Websocket sender: Connected at port {port} on node {display_name}");
|
||||
connected = true;
|
||||
var callBack = callbackMap[$ aid];
|
||||
sendCall(aid, callBack);
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static step = function() {
|
||||
static step = function() { #region
|
||||
var _type = getInputData(1);
|
||||
|
||||
inputs[| 2].setVisible(_type == 0, _type == 0);
|
||||
inputs[| 3].setVisible(_type == 1, _type == 1);
|
||||
inputs[| 4].setVisible(_type == 2, _type == 2);
|
||||
inputs[| 6].setVisible(_type == 3, _type == 3);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static update = function(frame = CURRENT_FRAME) {
|
||||
static update = function(frame = CURRENT_FRAME) { #region
|
||||
var _port = getInputData(0);
|
||||
var _target = getInputData(5);
|
||||
|
||||
if(port != _port || url != _target)
|
||||
connectTo(_port, _target);
|
||||
|
||||
var network = ds_map_try_get(NETWORK_CLIENTS, _port, noone);
|
||||
if(network < 0) return;
|
||||
|
||||
var _type = getInputData(1);
|
||||
var _buff, res;
|
||||
var params = {};
|
||||
|
||||
switch(_type) {
|
||||
case 0 :
|
||||
var _stru = getInputData(2);
|
||||
var _str = json_stringify(_stru);
|
||||
_buff = buffer_from_string(_str);
|
||||
res = network_send_raw(network, _buff, buffer_get_size(_buff), network_send_text);
|
||||
break;
|
||||
case 1 :
|
||||
var _surf = getInputData(3);
|
||||
if(!is_surface(_surf)) return;
|
||||
_buff = buffer_from_surface(_surf);
|
||||
res = network_send_raw(network, _buff, buffer_get_size(_buff), network_send_text);
|
||||
break;
|
||||
case 2 :
|
||||
var _path = getInputData(4);
|
||||
if(!file_exists(_path)) return;
|
||||
_buff = buffer_from_file(_path);
|
||||
res = network_send_raw(network, _buff, buffer_get_size(_buff), network_send_text);
|
||||
break;
|
||||
case 3 :
|
||||
_buff = getInputData(6);
|
||||
if(!buffer_exists(_buff)) return;
|
||||
res = network_send_raw(network, _buff, buffer_get_size(_buff), network_send_text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
params.content = _buff;
|
||||
connectTo(_port, _target, params);
|
||||
} #endregion
|
||||
|
||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
||||
var bbox = drawGetBbox(xx, yy, _s);
|
||||
var network = ds_map_try_get(NETWORK_CLIENTS, port, noone);
|
||||
|
||||
var cc = CDEF.red, aa = 1;
|
||||
if(network >= 0) cc = CDEF.lime;
|
||||
var cc = CDEF.lime, aa = 1;
|
||||
//if(network >= 0) cc = CDEF.lime;
|
||||
|
||||
var _y0 = bbox.y0 + ui(16);
|
||||
var _y1 = bbox.y1 - ui(16);
|
||||
|
@ -140,5 +157,9 @@ function Node_Websocket_Sender(_x, _y, _group = noone) : Node(_x, _y, _group) co
|
|||
draw_set_alpha(1);
|
||||
|
||||
draw_sprite_fit(THEME.node_websocket_send, 0, bbox.xc, (_y0 + _y1) / 2, bbox.w, _y1 - _y0, cc, aa);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static doApplyDeserialize = function() { #region
|
||||
if(struct_has(attributes, "network_timeout")) network_set_config(network_config_connect_timeout, attributes.network_timeout);
|
||||
} #endregion
|
||||
}
|
Loading…
Reference in a new issue