-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtoottally.gd
144 lines (135 loc) · 5.76 KB
/
toottally.gd
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
extends Button
@onready var main : Control = get_node("/root/Main")
@onready var diff_calc : Window = main.get_node("DiffCalc")
@onready var calc_contents : RichTextLabel = diff_calc.get_node("PanelContainer/VBoxContainer/PanelContainer/CalcInfo")
var info_template = """[i][font_size=24][b]{name}[/b][/font_size]\
[font_size=18] — TootTally Info[/font_size][/i]
[font_size=16]Note Hash: [b][url={"hash": "{note_hash}"}]\
[hint={note_hash}\n(Click to copy)]{short_note_hash}[/hint]\
[/url][/b]\t\t\
File Hash: [b][url={"hash": "{file_hash}"}]\
[hint={file_hash}\n(Click to copy)]{short_file_hash}[/hint]\
[/url][/b]
[/font_size]"""
var diff_template = """
[table=3]
[cell][hint='Difficulty rating estimated by TootTally's algorithm'][font_size=26]E[font_size=20]st. Diff.[/font_size] [/font_size][b]%s[/b][/hint][/cell]
[cell][/cell]
[cell][hint='TT earned at 60%% Max Percentage'][font_size=26]B[font_size=20]ase TT[/font_size] [/font_size][b]%s[/b][/hint][/cell]
[cell][left][font_size=18]T[/font_size]ap Rating\n[b]%s[/b][/left][/cell]
[cell][font_size=18]A[/font_size]im Rating\n[b]%s[/b][/cell]
[cell][right][font_size=18]A[/font_size]cc. Rating\n[b]%s[/b][/right][/cell]
[/table]
"""
var rating_checks_header = """
[font_size=25]Rating Criteria Checks[/font_size] \
[hint="View explanation on TootTally website"]\
[url=\"https://toottally.com/ratingchecks/\"][font_size=16](?)[/font_size][/url][/hint]"""
var table_header = "
[cell border=#fff padding=4,2,4,0][b]Type[/b][/cell]\
[cell border=#fff padding=4,2,4,0][b]Note ID[/b][/cell]\
[cell border=#fff padding=4,2,4,0][b]Timing[/b][/cell]\
[cell border=#fff padding=4,2,4,0][b]Value[/b][/cell][cell][/cell]"
func _on_toottally_request_completed(_result, response_code, _headers, body) -> void:
if response_code != HTTPClient.ResponseCode.RESPONSE_OK:
push_error("An error occured while submitting to TootTally: Response Code %s" % response_code)
%Alert.alert("Couldn't submit! Code %s" % response_code,
Vector2(global_position.x + 20, global_position.y - 20),
Alert.LV_ERROR, 2)
disabled = false
return
var json = JSON.new()
json.parse(body.get_string_from_utf8())
var data = json.get_data()
if data.get('error'):
calc_contents.text = "[center]\n\n\n[font_size=25]Failed to process chart![/font_size]\n\n{error}".format(data)
main.show_popup(diff_calc)
disabled = false
return
data["short_note_hash"] = data['note_hash'].left(6) + ' ... ' + data['note_hash'].right(6)
data["short_file_hash"] = data['file_hash'].left(6) + ' ... ' + data['file_hash'].right(6)
var big_whole_part = func(value:float,font_size:int=20,places:int=4) -> String:
var format_string : String = "[font_size=%s]%d[/font_size]" % [font_size,value]
format_string += str(value).substr(str(value).find('.'),places + 1)
return format_string
calc_contents.text = info_template.format(data)
calc_contents.text += (diff_template % [
big_whole_part.call(data['difficulty']),
big_whole_part.call(data['base_tt']),
big_whole_part.call(data['tap']),
big_whole_part.call(data['aim']),
big_whole_part.call(data['acc']),
])
calc_contents.text += rating_checks_header
var error_count = 0
var error_table = ""
var warn_count = 0
var warn_table = ""
for err in data["chart_errors"]:
# a bit ugly but the line is stupidly long otherwise lol
var row = "
[cell border=#fffa padding=4,2,4,0]{error_type}[/cell]\
[cell border=#fff7 padding=4,2,4,0][right]{note_id}[/right][/cell]\
[cell border=#fff7 padding=4,2,4,0]%.5f[/cell]\
[cell border=#fff7 padding=4,2,4,0]%.5f[/cell]\
[cell border=#fff8 padding=4,2,4,0][url={\"note\": {note_id}}]Jump to Note[/url][/cell]\
".format(err) % [err['timing'],err['value']]
match err["error_level"]:
"Error":
error_count += 1
error_table += row
"Warning":
warn_count += 1
warn_table += row
if error_count > 0:
calc_contents.text += \
"\n\n[color=#DE7576]{0} error/s found![/color]\n\n[indent][table=5]{1}{2}\n[/table][/indent]".format(
[error_count, table_header, error_table]
)
else:
calc_contents.text += "\n0 error/s found!"
if warn_count > 0:
calc_contents.text += \
"\n\n[color=#F5D64C]{0} warning/s found![/color]\n\n[indent][table=5]{1}{2}\n[/table][/indent]".format(
[warn_count, table_header, warn_table]
)
else:
calc_contents.text += "\n0 warnings/s found!"
if error_count == 0 and warn_count == 0:
calc_contents.text += "\n\n[center][rainbow sat=0.6][wave]Maximum Boner Levels Achieved"
%Chart.assign_tt_note_ids()
main.show_popup(diff_calc)
disabled = false
func _on_toottally_upload_pressed() -> void:
disabled = true
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(_on_toottally_request_completed)
var tmb_data = main.tmb.to_dict()
var errors = []
for key in tmb_data.keys():
if tmb_data[key] is String and not tmb_data[key]:
errors.append("Field [code]%s[/code] is empty!" % key)
elif tmb_data[key] is int and key not in ["UNK1", "year"] and tmb_data[key] < 1:
errors.append("Invaid value for [code]%s[/code]!" % key)
elif key == "notes" and not tmb_data[key]:
errors.append("There are no notes to process!")
if errors:
calc_contents.text = "[center]\n\n\n[font_size=25]Failed to process chart![/font_size]\n\n"
for e in errors:
calc_contents.text += "\n" + e
main.show_popup(diff_calc)
disabled = false
return
var chart_data = JSON.stringify(tmb_data)
var dict = {"tmb": chart_data, "skip_save": true}
var body = JSON.stringify(dict)
var error = http_request.request(
"https://toottally.com/api/upload/",
["Content-Type: application/json"],
HTTPClient.METHOD_POST, body)
if error != OK:
push_error("An error occured while submitting to TootTally: " + error)
%Alert.alert("Couldn't submit! " + error,
Vector2(global_position.x + 20, global_position.y - 20),
Alert.LV_ERROR, 2)