-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeManager.cs
1357 lines (1267 loc) · 59.7 KB
/
CodeManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.IO;
using UnityEngine.SceneManagement;
public class CodeManager : MonoBehaviour
{
GameObject copier;
string name;
/*** TODO:::
when deleting: give option to edit: precoded other options
Curr:
David: write up 10-20 example projects/exercises (#, title, 1 sentence desc, 2-4 comments)
Editting:
Brian: Clean up editor mode, add pretty lines/animations
***/
Vector2 old_position;
bool not_over_UI;
float tap_duration = 0;
/* MAIN TEXT DISPLAY */
public GameObject Display_Text;
//public float text_height = 62.75f; // 62.75 for 75, 41.75 for 50,
public float text_tab_width = 105f;
public Scrollbar UIElement_CompilationSpeed;
/* Options Menu */
public GameObject UIElement_OptionsMenu;
bool UI_optionsMenuOpen;
public Dropdown UIElement_LoadList;
/* Compiler Menu */
public GameObject UIElement_CompilationMenu;
/* Console variables*/
string Console_output = "Console:\n";
bool on_console = true;
public Text Output_text;
public Text Debug_text;
bool allowed_to_edit;
bool editting_locked = true;
public GameObject UIElement_EdittingMenu;
bool editting_mode;
int editting_tabAmount;
int editting_line;
string editting_line_type;
string editting_variable_type;
bool tapping_over_same_line;
bool entering_string_literal;
bool entering_string;
int line_shift;
bool just_editted = false;
public GameObject UIElement_InputField;
/**
*
* Calculate these in real time: check every line above current for variable declaration, skipping } and every line until a { + 1
*
* */
public List<string> integers_within_editting_scope = new List<string>();
public List<string> doubles_within_editting_scope = new List<string>();
public List<string> booleans_within_editting_scope = new List<string>();
public List<string> strings_within_editting_scope = new List<string>();
string[] available_variable_types;
public List<string> lines;
string[] list_of_PDTs = { "boolean", "char", "double", "int", "String" };
string[] list_of_evaluations = { "==", ">", "<", "<=", ">=", "!=" };
//string[] list_of_operations = { " + ", " - ", " * ", " / ", " % "};
string[] list_of_condensed_operations = { "=", "++", "--", "+=", "-=", "*=", "/=", "%=" };
bool next_else = false; //Used for if/else logic
string loop_condition;
string loop_variable_modifer;
float time_delayer; //counter for compiling speed
/* Initializing code (C++ified) */
void Start()
{
copier = GameObject.Find("CopyField");
copier.SetActive(false);
/* Load blank C++ Arduino document */
lines = new List<string>();
Display_LoadScript("NewClass");
Display_pushText();
}
/* All code that requires running per frame (animation calls, button presses */
void Update()
{
if (Input.GetKeyDown(KeyCode.DownArrow))
{
line_shift++;
Display_Text.transform.position = new Vector2(0,42f * Display_Text.transform.localScale.y * line_shift);
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
line_shift--;
Display_Text.transform.position = new Vector2(0, 42f * Display_Text.transform.localScale.y * line_shift);
}
Display_pushText();
float text_height = 42f * Display_Text.transform.localScale.y;
int current_line = (int)((Screen.height - Input.mousePosition.y) / text_height);
float snap_to_line = current_line * text_height;
float part_of_line = (Screen.height - Input.mousePosition.y) / text_height - Mathf.Round((Screen.height - Input.mousePosition.y) / text_height);
just_editted = false;
current_line += line_shift;
if (Input.GetMouseButtonDown(0) && editting_mode)
{
for (int i = 0; i < UIElement_EdittingMenu.transform.childCount; i++)
{
if (UIElement_EdittingMenu.transform.GetChild(i).gameObject.activeSelf)
{
// print(UIElement_EdittingMenu.transform.GetChild(i).GetChild(0).gameObject.GetComponent<Text>().text);
if (UI_clickCheck(-562.5f/2, 562.5f / 2, -50f, 50f, Input.mousePosition, UIElement_EdittingMenu.transform.GetChild(i).transform.position))
{
not_over_UI = false;
Editor_selectOption(UIElement_EdittingMenu.transform.GetChild(i).GetChild(0).gameObject.GetComponent<Text>().text);
just_editted = true;
break;
}
}
}
}
if (!UIElement_EdittingMenu.activeInHierarchy && !UIElement_InputField.activeInHierarchy)
{
GameObject.Find("EdittingPointer").GetComponent<Image>().color = new Color(1, 1, 1, .5f);
}
else
{
GameObject.Find("EdittingPointer").GetComponent<Image>().color = new Color(1, 1, 1, 0f);
}
if (Input.GetMouseButtonDown(0))
{
old_position = Input.mousePosition;
not_over_UI = true;
if (UI_optionsMenuOpen) not_over_UI = false;
/*Editting Locker*/
//if (UI_clickCheck(0, 200, -200, 0, old_position, UIElement_EdittingLocker.transform.position)) { not_over_UI = false; UI_setColor(UIElement_EdittingLocker, new Color(1, 0, 0)); Editor_toggleLock(); }
/*Options Menu*/
if (UI_clickCheck(0, 1000, 0, 200, old_position, UIElement_OptionsMenu.transform.position))
{ not_over_UI = false; if (UI_clickCheck(0, 200, 0, 200, old_position, UIElement_OptionsMenu.transform.position)) { UI_setColor(UIElement_OptionsMenu, new Color(1, 0, 0)); Display_OptionsMenu(); } }
tapping_over_same_line = true;
}
if ((part_of_line) > -.35f && (part_of_line) < 0)
{
GameObject.Find("EdittingPointer").GetComponent<RectTransform>().sizeDelta = new Vector2(Screen.width / 2, 15);
if (Input.GetMouseButtonDown(0) && current_line < lines.Count && not_over_UI)
{
if (current_line+1 < lines.Count && lines[current_line+1].Contains("{"))
{
GameObject.Find("EdittingPointer").GetComponent<Image>().color = new Color(1, 0, 0, 1f);
}
else if (!UIElement_EdittingMenu.activeInHierarchy && !UIElement_InputField.activeInHierarchy)
{
if (!just_editted) lines.Insert(current_line + 1, "");
}
else
{
}
}
snap_to_line = snap_to_line + 10 + text_height/2;
}
else
{
GameObject.Find("EdittingPointer").GetComponent<RectTransform>().sizeDelta = new Vector2(Screen.width / 2, 40);
if (Input.GetMouseButtonDown(0) && current_line < lines.Count && not_over_UI && !UIElement_EdittingMenu.activeInHierarchy && !UIElement_InputField.activeInHierarchy)
{
if ((lines[current_line].Contains("void") || lines[current_line].Contains("{") || lines[current_line].Contains("}")))
{
GameObject.Find("EdittingPointer").GetComponent<Image>().color = new Color(1, 0, 0, 1f);
}
else
{
if (!just_editted) Editor_start(current_line);
}
}
}
//float snap_to_line = (int)((Screen.height - Input.mousePosition.y) / text_height) * text_height;
GameObject.Find("EdittingPointer").GetComponent<RectTransform>().position = new Vector2(0, Screen.height - snap_to_line );
GameObject.Find("EdittingPointer").transform.GetChild(0).gameObject.GetComponent<Text>().text = (int)((Screen.height - Input.mousePosition.y) / text_height) + "";
allowed_to_edit = true;
if (UIElement_InputField.activeSelf == true) allowed_to_edit = false;
//!!
//font size 50 = 41.75 pixels !!!!
//!!
if (false && Input.GetMouseButtonUp(0))
{
if (tap_duration < .25f && tapping_over_same_line)
{
//short tap
if (allowed_to_edit && not_over_UI && !editting_mode && !UI_optionsMenuOpen)
{
int line = (int)((Screen.height - Input.mousePosition.y + Display_Text.GetComponent<RectTransform>().anchoredPosition.y) / text_height + 1);
if (line < lines.Count - 1)
{
print(lines[line]);
if (lines[line - 1].IndexOf("for") == 0 || lines[line - 1].IndexOf("if") == 0 || lines[line - 1].IndexOf("while") == 0)
{
line++;
}
}
}
}
if (tap_duration > .25f && tapping_over_same_line)
{
if (allowed_to_edit && not_over_UI && !editting_mode && !UI_optionsMenuOpen)
{
int line = (int)((Screen.height - Input.mousePosition.y + Display_Text.GetComponent<RectTransform>().anchoredPosition.y) / text_height);
print(lines[line]);
if (lines[line].Contains("public class"))
{
//if (!editting_locked)
//{
// UI_setColor(UIElement_EdittingLocker, new Color(1, 0, 0));
// Display_pushText(lines, new int[0]);
//}
//else
// {
//UIElement_EdittingMenu.SetActive(true);
Editor_setOptions(new string[] { "Enter the class's name:" });
editting_line_type = "SetClassName";
//}
}
int line_of_main_method = 0;
while (lines[line_of_main_method].Contains("public static void") == false)
{
line_of_main_method++;
}
if (line > ++line_of_main_method && line < lines.Count - 1)
{
// if (!editting_locked)
//{
// UI_setColor(UIElement_EdittingLocker, new Color(1, 0, 0));
// Display_pushText(lines, new int[0]);
//}
//else
//{
if (lines[line].IndexOf("if") == 0 || lines[line].IndexOf("while") == 0 || lines[line].IndexOf("for") == 0)
{
lines.RemoveAt(line);
lines.RemoveAt(line);
int matching_bracket = 0;
for (int i = line; i < lines.Count; i++)
{
if (lines[i].IndexOf("{") == 0)
{
matching_bracket++;
}
if (lines[i].IndexOf("}") == 0)
{
if (matching_bracket == 0)
{
lines.RemoveAt(i);
break;
}
matching_bracket--;
}
}
}
else if (lines[line].Contains("}") == false && lines[line].Contains("{") == false)
{
lines.RemoveAt(line);
}
//}
}
}
}
tap_duration = 0;
}
if (UI_optionsMenuOpen)
{
//UIElement_OptionsMenu.GetComponent<Image>().sprite = (Resources.Load("Sprites/SettingsOpen") as GameObject).GetComponent<SpriteRenderer>().sprite;
UIElement_OptionsMenu.transform.GetChild(0).gameObject.SetActive(true);
UI_setTowardsRectTransform(UIElement_OptionsMenu, -800, -25);
}
else
{
//UIElement_OptionsMenu.GetComponent<Image>().sprite = (Resources.Load("Sprites/SettingsClose") as GameObject).GetComponent<SpriteRenderer>().sprite;
UIElement_OptionsMenu.transform.GetChild(0).gameObject.SetActive(false);
UI_setTowardsRectTransform(UIElement_OptionsMenu, 0, -25);
}
if (editting_mode)
{
//UI_setTowardsRectTransform(Display_Text.gameObject, ((editting_tabAmount) * -1 * text_tab_width) - 100f, Display_Text.GetComponent<RectTransform>().anchoredPosition.y);
UIElement_EdittingMenu.GetComponent<RectTransform>().sizeDelta = new Vector2(lines[editting_line].Length * 120f + 300f, 410f);
UIElement_EdittingMenu.GetComponent<Image>().color = new Color(0, 0, 0, 0);
}
UI_resetColor(UIElement_OptionsMenu, .025f);
UI_resetColor(UIElement_OptionsMenu.transform.GetChild(0).gameObject, .025f);
// UI_resetColor(UIElement_EdittingLocker, .025f);
UI_resetColor(UIElement_EdittingMenu.transform.GetChild(0).gameObject, .025f);
UI_resetColor(UIElement_EdittingMenu.transform.GetChild(1).gameObject, .025f);
UI_resetColor(UIElement_EdittingMenu.transform.GetChild(2).gameObject, .025f);
UI_resetColor(UIElement_EdittingMenu.transform.GetChild(3).gameObject, .025f);
}
/* Check for button press (manual button) */
public bool UI_clickCheck(float xMin, float xMax, float yMin, float yMax, Vector2 mousePosition, Vector2 otherPosition)
{
if (mousePosition.x + xMin < otherPosition.x && mousePosition.x + xMax > otherPosition.x) if (mousePosition.y + yMin < otherPosition.y && mousePosition.y + yMax > otherPosition.y) return true;
return false;
}
/* UI animation assisting methods */
public void UI_moveRectTransform(GameObject item, float x, float y)
{
Vector2 pos = item.GetComponent<RectTransform>().anchoredPosition;
item.GetComponent<RectTransform>().anchoredPosition = new Vector2(pos.x + x, pos.y + y);
}
public void UI_setRectTransform(GameObject item, float x, float y)
{
item.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
}
public void UI_setTowardsRectTransform(GameObject item, float targetX, float targetY)
{
Vector2 pos = item.GetComponent<RectTransform>().anchoredPosition;
if (Mathf.Abs(pos.x - targetX) < .1f && Mathf.Abs(pos.y - targetY) < .1f)
{
if (!(pos.x == targetX && pos.y == targetY)) UI_setRectTransform(item, targetX, targetY);
}
else
{
float style_smoothness = 10f;
item.GetComponent<RectTransform>().anchoredPosition = new Vector2(pos.x - (pos.x - targetX) / style_smoothness, pos.y - (pos.y - targetY) / style_smoothness);
}
}
/* UI color animation assiting methods */
public void UI_setColor(GameObject item, Color color)
{
item.GetComponent<Image>().color = color;
}
public void UI_resetColor(GameObject item, float animation_speed)
{
Color current = item.GetComponent<Image>().color;
if (current.r < 1) current.r += animation_speed;
if (current.r > 1) current.r = 1;
if (current.g < 1) current.g += animation_speed;
if (current.g > 1) current.g = 1;
if (current.b < 1) current.b += animation_speed;
if (current.b > 1) current.b = 1;
item.GetComponent<Image>().color = current;
}
/* Editor initializing method */
public void Editor_start(int line)
{
editting_line = line;
editting_mode = true;
editting_tabAmount = 0;
for (int i = 0; i < line; i++)
{
if (lines[i].IndexOf("{") == 0)
{
editting_tabAmount++;
}
if (lines[i].IndexOf("}") == 0)
{
editting_tabAmount--;
}
}
// print(editting_tabAmount);
// lines.Insert(line, "");
// lines.Insert(line, " ");
// lines.Insert(line, "");
UIElement_EdittingMenu.SetActive(true);
// UI_setRectTransform(UIElement_EdittingMenu, -5, -Screen.height / 2);//(line + 1) * -41.75f + 12f);
//UI_setRectTransform(Display_Text.gameObject,0, (line + 1) * text_height - 511);
editting_line_type = "";
Editor_findVariablesWithinScope(line);
/* Variable
* -Create new variable
* Types
* -Modify existing variable [only if exists in scope]
* Flow Control
* -If
* -Else [only if immediately after an if block]
* -Switch
* -While
* -For
* Method
* -Serial
* Begin, Println, Print
* -Delay
* -pinMode
* -digitalRead
* -analogWrite
* -Make [only if outside other methods]
*
*/
Editor_setOptions(new string[] { "New Line", "Delete Line", "Cancel",});
//Editor_setOptions(new string[] { "Create Variable", "Modify Variable", "Flow Control", "Method" });
}
/* Editor closing method */
public void Editor_end()
{
editting_line = -1;
editting_mode = false;
editting_line_type = "";
UIElement_EdittingMenu.SetActive(false);
}
/* Sketchy code: does typing/entering of code into program from user input */
public void Editor_findVariablesWithinScope(int line)
{
booleans_within_editting_scope = new List<string>();
integers_within_editting_scope = new List<string>();
doubles_within_editting_scope = new List<string>();
strings_within_editting_scope = new List<string>();
for (int i = 0; i < line; i++)
{
for (int types_of_PDTs = 0; types_of_PDTs < list_of_PDTs.Length; types_of_PDTs++)
{
if (lines[i].Contains(list_of_PDTs[types_of_PDTs] + " "))
{
if (lines[i].Contains("for (" + list_of_PDTs[types_of_PDTs] + " ") || lines[i].IndexOf(list_of_PDTs[types_of_PDTs] + " ") == 0)
{
string name = lines[i].Substring(lines[i].IndexOf(list_of_PDTs[types_of_PDTs] + " ") + list_of_PDTs[types_of_PDTs].Length + 1);
if (name.IndexOf(" ") < name.IndexOf(";")) name = name.Remove(name.IndexOf(" "));
else name = name.Remove(name.IndexOf(";"));
switch (types_of_PDTs)
{
case 0: //Add new integer definition to list
booleans_within_editting_scope.Add(name);
break;
case 2: //Add new double definition to list
doubles_within_editting_scope.Add(name);
break;
case 3: //Add new integer definition to list
integers_within_editting_scope.Add(name);
break;
case 4: //Add new string definition to list
strings_within_editting_scope.Add(name);
break;
}
}
}
}
}
List<string> availables = new List<string>();
if (integers_within_editting_scope.Count != 0) availables.Add("Integer");
if (doubles_within_editting_scope.Count != 0) availables.Add("Double");
if (booleans_within_editting_scope.Count != 0) availables.Add("Boolean");
if (strings_within_editting_scope.Count != 0) availables.Add("String");
available_variable_types = availables.ToArray();
}
public void Editor_setOptions(string[] options)
{
Editor_setOptionPositions(options);
entering_string_literal = false;
entering_string = false;
for (int i = 0; i < options.Length; i++)
{
if (i == 0)
{
if (options[i] == "Enter a name:" || options[i] == "Enter a string:" || options[i] == "Enter the class's name:")
{
entering_string = true;
if (options[i] == "Enter a string:") entering_string_literal = true;
UIElement_InputField.SetActive(true);
UIElement_InputField.GetComponent<InputField>().contentType = InputField.ContentType.Standard;
UIElement_InputField.GetComponent<InputField>().placeholder.GetComponent<Text>().text = options[i];
UIElement_EdittingMenu.transform.GetChild(i).gameObject.SetActive(false);
}
else if (options[i] == "Enter a number:")
{
UIElement_InputField.SetActive(true);
if (editting_variable_type == "Integer") UIElement_InputField.GetComponent<InputField>().contentType = InputField.ContentType.IntegerNumber;
else if (editting_variable_type == "Double") UIElement_InputField.GetComponent<InputField>().contentType = InputField.ContentType.DecimalNumber;
UIElement_InputField.GetComponent<InputField>().placeholder.GetComponent<Text>().text = options[i];
UIElement_EdittingMenu.transform.GetChild(i).gameObject.SetActive(false);
}
else
{
UIElement_InputField.SetActive(false);
Editor_setOption(i, options[i]);
UIElement_EdittingMenu.transform.GetChild(i).gameObject.SetActive(true);
}
}
else
{
Editor_setOption(i, options[i]);
UIElement_EdittingMenu.transform.GetChild(i).gameObject.SetActive(true);
}
}
for (int i = options.Length; i < UIElement_EdittingMenu.transform.childCount; i++)
{
UIElement_EdittingMenu.transform.GetChild(i).gameObject.SetActive(false);
}
}
public void Editor_setOption(int option, string text)
{
UIElement_EdittingMenu.transform.GetChild(option).GetChild(0).gameObject.GetComponent<Text>().text = text;
}
public void Editor_finishTyping()
{
string input = UIElement_InputField.GetComponent<InputField>().text;
if (entering_string)
{
input = input.Replace(' ', '_');
if (entering_string_literal)
{
input = "\"" + input + "\"";
}
}
//UIElement_EdittingMenu.transform.GetChild(0).GetChild(1).gameObject.GetComponent<InputField>().text;
UIElement_InputField.GetComponent<InputField>().text = "";
UIElement_InputField.SetActive(false);
//UIElement_EdittingMenu.transform.GetChild(0).GetChild(1).gameObject.GetComponent<InputField>().text = "";
if (editting_line_type == "SetClassName")
{
int line = 0;
while (lines[line].Contains("/*") == false)
{
line++;
}
line++;
lines[line] = "" + input;
Display_pushText();
}
if (editting_line_type.Contains("Write") && !editting_line_type.Contains("Analog Write") && !editting_line_type.Contains("Digital Write"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("Attach"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("Pin Mode"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ", )";
Editor_setOptions(new string[] {"INPUT", "OUTPUT" });
}
if (editting_line_type.Contains( "Map") && editting_line_type.Length > 6)
{
editting_line_type += "p";
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
else if (editting_line_type.Contains("Map"))
{
editting_line_type += "p";
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ", )";
Editor_setOptions(new string[] { "Number" });
}
if (editting_line_type.Contains("Digital Write"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ", )";
Editor_setOptions(new string[] { "HIGH", "LOW"});
}
if (editting_line_type.Contains("Delay"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("Digital Read"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type == "Analog Write")
{
editting_line_type = "Analog Write 2";
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ", )";
string[] answersAWri = new string[integers_within_editting_scope.Count + 1];
answersAWri[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersAWri[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(answersAWri);
}
else if (editting_line_type == "Analog Write 2")
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("Analog Read"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("rint"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
if (editting_line_type.Contains("If"))
{
if (editting_line_type == "IfLeftSide") Editor_setOptions(new string[] { "Comparison" });
else Editor_setOptions(new string[] { "Finish" });
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
}
if (editting_line_type.Contains("Modify"))
{
if (editting_line_type.IndexOf("ForModify") == 0)
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Finish" });
}
else if (editting_line_type.Contains("For"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
Editor_setOptions(new string[] { "Modifier" });
}
else
{
if (editting_line_type == "ModifyString")
{
lines[editting_line] += input;
}
else lines[editting_line] += input;
Editor_setOptions(new string[] { "Finish" });
}
}
if (editting_line_type == "ForSetVariable")
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + ")";
editting_line_type = "ForSetVariableModify" + editting_variable_type;
Editor_setOptions(new string[] { "Comparison" });
}
string[] options;
if (editting_line_type == "CreateInteger" || (editting_line_type == "ForNameVariable" && editting_variable_type == "Integer"))
{
if (editting_line_type == "ForNameVariable")
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + " = )";
editting_line_type = "ForSetVariable";
integers_within_editting_scope.Add(input);
}
else
{
lines[editting_line] += input + " = ";
editting_line_type = "ModifyInteger";
}
if (integers_within_editting_scope.Count != 0)
{
options = new string[integers_within_editting_scope.Count + 1];
options[0] = "Number";
//options[1] = "Method";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
options[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(options);
}
else Editor_setOptions(new string[] { "Number" });
}
if (editting_line_type == "CreateDouble" || (editting_line_type == "ForNameVariable" && editting_variable_type == "Double"))
{
if (editting_line_type == "ForNameVariable")
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + input + " = )";
editting_line_type = "ForSetVariable";
doubles_within_editting_scope.Add(input);
}
else
{
lines[editting_line] += input + " = ";
editting_line_type = "ModifyDouble";
}
if (doubles_within_editting_scope.Count != 0)
{
options = new string[doubles_within_editting_scope.Count + 2];
options[0] = "Number";
options[1] = "Method";
for (int i = 0; i < doubles_within_editting_scope.Count; i++)
{
options[i + 2] = doubles_within_editting_scope[i];
}
Editor_setOptions(options);
}
else Editor_setOptions(new string[] { "Method", "Number" });
}
if (editting_line_type == "CreateBoolean")
{
editting_line_type = "ModifyBoolean";
lines[editting_line] += input + " = ";
if (booleans_within_editting_scope.Count != 0) Editor_setOptions(new string[] { "Variable", "True", "False" });
else Editor_setOptions(new string[] { "True", "False" });
}
if (editting_line_type == "CreateString")
{
editting_line_type = "ModifyString";
lines[editting_line] += input + " = ";
if (strings_within_editting_scope.Count != 0) Editor_setOptions(new string[] { "Variable", "String Literal" });
else Editor_setOptions(new string[] { "String Literal" });
}
// Display_pushText(lines, new int[0]);
}
public void Editor_selectOption(string selection)
{
switch (selection)
{
case "New Line":
Editor_setOptions(new string[] { "Create Variable", "Modify Variable", "Flow Control", "Method" });
if (name == "Servos")
{
Editor_setOptions(new string[] { "Create Variable", "Modify Variable", "Flow Control", "Method", "Servos" });
}
break;
case "Delete Line":
lines.RemoveAt(editting_line);
Editor_end();
break;
case "Cancel":
Editor_end();
break;
case "Flow Control":
if (editting_line_type == "") { Editor_setOptions(new string[] { "Delay","If"/*, "Else", "While", "For"*/ }); editting_line_type = selection; }
break;
case "Servos":
Editor_setOptions(new string[] { "Map" ,"servo1", "servo2" });
break;
case "servo1":
editting_line_type = selection;
lines[editting_line] = "servo1";
Editor_setOptions(new string[] { "Attach", "Write" });
break;
case "servo2":
editting_line_type = selection;
lines[editting_line] = "servo2";
Editor_setOptions(new string[] { "Attach", "Write" });
break;
case "Attach":
editting_line_type = selection;
lines[editting_line] += ".attach()";
Editor_setOptions(new string[] { "Number" });
break;
case "Write":
editting_line_type = selection;
lines[editting_line] += ".write()";
string[] answersWri = new string[integers_within_editting_scope.Count + 1];
answersWri[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersWri[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(answersWri);
break;
case "Map":
editting_line_type = selection;
lines[editting_line] += "map()";
string[] answersMap = new string[integers_within_editting_scope.Count + 1];
answersMap[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersMap[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(answersMap);
break;
case "Method":
if (editting_line_type == "")
{
//voids
editting_line_type = selection; lines[editting_line] = selection;
Editor_setOptions(new string[] { "Serial", "Pin Mode", "Digital Write", "Analog Write" });
}
else
{
if (editting_line_type == "If")
{
Editor_setOptions(new string[] {"Digital Read", "Analog Read"});
}
//numbers (iterate == temperature probe)
//Editor_setOptions(new string[] { "Math", "Iterate", });
}
if (editting_line_type.Contains("ModifyInteger"))
{
editting_line_type = selection;
Editor_setOptions(new string[] { "Digital Read", "Analog Read", "Map"});
}
break;
case "Create Variable":
editting_line_type = "CreateVariable";
Editor_setOptions(new string[] { "Integer", "Double", "Boolean", "String" });
break;
case "Modify Variable":
editting_line_type = "ModifyVariable";
if (available_variable_types.Length > 0) Editor_setOptions(available_variable_types);
else
{
UI_setColor(UIElement_EdittingMenu.transform.GetChild(1).gameObject, new Color(1, 0, 0));
print("no variables");
}
break;
case "Variable":
if (editting_line_type == "") { Editor_setOptions(available_variable_types); editting_line_type = "ModifyVariable"; }
if (editting_line_type == "Keyword") { Editor_setOptions(new string[] { "Integer", "Boolean" }); editting_line_type = "CreateVariable"; }
if (editting_line_type == "If") { Editor_setOptions(available_variable_types); editting_line_type = "IfLeftSide"; }
if (editting_line_type == "IfLeftSide") { Editor_setOptions(available_variable_types); editting_line_type = "IfLeftSide"; }
if (editting_line_type == "IfRightSide") { Editor_setOptions(available_variable_types); editting_line_type = "IfRightSide"; }
if (editting_line_type == "Print") { Editor_setOptions(available_variable_types); }
break;
case "Conditional":
if (editting_line_type == "Keyword") { editting_line_type = selection; lines[editting_line] = selection; }
Editor_setOptions(new string[] { "If", "Else" });
break;
case "Loop":
if (editting_line_type == "Keyword") editting_line_type = selection;
Editor_setOptions(new string[] { "While Loop", "For Loop" });
break;
case "Serial":
lines[editting_line] = selection;
Editor_setOptions(new string[] { "Begin", "Print", "Print Line" });
break;
case "Delay":
editting_line_type = selection;
lines[editting_line] = "delay()";
Editor_setOptions(new string[] { "Number" });
break;
case "Digital Read":
lines[editting_line] += "digitalRead()";
if (editting_line_type == "")
{
editting_line_type = selection;
Editor_setOptions(new string[] { "Number" });
}
else if (editting_line_type == "If")
{
editting_line_type = "If Digital";
Editor_setOptions(new string[] { "Number" });
}
else
{
}
break;
case "Digital Write":
editting_line_type = selection;
lines[editting_line] = "digitalWrite()";
string[] answersDW = new string[integers_within_editting_scope.Count + 1];
answersDW[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersDW[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(new string[] { "Number" });
break;
case "Analog Read":
editting_line_type = selection;
lines[editting_line] += "analogRead()";
string[] answersAR = new string[integers_within_editting_scope.Count + 1];
answersAR[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersAR[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(answersAR);
break;
case "Analog Write":
editting_line_type = selection;
lines[editting_line] = "analogWrite()";
string[] answersAW = new string[integers_within_editting_scope.Count + 1];
answersAW[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answersAW[i + 1] = integers_within_editting_scope[i];
}
Editor_setOptions(answersAW);
break;
case "Pin Mode":
editting_line_type = selection;
lines[editting_line] = "pinMode()";
string[] answers = new string[integers_within_editting_scope.Count + 1];
answers[0] = "Number";
for (int i = 0; i < integers_within_editting_scope.Count; i++)
{
answers[i+1] = integers_within_editting_scope[i];
}
Editor_setOptions(answers);
break;
case "Random Value":
if (editting_line_type.Contains("If") || editting_line_type.Contains("Print"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + "Math.random())";
}
else
{
lines[editting_line] += "Math.random()";
}
Editor_setOptions(new string[] { "Finish" });
break;
case "Number":
Editor_setOptions(new string[] { "Enter a number:" });
break;
case "String Literal":
Editor_setOptions(new string[] { "Enter a string:" });
break;
case "Integer":
if (editting_line_type == "CreateVariable") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = "int "; editting_line_type = "CreateInteger"; }
else if (editting_line_type == "For") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + "int )"; editting_line_type = "ForNameVariable"; }
else Editor_setOptions(integers_within_editting_scope.ToArray());
editting_variable_type = "Integer";
break;
case "Double":
if (editting_line_type == "CreateVariable") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = "double "; editting_line_type = "CreateDouble"; }
else if (editting_line_type == "For") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + "double )"; editting_line_type = "ForNameVariable"; }
else Editor_setOptions(doubles_within_editting_scope.ToArray());
editting_variable_type = "Double";
break;
case "Boolean":
if (editting_line_type == "CreateVariable") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = "boolean "; editting_line_type = "CreateBoolean"; }
else Editor_setOptions(booleans_within_editting_scope.ToArray());
editting_variable_type = "Boolean";
break;
case "String":
if (editting_line_type == "CreateVariable") { Editor_setOptions(new string[] { "Enter a name:" }); lines[editting_line] = "String "; editting_line_type = "CreateString"; }
else Editor_setOptions(strings_within_editting_scope.ToArray());
editting_variable_type = "String";
break;
case "True":
if (editting_line_type.Contains("If"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + "true)";
}
else lines[editting_line] += "true";
Editor_setOptions(new string[] { "Finish" });
break;
case "False":
if (editting_line_type.Contains("If"))
{
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + "false)";
}
else lines[editting_line] += "false";
Editor_setOptions(new string[] { "Finish" });
break;
case "HIGH":
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + selection + ")";
Editor_setOptions(new string[] { "Finish" });
break;
case "LOW":
lines[editting_line] = lines[editting_line].Substring(0, lines[editting_line].Length - 1) + selection + ")";
Editor_setOptions(new string[] { "Finish" });
break;