|
1
|
|
|
from threading import Thread |
|
2
|
|
|
from gadgets.ladder_timer import LadderTimer |
|
3
|
|
|
|
|
4
|
|
|
import obspython as obs |
|
5
|
|
|
import clients.racetime_client as racetime_client |
|
6
|
|
|
import scripting.coop_scripting as coop_scripting |
|
7
|
|
|
import scripting.media_player_scripting as media_player_scripting |
|
8
|
|
|
import scripting.qualifier_scripting as qualifier_scripting |
|
9
|
|
|
import scripting.setup_scripting as setup_scripting |
|
10
|
|
|
import scripting.timer_scripting as timer_scripting |
|
11
|
|
|
import scripting.ladder_scripting as ladder_scripting |
|
12
|
|
|
from rtgg_obs import RacetimeObs |
|
13
|
|
|
from scripting import fill_race_list, fill_source_list, set_source_text |
|
14
|
|
|
from scripting import ScriptProperties as sp |
|
15
|
|
|
|
|
16
|
|
|
rtgg_obs = RacetimeObs() |
|
17
|
|
|
ladder_timer = LadderTimer(rtgg_obs.logger) |
|
18
|
|
|
ladder_scripting.ladder_timer = ladder_timer |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def script_description(): |
|
22
|
|
|
return ( |
|
23
|
|
|
"<center>racetime-obs xxVERSIONxx<hr>" |
|
24
|
|
|
"<p>Select a text source to use as your timer and enter your" |
|
25
|
|
|
"full username on racetime.gg (including discriminator). This only" |
|
26
|
|
|
"needs to be done once.\n\nThen select the race room each race you " |
|
27
|
|
|
"join and stop worrying about whether you started your timer or not." |
|
28
|
|
|
"<hr/></p>" |
|
29
|
|
|
) |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def script_load(settings): |
|
33
|
|
|
obs.obs_frontend_add_event_callback(on_load) |
|
34
|
|
|
|
|
35
|
|
|
rtgg_obs.timer.use_podium_colors = obs.obs_data_get_bool( |
|
36
|
|
|
settings, "use_podium") |
|
37
|
|
|
|
|
38
|
|
|
rtgg_obs.media_player.last_session_race = obs.obs_data_get_string( |
|
39
|
|
|
settings, "last_session_race") |
|
40
|
|
|
|
|
41
|
|
|
obs.obs_data_set_string(settings, "race", sp.none_races) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def on_load(event): |
|
45
|
|
|
if event == obs.OBS_FRONTEND_EVENT_FINISHED_LOADING: |
|
46
|
|
|
race_update_t = Thread(target=rtgg_obs.race_update_thread) |
|
47
|
|
|
race_update_t.daemon = True |
|
48
|
|
|
race_update_t.start() |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
def script_save(settings): |
|
52
|
|
|
obs.obs_data_set_bool(settings, "use_podium", |
|
53
|
|
|
rtgg_obs.timer.use_podium_colors) |
|
54
|
|
|
obs.obs_data_set_string( |
|
55
|
|
|
settings, "last_session_race", rtgg_obs.selected_race) |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
def script_update(settings): |
|
59
|
|
|
setup_scripting.script_update_setup_settings(settings, rtgg_obs) |
|
60
|
|
|
timer_scripting.script_update_timer_settings( |
|
61
|
|
|
settings, rtgg_obs, update_sources |
|
62
|
|
|
) |
|
63
|
|
|
coop_scripting.script_update_coop_settings(settings, rtgg_obs) |
|
64
|
|
|
qualifier_scripting.script_update_qualifier_settings(settings, rtgg_obs) |
|
65
|
|
|
media_player_scripting.script_update_media_player_settings( |
|
66
|
|
|
settings, rtgg_obs |
|
67
|
|
|
) |
|
68
|
|
|
ladder_scripting.script_update_ladder_settings(settings) |
|
69
|
|
|
|
|
70
|
|
|
rtgg_obs.full_name = obs.obs_data_get_string(settings, "username") |
|
71
|
|
|
|
|
72
|
|
|
rtgg_obs.timer.source_name = obs.obs_data_get_string(settings, "source") |
|
73
|
|
|
|
|
74
|
|
|
rtgg_obs.selected_race = obs.obs_data_get_string(settings, "race") |
|
75
|
|
|
rtgg_obs.category = obs.obs_data_get_string(settings, "category_filter") |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
def script_defaults(settings): |
|
79
|
|
|
obs.obs_data_set_default_string(settings, "race_info", "Race info") |
|
80
|
|
|
obs.obs_data_set_default_string(settings, "race", "None") |
|
81
|
|
|
obs.obs_data_set_default_int(settings, "qualifier_cutoff", 3) |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
def script_properties(): |
|
85
|
|
|
props = obs.obs_properties_create() |
|
86
|
|
|
setup_scripting.script_setup( |
|
87
|
|
|
props, new_race_selected, new_category_selected |
|
88
|
|
|
) |
|
89
|
|
|
|
|
90
|
|
|
refresh = obs.obs_properties_add_button( |
|
91
|
|
|
props, "button", "Refresh", lambda *props: None) |
|
92
|
|
|
obs.obs_property_set_modified_callback(refresh, refresh_pressed) |
|
93
|
|
|
timer_scripting.script_timer_settings(props, rtgg_obs,) |
|
94
|
|
|
coop_scripting.script_coop_settings(props, rtgg_obs) |
|
95
|
|
|
qualifier_scripting.script_qualifier_settings(props, rtgg_obs) |
|
96
|
|
|
media_player_scripting.script_media_player_settings( |
|
97
|
|
|
props, rtgg_obs, media_player_toggled |
|
98
|
|
|
) |
|
99
|
|
|
ladder_scripting.script_ladder_settings(props) |
|
100
|
|
|
|
|
101
|
|
|
return props |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
def refresh_pressed(props, prop, *args, **kwargs): |
|
105
|
|
|
fill_source_list(obs.obs_properties_get(props, "source")) |
|
106
|
|
|
fill_source_list(obs.obs_properties_get(props, "coop_our_source")) |
|
107
|
|
|
fill_source_list(obs.obs_properties_get(props, "coop_opponent_source")) |
|
108
|
|
|
fill_source_list(obs.obs_properties_get(props, "qualifier_par_source")) |
|
109
|
|
|
fill_source_list(obs.obs_properties_get(props, "qualifier_score_source")) |
|
110
|
|
|
fill_race_list(rtgg_obs, obs.obs_properties_get(props, "race"), |
|
111
|
|
|
obs.obs_properties_get(props, "category_filter")) |
|
112
|
|
|
coop_scripting.fill_coop_entrant_lists(props, rtgg_obs) |
|
113
|
|
|
if rtgg_obs.race is not None: |
|
114
|
|
|
rtgg_obs.coop.update_coop_text(rtgg_obs.race, rtgg_obs.full_name) |
|
115
|
|
|
update_coop_sources() |
|
116
|
|
|
rtgg_obs.qualifier.update_qualifier_text( |
|
117
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
118
|
|
|
rtgg_obs.media_player.race_updated( |
|
119
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
120
|
|
|
return True |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
def new_race_selected(props, prop, settings): |
|
124
|
|
|
rtgg_obs.race_changed = True |
|
125
|
|
|
obs.timer_remove(update_sources) |
|
126
|
|
|
|
|
127
|
|
|
rtgg_obs.selected_race = obs.obs_data_get_string(settings, "race") |
|
128
|
|
|
if rtgg_obs.selected_race == sp.none_races: |
|
129
|
|
|
rtgg_obs.race = None |
|
130
|
|
|
if rtgg_obs.selected_race == sp.alttpr_ladder: |
|
131
|
|
|
rtgg_obs.race = None |
|
132
|
|
|
ladder_timer.enabled = True |
|
133
|
|
|
else: |
|
134
|
|
|
ladder_timer.enabled = False |
|
135
|
|
|
r = racetime_client.get_race_by_name(rtgg_obs.selected_race) |
|
136
|
|
|
if r is not None: |
|
137
|
|
|
rtgg_obs.race = r |
|
138
|
|
|
rtgg_obs.coop.update_coop_text(rtgg_obs.race, rtgg_obs.full_name) |
|
139
|
|
|
rtgg_obs.qualifier.update_qualifier_text( |
|
140
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
141
|
|
|
rtgg_obs.media_player.race_updated( |
|
142
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
143
|
|
|
rtgg_obs.logger.info(f"new race selected: {rtgg_obs.race}") |
|
144
|
|
|
obs.obs_data_set_default_string(settings, "race_info", r.info) |
|
145
|
|
|
coop_scripting.fill_coop_entrant_lists(props, rtgg_obs) |
|
146
|
|
|
rtgg_obs.timer.enabled = True |
|
147
|
|
|
obs.timer_add(update_sources, 100) |
|
148
|
|
|
elif ladder_timer.enabled: |
|
149
|
|
|
obs.timer_add(update_sources, 100) |
|
150
|
|
|
elif rtgg_obs.preview_mode: |
|
151
|
|
|
obs.timer_add(update_sources, 100) |
|
152
|
|
|
else: |
|
153
|
|
|
obs.obs_data_set_default_string( |
|
154
|
|
|
settings, "race_info", "Race not found") |
|
155
|
|
|
return True |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
def new_category_selected(props, prop, settings): |
|
159
|
|
|
rtgg_obs.category = obs.obs_data_get_string(settings, "category_filter") |
|
160
|
|
|
rtgg_obs.logger.info(f"new category selected: {rtgg_obs.category}") |
|
161
|
|
|
fill_race_list(rtgg_obs, obs.obs_properties_get(props, "race"), prop) |
|
162
|
|
|
return True |
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
def media_player_toggled(props, prop, settings): |
|
166
|
|
|
vis = obs.obs_data_get_bool(settings, "use_media_player") |
|
167
|
|
|
obs.obs_property_set_visible( |
|
168
|
|
|
obs.obs_properties_get(props, "media_player_group"), vis) |
|
169
|
|
|
return True |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
def update_sources(): |
|
173
|
|
|
if rtgg_obs.preview_mode: |
|
174
|
|
|
update_sources_preview() |
|
175
|
|
|
|
|
176
|
|
|
if rtgg_obs.race is not None: |
|
177
|
|
|
if rtgg_obs.timer.is_enabled(): |
|
178
|
|
|
color, time = rtgg_obs.timer.get_timer_text( |
|
179
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
180
|
|
|
set_source_text(rtgg_obs.timer.source_name, time, color) |
|
181
|
|
|
update_coop_sources() |
|
182
|
|
|
if rtgg_obs.qualifier.is_enabled(): |
|
183
|
|
|
set_source_text(rtgg_obs.qualifier.par_source, |
|
184
|
|
|
rtgg_obs.qualifier.par_text, None) |
|
185
|
|
|
set_source_text(rtgg_obs.qualifier.score_source, |
|
186
|
|
|
rtgg_obs.qualifier.entrant_score, None) |
|
187
|
|
|
if rtgg_obs.media_player.enabled: |
|
188
|
|
|
rtgg_obs.media_player.race_updated( |
|
189
|
|
|
rtgg_obs.race, rtgg_obs.full_name) |
|
190
|
|
|
elif ladder_timer.enabled: |
|
191
|
|
|
color, time = ladder_timer.get_timer_text() |
|
192
|
|
|
set_source_text(rtgg_obs.timer.source_name, time, color) |
|
193
|
|
|
stats = ladder_timer.get_stats() |
|
194
|
|
|
set_source_text(ladder_timer.stats_source, stats, None) |
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
def update_sources_preview(): |
|
198
|
|
|
color, time = rtgg_obs.timer.get_timer_text_preview() |
|
199
|
|
|
set_source_text(rtgg_obs.timer.source_name, time, color) |
|
200
|
|
|
if (rtgg_obs.coop.is_enabled()): |
|
201
|
|
|
rtgg_obs.coop.update_coop_text_preview() |
|
202
|
|
|
set_source_text( |
|
203
|
|
|
rtgg_obs.coop.our_time_source, |
|
204
|
|
|
rtgg_obs.coop.our_time_text, |
|
205
|
|
|
rtgg_obs.coop.our_time_color |
|
206
|
|
|
) |
|
207
|
|
|
set_source_text( |
|
208
|
|
|
rtgg_obs.coop.opponent_time_source, |
|
209
|
|
|
rtgg_obs.coop.opponent_time_text, |
|
210
|
|
|
rtgg_obs.coop.opponent_time_color |
|
211
|
|
|
) |
|
212
|
|
|
if (rtgg_obs.qualifier.is_enabled): |
|
213
|
|
|
rtgg_obs.qualifier.update_qualifier_text_preview() |
|
214
|
|
|
set_source_text(rtgg_obs.qualifier.par_source, |
|
215
|
|
|
rtgg_obs.qualifier.par_text, None) |
|
216
|
|
|
set_source_text(rtgg_obs.qualifier.score_source, |
|
217
|
|
|
rtgg_obs.qualifier.entrant_score, None) |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
def update_coop_sources(): |
|
221
|
|
|
if rtgg_obs.coop.is_enabled(): |
|
222
|
|
|
rtgg_obs.coop.update_coop_text(rtgg_obs.race, rtgg_obs.full_name) |
|
223
|
|
|
set_source_text( |
|
224
|
|
|
rtgg_obs.coop.our_time_source, |
|
225
|
|
|
rtgg_obs.coop.our_time_text, |
|
226
|
|
|
rtgg_obs.coop.our_time_color |
|
227
|
|
|
) |
|
228
|
|
|
set_source_text( |
|
229
|
|
|
rtgg_obs.coop.opponent_time_source, |
|
230
|
|
|
rtgg_obs.coop.opponent_time_text, |
|
231
|
|
|
rtgg_obs.coop.opponent_time_color |
|
232
|
|
|
) |
|
233
|
|
|
|