Bagelicious.gd 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. extends Control
  2. var _textEdit;
  3. var Code;
  4. var _httpEntry = HTTPRequest.new();
  5. var _httpButton = HTTPRequest.new();
  6. var _httpLocation = HTTPRequest.new();
  7. var _delivery;
  8. var _editX;
  9. var _editY;
  10. var _currentOrderId;
  11. var _delivering;
  12. var TT = Timer.new();
  13. func FuckYou():
  14. _delivering.Hide();
  15. func FuckYou2(s: String):
  16. if s.length() == 4:
  17. var req = "https://nairobi.ninja/bagel/verify/" + s
  18. _httpEntry.request(req)
  19. func _ready():
  20. add_child(_httpButton);
  21. add_child(_httpEntry);
  22. add_child(_httpLocation);
  23. _httpButton.request_completed.connect(OnRequestCompletedButton);
  24. _httpEntry.request_completed.connect(OnRequestCompletedEntry);
  25. _httpLocation.request_completed.connect(OnRequestCompletedLoc);
  26. _httpButton.set_timeout(2.0)
  27. _httpEntry.set_timeout(2.0)
  28. _httpLocation.set_timeout(2.0)
  29. _delivery = find_child("Delivery");
  30. _editX = find_child("LineEditE");
  31. _editY = find_child("LineEditS");
  32. _textEdit = find_child("EnterCode");
  33. _delivering = $"Delivering";
  34. TT.wait_time = 5.0;
  35. TT.oneshot = true;
  36. TT.timeout.connect(FuckYou)
  37. add_child(TT);
  38. Code = "";
  39. _textEdit.text_changed.connect(FuckYou2);
  40. # foreach(Node bagelnode in GetTree().GetNodesInGroup("bagelbutton")) {
  41. # Button bagelbutton = (Button)bagelnode;
  42. # int id = bagelbutton.GetMeta("bagelid").As<int>();
  43. # bagelbutton.Pressed += () => {
  44. # if (Code.Length == 4) {
  45. # _currentOrderId = id;
  46. # _delivery.Show();
  47. # }
  48. # };
  49. # }
  50. #
  51. # ((Button)FindChild("SendBB")).Pressed += () => {
  52. # if(_editX.Text.Length > 0 && _editY.Text.Length > 0) {
  53. # String req = "https://nairobi.ninja/bagel/order/" + Code + "/" + _currentOrderId + "/" + _editX.Text + "/" + _editY.Text;
  54. # GD.Print(req);
  55. # foreach(Node bagelnode in GetTree().GetNodesInGroup("bagelbutton")) {
  56. # Button bagelbutton = (Button)bagelnode;
  57. # bagelbutton.Disabled = true;
  58. # }
  59. # _httpButton.Request(req);
  60. # _delivery.Hide();
  61. # }
  62. # };
  63. #
  64. # (GetNode<Timer>("PosSpyTimer")).Timeout += () => {
  65. # if (Code.Length == 4) {
  66. # String req = "https://nairobi.ninja/bagel/getpos/" + Code;
  67. # _httpLocation.Request(req);
  68. # }
  69. # };
  70. func _input(ev: InputEvent):
  71. if ev.IsActionReleased("esc"):
  72. Code = "";
  73. $"OtherScreen".show();
  74. $"MainScreen".hide();
  75. $"PosSpy".hide();
  76. func OnRequestCompletedLoc(result, responseCode, headers, body):
  77. var j = JSON.new();
  78. var e = j.parse(body);
  79. if e == OK:
  80. pass
  81. # var x
  82. # var y
  83. # j.Data.AsGodotDictionary().TryGetValue("x", out x);
  84. # j.Data.AsGodotDictionary().TryGetValue("y", out y);
  85. # var xx = x.As<float>();
  86. # var yy = y.As<float>();
  87. # if(xx >= 0.0f || yy >= 0.0f) {
  88. # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Your location: (" + yy.ToString("0.000") + "°S, " + xx.ToString("0.000") + "°E)[/center]";
  89. # } else {
  90. # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Your location: unreachable[/center]";
  91. # }
  92. # } else {
  93. # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Connection lost[/center]";
  94. # }
  95. func OnRequestCompletedEntry(result, responseCode, headers, body):
  96. pass
  97. # var res = System.Text.Encoding.UTF8.GetString(body);
  98. # if(responseCode == 200 && res.Length == 4) {
  99. # Code = res;
  100. # _textEdit.Text = "";
  101. # GetNode<Control>("OtherScreen").Hide();
  102. # GetNode<Control>("MainScreen").Show();
  103. # GetNode<Control>("PosSpy").Show();
  104. # } else if(responseCode == 404) {
  105. # _textEdit.Text = "";
  106. # _textEdit.PlaceholderText = "Invalid code";
  107. # else:
  108. # _textEdit.Text = "";
  109. # _textEdit.PlaceholderText = "Server unreachable";
  110. func OnRequestCompletedButton(result, responseCode, headers, body):
  111. if responseCode == 200:
  112. for bagelnode in get_tree().get_nodes_in_group("bagelbutton"):
  113. bagelnode.disabled = false;
  114. _delivering.show();
  115. TT.start();
  116. else:
  117. $"OtherScreen".show();
  118. $"MainScreen".hide();
  119. $"PosSpy".hide();
  120. Code = "";
  121. _textEdit.placeholder_text = "Server unreachable";