1
|
|
|
from typing import List |
2
|
|
|
from models.race import Race |
3
|
|
|
from models.category import Category |
4
|
|
|
import obspython as obs |
5
|
|
|
from helpers.obs_context_manager import data_ar, source_ar, source_list_ar |
6
|
|
|
from rtgg_obs import RacetimeObs |
7
|
|
|
import racetime_client |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def fill_source_list(p): |
11
|
|
|
obs.obs_property_list_clear(p) |
12
|
|
|
obs.obs_property_list_add_string(p, "", "") |
13
|
|
|
with source_list_ar() as sources: |
14
|
|
|
if sources is not None: |
15
|
|
|
for source in sources: |
16
|
|
|
source_id = obs.obs_source_get_unversioned_id(source) |
17
|
|
|
if ( |
18
|
|
|
source_id == "text_gdiplus" or |
19
|
|
|
source_id == "text_ft2_source" |
20
|
|
|
): |
21
|
|
|
name = obs.obs_source_get_name(source) |
22
|
|
|
obs.obs_property_list_add_string(p, name, name) |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def fill_race_list(rtgg_obs: RacetimeObs, race_list, category_list): |
26
|
|
|
obs.obs_property_list_clear(race_list) |
27
|
|
|
obs.obs_property_list_clear(category_list) |
28
|
|
|
obs.obs_property_list_add_string(category_list, "All", "All") |
29
|
|
|
|
30
|
|
|
obs.obs_property_list_add_string(race_list, "None", "None") |
31
|
|
|
races = racetime_client.get_races() |
32
|
|
|
if races is not None: |
33
|
|
|
fill_category_list(category_list, races) |
34
|
|
|
for race in filter_races_by_category( |
35
|
|
|
rtgg_obs, races, rtgg_obs.category |
36
|
|
|
): |
37
|
|
|
obs.obs_property_list_add_string(race_list, race.name, race.name) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
def fill_category_list(category_list, races: List[Race]): |
41
|
|
|
categories = [] |
42
|
|
|
for race in races: |
43
|
|
|
if race.category.name not in categories: |
44
|
|
|
categories.append(race.category.name) |
45
|
|
|
obs.obs_property_list_add_string( |
46
|
|
|
category_list, race.category.name, race.category.name) |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
def filter_races_by_category( |
50
|
|
|
rtgg_obs: RacetimeObs, races: List[Race], category: Category |
51
|
|
|
) -> Race: |
52
|
|
|
for race in races: |
53
|
|
|
if ( |
54
|
|
|
rtgg_obs.category == "" or rtgg_obs.category == "All" or |
55
|
|
|
race.category.name == rtgg_obs.category |
56
|
|
|
): |
57
|
|
|
yield race |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
def set_source_text(source_name: str, text: str, color: int): |
61
|
|
|
if source_name is None or source_name == "": |
62
|
|
|
return |
63
|
|
|
# copied and modified from scripted-text.py by UpgradeQ |
64
|
|
|
with source_ar(source_name) as source, data_ar() as settings: |
65
|
|
|
obs.obs_data_set_string(settings, "text", text) |
66
|
|
|
source_id = obs.obs_source_get_unversioned_id(source) |
67
|
|
|
if color is not None: |
68
|
|
|
if source_id == "text_gdiplus": |
69
|
|
|
obs.obs_data_set_int(settings, "color", color) # colored text |
70
|
|
|
|
71
|
|
|
# freetype2 is BGR, should be reversed for getting correct color |
72
|
|
|
else: |
73
|
|
|
number = "".join(hex(color)[2:]) |
74
|
|
|
color = int("0xff" f"{number}", base=16) |
75
|
|
|
obs.obs_data_set_int(settings, "color1", color) |
76
|
|
|
|
77
|
|
|
obs.obs_source_update(source, settings) |
78
|
|
|
|