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