Commit 5ad27023 authored by Aayush's avatar Aayush

fixed bugs in ascii_art->pd

parent b38b0126
Pipeline #1643 failed with stage
in 0 seconds
...@@ -279,8 +279,9 @@ ...@@ -279,8 +279,9 @@
"canvas": { "canvas": {
"paste_clipboard_prompt": "Warnung: Sie sind dabei, Pd-Code einzufügen, der außerhalb von Pd erstellt wurde. Möchten Sie fortfahren?", "paste_clipboard_prompt": "Warnung: Sie sind dabei, Pd-Code einzufügen, der außerhalb von Pd erstellt wurde. Möchten Sie fortfahren?",
"ascii_art": { "ascii_art": {
"close": "Close Button", "close": "Close",
"close_tt": "close ascii_art text area" "close_tt": "close ascii_art text area",
"placeholder": "write your ascii_art here"
}, },
"save_dialog": { "save_dialog": {
"prompt": "Speichern der Änderungen in", "prompt": "Speichern der Änderungen in",
......
...@@ -278,8 +278,9 @@ ...@@ -278,8 +278,9 @@
"canvas": { "canvas": {
"paste_clipboard_prompt": "Warning: you are about to paste Pd code that came from somewhere outside of Pd. Do you want to continue?", "paste_clipboard_prompt": "Warning: you are about to paste Pd code that came from somewhere outside of Pd. Do you want to continue?",
"ascii_art": { "ascii_art": {
"close": "Close Button", "close": "Close",
"close_tt": "close ascii_art text area" "close_tt": "close ascii_art text area",
"placeholder": "write your ascii_art here"
}, },
"save_dialog": { "save_dialog": {
"prompt": "Do you want to save the changes you made in", "prompt": "Do you want to save the changes you made in",
......
...@@ -164,15 +164,13 @@ function parse_ascii_art(ascii_art) { ...@@ -164,15 +164,13 @@ function parse_ascii_art(ascii_art) {
} }
} }
} }
// Finding the connection's end points // Finding the connection's end points
for (i = 0 ; i < row ; i++) { for (i = 0 ; i < string_array.length ; i++) {
for (j = 0 ; j < string_array[i].length ; j++) { for (j = 0 ; j < string_array[i].length ; j++) {
// visited_array to travel a connection path only once // visited_array to travel a connection path only once
var temp = string_array[i][j], var temp = string_array[i][j],
flag = 1, flag = 1,
end_index; end_index;
if (visited_array[i][j] == 0) { if (visited_array[i][j] == 0) {
switch(temp) { switch(temp) {
case "|": start_index = new INDEX(i-1, j); case "|": start_index = new INDEX(i-1, j);
...@@ -196,8 +194,11 @@ function parse_ascii_art(ascii_art) { ...@@ -196,8 +194,11 @@ function parse_ascii_art(ascii_art) {
// as a connection starting with X will // as a connection starting with X will
// be a single element connection // be a single element connection
case "X": start_index = new INDEX(i, j); case "X": start_index = new INDEX(i, j+1);
end_index = new INDEX(i, j); end_index = new INDEX(i+1, j-1);
connections_array.push({index1:start_index, index2:end_index});
start_index = new INDEX(i, j-1);
end_index = new INDEX(i+1, j+1);
visited_array[i][j] = 1; visited_array[i][j] = 1;
break; break;
default : flag = 0; default : flag = 0;
...@@ -213,7 +214,6 @@ function parse_ascii_art(ascii_art) { ...@@ -213,7 +214,6 @@ function parse_ascii_art(ascii_art) {
} }
} }
//Finding the mapping between connections and Objects/Messages //Finding the mapping between connections and Objects/Messages
for (i = 0 ; i< connections_array.length ; i++) { for (i = 0 ; i< connections_array.length ; i++) {
var start_index = connections_array[i].index1, var start_index = connections_array[i].index1,
...@@ -224,17 +224,16 @@ function parse_ascii_art(ascii_art) { ...@@ -224,17 +224,16 @@ function parse_ascii_art(ascii_art) {
outlet_object_index=0, outlet_object_index=0,
start_point = 0, start_point = 0,
end_point = 0, end_point = 0,
state_flag = 0; state_flag=0;
for (j = 0 ; j < obj_msg_array.length ; j++) { for (j = 0 ; j < obj_msg_array.length ; j++) {
var start = obj_msg_array[j].index1, var start = obj_msg_array[j].index1,
end = obj_msg_array[j].index2; end = obj_msg_array[j].index2;
if ( start_index.x == end.x ) {
if ( start_index.x == end.x ) {
if ( Math.min( Math.abs(start_index.y - start.y) , if ( Math.min( Math.abs(start_index.y - start.y) ,
Math.abs(start_index.y - end.y) ) < max_distance1 ) { Math.abs(start_index.y - end.y) ) < max_distance1 ) {
outlet_object_index=j; outlet_object_index=j;
max_distance1 = Math.abs(start_index.y - start.y); max_distance1 = Math.min( Math.abs(start_index.y - start.y) ,
Math.abs(start_index.y - end.y) );
state_flag= state_flag+ 1; state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) { if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
start_point = 0; start_point = 0;
...@@ -244,12 +243,12 @@ function parse_ascii_art(ascii_art) { ...@@ -244,12 +243,12 @@ function parse_ascii_art(ascii_art) {
} }
} }
if ( Math.abs(end_index.x - start.x)<=1 ) {
if ( end_index.x == start.x ){
if ( Math.min( Math.abs(end_index.y - start.y) , if ( Math.min( Math.abs(end_index.y - start.y) ,
Math.abs(end_index.y - end.y) ) < max_distance2 ) { Math.abs(end_index.y - end.y) ) < max_distance2 ) {
inlet_object_index=j; inlet_object_index=j;
max_distance2 = Math.abs(end_index.y - end.y); max_distance2 = Math.min( Math.abs(end_index.y - start.y) ,
Math.abs(end_index.y - end.y) );
state_flag= state_flag+ 1; state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) { if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
end_point = 0; end_point = 0;
...@@ -258,10 +257,8 @@ function parse_ascii_art(ascii_art) { ...@@ -258,10 +257,8 @@ function parse_ascii_art(ascii_art) {
} }
} }
} }
} }
if (state_flag>= 2)
if (state_flag== 2)
{ {
state= "valid"; state= "valid";
} else { } else {
...@@ -309,6 +306,6 @@ function parse_ascii_art(ascii_art) { ...@@ -309,6 +306,6 @@ function parse_ascii_art(ascii_art) {
var parser_data = {pd_message:pd_message, var parser_data = {pd_message:pd_message,
state:state}; state:state};
return parser_data; return parser_data;
} };
exports.parse_ascii_art = parse_ascii_art; exports.parse_ascii_art = parse_ascii_art;
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
</div> </div>
<div id="ascii_art" style="display:none;"> <div id="ascii_art" style="display:none;">
<textarea id="ascii_art_text_area" <textarea id="ascii_art_text_area"
rows="10" cols="25">write your ascii art here</textarea> rows="10" cols="25"
data-i18n="canvas.ascii_art.placeholder">
</textarea>
<br/> <br/>
<p id="ascii_art_state">State:partial</p> <p id="ascii_art_state">State:partial</p>
<button type="button" <button type="button"
......
...@@ -1613,6 +1613,7 @@ function nw_create_patch_window_menus(gui, w, name) { ...@@ -1613,6 +1613,7 @@ function nw_create_patch_window_menus(gui, w, name) {
if (display_state === "none") { if (display_state === "none") {
ascii_art.style.setProperty("display", "inline"); ascii_art.style.setProperty("display", "inline");
ascii_art_text_area.focus(); ascii_art_text_area.focus();
ascii_art_text_area.select();
canvas_events.ascii_art(); canvas_events.ascii_art();
} else { } else {
ascii_art_text_area.value = "write your ascii art here"; ascii_art_text_area.value = "write your ascii art here";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment