123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- extends Control
- var _textEdit;
- var Code;
- var _httpEntry = HTTPRequest.new();
- var _httpButton = HTTPRequest.new();
- var _httpLocation = HTTPRequest.new();
- var _delivery;
- var _editX;
- var _editY;
- var _currentOrderId;
- var _delivering;
- var TT = Timer.new();
- func FuckYou():
- _delivering.Hide();
-
- func FuckYou2(s: String):
- if s.length() == 4:
- var req = "https://nairobi.ninja/bagel/verify/" + s
- _httpEntry.request(req)
- func _ready():
- add_child(_httpButton);
- add_child(_httpEntry);
- add_child(_httpLocation);
- _httpButton.request_completed.connect(OnRequestCompletedButton);
- _httpEntry.request_completed.connect(OnRequestCompletedEntry);
- _httpLocation.request_completed.connect(OnRequestCompletedLoc);
- _httpButton.set_timeout(2.0)
- _httpEntry.set_timeout(2.0)
- _httpLocation.set_timeout(2.0)
- _delivery = find_child("Delivery");
- _editX = find_child("LineEditE");
- _editY = find_child("LineEditS");
- _textEdit = find_child("EnterCode");
- _delivering = $"Delivering";
- TT.wait_time = 5.0;
- TT.oneshot = true;
- TT.timeout.connect(FuckYou)
- add_child(TT);
-
- Code = "";
- _textEdit.text_changed.connect(FuckYou2);
- # foreach(Node bagelnode in GetTree().GetNodesInGroup("bagelbutton")) {
- # Button bagelbutton = (Button)bagelnode;
- # int id = bagelbutton.GetMeta("bagelid").As<int>();
- # bagelbutton.Pressed += () => {
- # if (Code.Length == 4) {
- # _currentOrderId = id;
- # _delivery.Show();
- # }
- # };
- # }
- #
- # ((Button)FindChild("SendBB")).Pressed += () => {
- # if(_editX.Text.Length > 0 && _editY.Text.Length > 0) {
- # String req = "https://nairobi.ninja/bagel/order/" + Code + "/" + _currentOrderId + "/" + _editX.Text + "/" + _editY.Text;
- # GD.Print(req);
- # foreach(Node bagelnode in GetTree().GetNodesInGroup("bagelbutton")) {
- # Button bagelbutton = (Button)bagelnode;
- # bagelbutton.Disabled = true;
- # }
- # _httpButton.Request(req);
- # _delivery.Hide();
- # }
- # };
- #
- # (GetNode<Timer>("PosSpyTimer")).Timeout += () => {
- # if (Code.Length == 4) {
- # String req = "https://nairobi.ninja/bagel/getpos/" + Code;
- # _httpLocation.Request(req);
- # }
- # };
- func _input(ev: InputEvent):
- if ev.IsActionReleased("esc"):
- Code = "";
- $"OtherScreen".show();
- $"MainScreen".hide();
- $"PosSpy".hide();
- func OnRequestCompletedLoc(result, responseCode, headers, body):
- var j = JSON.new();
- var e = j.parse(body);
- if e == OK:
- pass
- # var x
- # var y
- # j.Data.AsGodotDictionary().TryGetValue("x", out x);
- # j.Data.AsGodotDictionary().TryGetValue("y", out y);
- # var xx = x.As<float>();
- # var yy = y.As<float>();
- # if(xx >= 0.0f || yy >= 0.0f) {
- # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Your location: (" + yy.ToString("0.000") + "°S, " + xx.ToString("0.000") + "°E)[/center]";
- # } else {
- # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Your location: unreachable[/center]";
- # }
- # } else {
- # GetNode<RichTextLabel>("PosSpy/RichTextLabel").Text = "[center]Connection lost[/center]";
- # }
- func OnRequestCompletedEntry(result, responseCode, headers, body):
- pass
- # var res = System.Text.Encoding.UTF8.GetString(body);
- # if(responseCode == 200 && res.Length == 4) {
- # Code = res;
- # _textEdit.Text = "";
- # GetNode<Control>("OtherScreen").Hide();
- # GetNode<Control>("MainScreen").Show();
- # GetNode<Control>("PosSpy").Show();
- # } else if(responseCode == 404) {
- # _textEdit.Text = "";
- # _textEdit.PlaceholderText = "Invalid code";
- # else:
- # _textEdit.Text = "";
- # _textEdit.PlaceholderText = "Server unreachable";
- func OnRequestCompletedButton(result, responseCode, headers, body):
- if responseCode == 200:
- for bagelnode in get_tree().get_nodes_in_group("bagelbutton"):
- bagelnode.disabled = false;
- _delivering.show();
- TT.start();
- else:
- $"OtherScreen".show();
- $"MainScreen".hide();
- $"PosSpy".hide();
- Code = "";
- _textEdit.placeholder_text = "Server unreachable";
|