|
1
|
|
|
from threading import Thread |
|
2
|
|
|
import obspython as obs |
|
3
|
|
|
import racetime_client |
|
4
|
|
|
from rtgg_obs import RacetimeObs |
|
5
|
|
|
|
|
6
|
|
|
rtgg_obs = RacetimeObs() |
|
7
|
|
|
|
|
8
|
|
|
def script_description(): |
|
9
|
|
|
return "<center><p>Select a text source to use as your timer and enter your full " + \ |
|
10
|
|
|
"username on racetime.gg (including discriminator). This only needs " + \ |
|
11
|
|
|
"to be done once.\n\nThen select the race room each race you join and " + \ |
|
12
|
|
|
"stop worrying about whether you started your timer or not.<hr/></p>" |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
def script_load(settings): |
|
16
|
|
|
rtgg_obs.timer.use_podium_colors = obs.obs_data_get_bool(settings, "use_podium") |
|
17
|
|
|
|
|
18
|
|
|
race_update_t = Thread(target=rtgg_obs.race_update_thread) |
|
19
|
|
|
race_update_t.daemon = True |
|
20
|
|
|
race_update_t.start() |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def script_save(settings): |
|
24
|
|
|
obs.obs_data_set_bool(settings, "use_podium", rtgg_obs.timer.use_podium_colors) |
|
25
|
|
|
|
|
26
|
|
|
def script_update(settings): |
|
27
|
|
|
script_update_setup_settings(settings) |
|
28
|
|
|
script_update_timer_settings(settings) |
|
29
|
|
|
script_update_coop_settings(settings) |
|
30
|
|
|
script_update_qualifier_settings(settings) |
|
31
|
|
|
|
|
32
|
|
|
def script_update_qualifier_settings(settings): |
|
33
|
|
|
rtgg_obs.qualifier.enabled = obs.obs_data_get_bool(settings, "use_qualifier") |
|
34
|
|
|
rtgg_obs.qualifier.qualifier_cutoff = obs.obs_data_get_int(settings, "qualifier_cutoff") |
|
35
|
|
|
rtgg_obs.logger.debug(f"qualifier_cutoff is {rtgg_obs.qualifier.qualifier_cutoff}") |
|
36
|
|
|
rtgg_obs.qualifier.qualifier_par_source = obs.obs_data_get_string( |
|
37
|
|
|
settings, "qualifier_par_source") |
|
38
|
|
|
rtgg_obs.qualifier.qualifier_score_source = obs.obs_data_get_string( |
|
39
|
|
|
settings, "qualifier_score_source") |
|
40
|
|
|
|
|
41
|
|
|
def script_update_coop_settings(settings): |
|
42
|
|
|
rtgg_obs.coop.enabled = obs.obs_data_get_bool(settings, "use_coop") |
|
43
|
|
|
rtgg_obs.coop.partner = obs.obs_data_get_string(settings, "coop_partner") |
|
44
|
|
|
rtgg_obs.coop.opponent1 = obs.obs_data_get_string(settings, "coop_opponent1") |
|
45
|
|
|
rtgg_obs.coop.opponent2 = obs.obs_data_get_string(settings, "coop_opponent2") |
|
46
|
|
|
rtgg_obs.coop.source_name = obs.obs_data_get_string(settings, "coop_source") |
|
47
|
|
|
rtgg_obs.coop.label_source_name = obs.obs_data_get_string(settings, "coop_label") |
|
48
|
|
|
|
|
49
|
|
|
def script_update_timer_settings(settings): |
|
50
|
|
|
obs.timer_remove(rtgg_obs.update_sources) |
|
51
|
|
|
|
|
52
|
|
|
rtgg_obs.timer.use_podium_colors = obs.obs_data_get_bool(settings, "use_podium") |
|
53
|
|
|
rtgg_obs.timer.pre_color = obs.obs_data_get_int(settings, "pre_color") |
|
54
|
|
|
rtgg_obs.timer.first_color = obs.obs_data_get_int(settings, "first_color") |
|
55
|
|
|
rtgg_obs.timer.second_color = obs.obs_data_get_int(settings, "second_color") |
|
56
|
|
|
rtgg_obs.timer.third_color = obs.obs_data_get_int(settings, "third_color") |
|
57
|
|
|
rtgg_obs.timer.racing_color = obs.obs_data_get_int(settings, "racing_color") |
|
58
|
|
|
rtgg_obs.timer.finished_color = obs.obs_data_get_int(settings, "finished_color") |
|
59
|
|
|
|
|
60
|
|
|
if rtgg_obs.timer.source_name != "" and rtgg_obs.selected_race != "": |
|
61
|
|
|
obs.timer_add(rtgg_obs.update_sources, 100) |
|
62
|
|
|
rtgg_obs.timer.enabled = True |
|
63
|
|
|
else: |
|
64
|
|
|
rtgg_obs.timer.enabled = False |
|
65
|
|
|
rtgg_obs.logger.debug(f"timer.enabled is {rtgg_obs.timer.enabled}") |
|
66
|
|
|
rtgg_obs.logger.debug(f"timer.source_name is {rtgg_obs.timer.source_name}") |
|
67
|
|
|
rtgg_obs.logger.debug(f"selected_race is {rtgg_obs.selected_race}") |
|
68
|
|
|
|
|
69
|
|
|
def script_update_setup_settings(settings): |
|
70
|
|
|
rtgg_obs.update_logger(obs.obs_data_get_bool(settings, "enable_log"), |
|
71
|
|
|
obs.obs_data_get_bool(settings, "log_to_file"), |
|
72
|
|
|
obs.obs_data_get_string(settings, "log_file"), |
|
73
|
|
|
obs.obs_data_get_string(settings, "log_level")) |
|
74
|
|
|
|
|
75
|
|
|
rtgg_obs.full_name = obs.obs_data_get_string(settings, "username") |
|
76
|
|
|
|
|
77
|
|
|
rtgg_obs.timer.source_name = obs.obs_data_get_string(settings, "source") |
|
78
|
|
|
|
|
79
|
|
|
rtgg_obs.selected_race = obs.obs_data_get_string(settings, "race") |
|
80
|
|
|
rtgg_obs.category = obs.obs_data_get_string(settings, "category_filter") |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
def script_defaults(settings): |
|
84
|
|
|
obs.obs_data_set_default_string(settings, "race_info", "Race info") |
|
85
|
|
|
obs.obs_data_set_default_string(settings, "race", "") |
|
86
|
|
|
|
|
87
|
|
|
def script_properties(): |
|
88
|
|
|
props = obs.obs_properties_create() |
|
89
|
|
|
script_setup(props) |
|
90
|
|
|
script_timer_settings(props) |
|
91
|
|
|
script_coop_settings(props) |
|
92
|
|
|
script_qualifier_settings(props) |
|
93
|
|
|
|
|
94
|
|
|
return props |
|
95
|
|
|
|
|
96
|
|
|
def script_qualifier_settings(props): |
|
97
|
|
|
p = obs.obs_properties_add_bool( |
|
98
|
|
|
props, "use_qualifier", "Display race results as tournament qualifier?") |
|
99
|
|
|
obs.obs_property_set_modified_callback(p, qualifier_toggled) |
|
100
|
|
|
qualifier_group = obs.obs_properties_create() |
|
101
|
|
|
obs.obs_properties_add_group( |
|
102
|
|
|
props, "qualifier_group", "Qualifier Mode", obs.OBS_GROUP_NORMAL, qualifier_group) |
|
103
|
|
|
obs.obs_property_set_visible( |
|
104
|
|
|
obs.obs_properties_get(props, "qualifier_group"), rtgg_obs.qualifier.enabled) |
|
105
|
|
|
p = obs.obs_properties_add_int_slider( |
|
106
|
|
|
qualifier_group, "qualifier_cutoff", "Use Top X as par time, where X=", 3, 10, 1) |
|
107
|
|
|
p = obs.obs_properties_add_list(qualifier_group, "qualifier_par_source", |
|
108
|
|
|
"Qualifier Par Time Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) |
|
109
|
|
|
rtgg_obs.fill_source_list(p) |
|
110
|
|
|
p = obs.obs_properties_add_list(qualifier_group, "qualifier_score_source", |
|
111
|
|
|
"Qualifier Score Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) |
|
112
|
|
|
rtgg_obs.fill_source_list(p) |
|
113
|
|
|
|
|
114
|
|
|
def script_coop_settings(props): |
|
115
|
|
|
p = obs.obs_properties_add_bool( |
|
116
|
|
|
props, "use_coop", "Display coop information?") |
|
117
|
|
|
obs.obs_property_set_modified_callback(p, coop_toggled) |
|
118
|
|
|
coop_group = obs.obs_properties_create() |
|
119
|
|
|
obs.obs_properties_add_group( |
|
120
|
|
|
props, "coop_group", "Co-op Mode", obs.OBS_GROUP_NORMAL, coop_group) |
|
121
|
|
|
obs.obs_property_set_visible( |
|
122
|
|
|
obs.obs_properties_get(props, "coop_group"), rtgg_obs.coop.enabled) |
|
123
|
|
|
p = obs.obs_properties_add_list( |
|
124
|
|
|
coop_group, "coop_partner", "Co-op Partner", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
125
|
|
|
p = obs.obs_properties_add_list( |
|
126
|
|
|
coop_group, "coop_opponent1", "Co-op Opponent 1", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
127
|
|
|
p = obs.obs_properties_add_list( |
|
128
|
|
|
coop_group, "coop_opponent2", "Co-op Opponent 2", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
129
|
|
|
rtgg_obs.fill_coop_entrant_lists(props) |
|
130
|
|
|
p = obs.obs_properties_add_list(coop_group, "coop_source", "Coop Text Source", |
|
131
|
|
|
obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) |
|
132
|
|
|
obs.obs_property_set_long_description( |
|
133
|
|
|
p, "This text source will display the time that the last racer needs to finish for their team to win") |
|
134
|
|
|
rtgg_obs.fill_source_list(p) |
|
135
|
|
|
p = obs.obs_properties_add_list(coop_group, "coop_label", "Coop Label Text Source", |
|
136
|
|
|
obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) |
|
137
|
|
|
obs.obs_property_set_long_description( |
|
138
|
|
|
p, "This text source will be use to display a label such as \'<PartnerName> needs to finish before\' based on who the last racer is") |
|
139
|
|
|
rtgg_obs.fill_source_list(p) |
|
140
|
|
|
|
|
141
|
|
|
def script_timer_settings(props): |
|
142
|
|
|
p = obs.obs_properties_add_bool(props, "use_podium", "Use custom color for podium finishes?") |
|
143
|
|
|
obs.obs_property_set_modified_callback(p, podium_toggled) |
|
144
|
|
|
podium_group = obs.obs_properties_create() |
|
145
|
|
|
obs.obs_properties_add_group( |
|
146
|
|
|
props, "podium_group", "Podium Colors", obs.OBS_GROUP_NORMAL, podium_group) |
|
147
|
|
|
obs.obs_property_set_visible(obs.obs_properties_get( |
|
148
|
|
|
props, "podium_group"), rtgg_obs.timer.use_podium_colors) |
|
149
|
|
|
obs.obs_properties_add_color(podium_group, "pre_color", "Pre-race:") |
|
150
|
|
|
obs.obs_properties_add_color(podium_group, "racing_color", "Still racing:") |
|
151
|
|
|
obs.obs_properties_add_color(podium_group, "first_color", "1st place:") |
|
152
|
|
|
obs.obs_properties_add_color(podium_group, "second_color", "2nd place:") |
|
153
|
|
|
obs.obs_properties_add_color(podium_group, "third_color", "3rd place:") |
|
154
|
|
|
obs.obs_properties_add_color( |
|
155
|
|
|
podium_group, "finished_color", "After podium:") |
|
156
|
|
|
|
|
157
|
|
|
def script_setup(props): |
|
158
|
|
|
setup_group = obs.obs_properties_create() |
|
159
|
|
|
obs.obs_properties_add_group( |
|
160
|
|
|
props, "initial_setup", "Initial setup - Check to make changes", obs.OBS_GROUP_CHECKABLE, setup_group) |
|
161
|
|
|
p = obs.obs_properties_add_list( |
|
162
|
|
|
setup_group, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) |
|
163
|
|
|
rtgg_obs.fill_source_list(p) |
|
164
|
|
|
obs.obs_properties_add_text( |
|
165
|
|
|
setup_group, "username", "Username", obs.OBS_TEXT_DEFAULT) |
|
166
|
|
|
logging = obs.obs_properties_add_bool( |
|
167
|
|
|
setup_group, "enable_log", "Enable logging") |
|
168
|
|
|
log_levels = obs.obs_properties_add_list( |
|
169
|
|
|
setup_group, "log_level", "Log lever", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
170
|
|
|
obs.obs_property_list_add_string(log_levels, "Error", "Error") |
|
171
|
|
|
obs.obs_property_list_add_string(log_levels, "Debug", "Debug") |
|
172
|
|
|
obs.obs_property_list_add_string(log_levels, "Info", "Info") |
|
173
|
|
|
obs.obs_property_set_long_description( |
|
174
|
|
|
logging, "Generally, only log errors unless you are developing or are trying to find a specific problem.") |
|
175
|
|
|
obs.obs_properties_add_bool(setup_group, "log_to_file", "Log to file?") |
|
176
|
|
|
category_list = obs.obs_properties_add_list( |
|
177
|
|
|
props, "category_filter", "Filter by Category", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
178
|
|
|
race_list = obs.obs_properties_add_list( |
|
179
|
|
|
props, "race", "Race", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING) |
|
180
|
|
|
obs.obs_property_set_modified_callback(race_list, new_race_selected) |
|
181
|
|
|
obs.obs_property_set_modified_callback( |
|
182
|
|
|
category_list, new_category_selected) |
|
183
|
|
|
|
|
184
|
|
|
p = obs.obs_properties_add_text( |
|
185
|
|
|
props, "race_info", "Race Desc", obs.OBS_TEXT_MULTILINE) |
|
186
|
|
|
obs.obs_property_set_enabled(p, False) |
|
187
|
|
|
|
|
188
|
|
|
refresh = obs.obs_properties_add_button( |
|
189
|
|
|
props, "button", "Refresh", lambda *props: None) |
|
190
|
|
|
obs.obs_property_set_modified_callback(refresh, refresh_pressed) |
|
191
|
|
|
|
|
192
|
|
|
def refresh_pressed(props, prop, *args, **kwargs): |
|
193
|
|
|
rtgg_obs.fill_source_list(obs.obs_properties_get(props, "source")) |
|
194
|
|
|
rtgg_obs.fill_source_list(obs.obs_properties_get(props, "coop_label")) |
|
195
|
|
|
rtgg_obs.fill_source_list(obs.obs_properties_get(props, "coop_text")) |
|
196
|
|
|
rtgg_obs.fill_source_list(obs.obs_properties_get(props, "qualifier_par_source")) |
|
197
|
|
|
rtgg_obs.fill_source_list(obs.obs_properties_get(props, "qualifier_score_source")) |
|
198
|
|
|
rtgg_obs.fill_race_list(obs.obs_properties_get(props, "race"), |
|
199
|
|
|
obs.obs_properties_get(props, "category_filter")) |
|
200
|
|
|
if rtgg_obs.race is not None: |
|
201
|
|
|
rtgg_obs.coop.update_coop_text(rtgg_obs.race, rtgg_obs.full_name) |
|
202
|
|
|
rtgg_obs.qualifier.update_qualifier_text(rtgg_obs.race, rtgg_obs.full_name) |
|
203
|
|
|
return True |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
def new_race_selected(props, prop, settings): |
|
207
|
|
|
rtgg_obs.selected_race = obs.obs_data_get_string(settings, "race") |
|
208
|
|
|
r = racetime_client.get_race(rtgg_obs.selected_race) |
|
209
|
|
|
if r is not None: |
|
210
|
|
|
rtgg_obs.race = r |
|
211
|
|
|
rtgg_obs.coop.update_coop_text(rtgg_obs.race, rtgg_obs.full_name) |
|
212
|
|
|
rtgg_obs.qualifier.update_qualifier_text(rtgg_obs.race, rtgg_obs.full_name) |
|
213
|
|
|
rtgg_obs.logger.info(f"new race selected: {rtgg_obs.race}") |
|
214
|
|
|
obs.obs_data_set_default_string(settings, "race_info", r.info) |
|
215
|
|
|
rtgg_obs.fill_coop_entrant_lists(props) |
|
216
|
|
|
else: |
|
217
|
|
|
obs.obs_data_set_default_string( |
|
218
|
|
|
settings, "race_info", "Race not found") |
|
219
|
|
|
|
|
220
|
|
|
rtgg_obs.race_changed = True |
|
221
|
|
|
return True |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
def new_category_selected(props, prop, settings): |
|
225
|
|
|
rtgg_obs.category = obs.obs_data_get_string(settings, "category_filter") |
|
226
|
|
|
rtgg_obs.logger.info(f"new category selected: {rtgg_obs.category}") |
|
227
|
|
|
rtgg_obs.fill_race_list(obs.obs_properties_get(props, "race"), prop) |
|
228
|
|
|
return True |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
def podium_toggled(props, prop, settings): |
|
232
|
|
|
vis = obs.obs_data_get_bool(settings, "use_podium") |
|
233
|
|
|
obs.obs_property_set_visible( |
|
234
|
|
|
obs.obs_properties_get(props, "podium_group"), vis) |
|
235
|
|
|
return True |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
def coop_toggled(props, prop, settings): |
|
239
|
|
|
vis = obs.obs_data_get_bool(settings, "use_coop") |
|
240
|
|
|
obs.obs_property_set_visible( |
|
241
|
|
|
obs.obs_properties_get(props, "coop_group"), vis) |
|
242
|
|
|
return True |
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
def qualifier_toggled(props, prop, settings): |
|
246
|
|
|
vis = obs.obs_data_get_bool(settings, "use_qualifier") |
|
247
|
|
|
obs.obs_property_set_visible( |
|
248
|
|
|
obs.obs_properties_get(props, "qualifier_group"), vis) |
|
249
|
|
|
return True |
|
250
|
|
|
|