|
1
|
|
|
from enum import Enum, auto |
|
2
|
|
|
import os |
|
3
|
|
|
from typing import List |
|
4
|
|
|
import gettext |
|
5
|
|
|
from models.race import Race |
|
6
|
|
|
import obspython as obs |
|
7
|
|
|
from helpers.obs_context_manager import data_ar, source_ar, source_list_ar |
|
8
|
|
|
from rtgg_obs import RacetimeObs |
|
9
|
|
|
import clients.racetime_client as racetime_client |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class ScriptProperties(str, Enum): |
|
13
|
|
|
all_category = auto() |
|
14
|
|
|
none_races = auto() |
|
15
|
|
|
alttpr_ladder = "ALTTPR Ladder" |
|
16
|
|
|
alttpr_category = "A Link to the Past Randomizer" |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
sp = ScriptProperties |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
def fill_source_list(p): |
|
23
|
|
|
obs.obs_property_list_clear(p) |
|
24
|
|
|
obs.obs_property_list_add_string(p, "", "") |
|
25
|
|
|
with source_list_ar() as sources: |
|
26
|
|
|
if sources is not None: |
|
27
|
|
|
for source in sources: |
|
28
|
|
|
source_id = obs.obs_source_get_unversioned_id(source) |
|
29
|
|
|
if ( |
|
30
|
|
|
source_id == "text_gdiplus" or |
|
31
|
|
|
source_id == "text_ft2_source" |
|
32
|
|
|
): |
|
33
|
|
|
name = obs.obs_source_get_name(source) |
|
34
|
|
|
obs.obs_property_list_add_string(p, name, name) |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
def fill_race_list(rtgg_obs: RacetimeObs, race_list, category_list): |
|
38
|
|
|
lang = gettext.translation( |
|
39
|
|
|
"racetime-obs", localedir=os.environ['LOCALEDIR']) |
|
40
|
|
|
_ = lang.gettext |
|
41
|
|
|
obs.obs_property_list_clear(race_list) |
|
42
|
|
|
obs.obs_property_list_clear(category_list) |
|
43
|
|
|
obs.obs_property_list_add_string(category_list, _("All"), sp.all_category) |
|
44
|
|
|
|
|
45
|
|
|
obs.obs_property_list_add_string(race_list, _("None"), "None") |
|
46
|
|
|
races = racetime_client.get_races() |
|
47
|
|
|
if races is not None: |
|
48
|
|
|
fill_category_list(category_list, races) |
|
49
|
|
|
if (rtgg_obs.category == sp.alttpr_category or |
|
50
|
|
|
rtgg_obs.category == sp.all_category): |
|
51
|
|
|
obs.obs_property_list_add_string( |
|
52
|
|
|
race_list, sp.alttpr_ladder, sp.alttpr_ladder) |
|
53
|
|
|
for race in filter_races_by_category(rtgg_obs, races): |
|
54
|
|
|
obs.obs_property_list_add_string(race_list, race.name, race.name) |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
def fill_category_list(category_list, races: List[Race]): |
|
58
|
|
|
categories = [] |
|
59
|
|
|
for race in races: |
|
60
|
|
|
if race.category.name not in categories: |
|
61
|
|
|
categories.append(race.category.name) |
|
62
|
|
|
obs.obs_property_list_add_string( |
|
63
|
|
|
category_list, race.category.name, race.category.name) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
def filter_races_by_category( |
|
67
|
|
|
rtgg_obs: RacetimeObs, races: List[Race] |
|
68
|
|
|
) -> List[Race]: |
|
69
|
|
|
for race in races: |
|
70
|
|
|
if ( |
|
71
|
|
|
rtgg_obs.category == "" or rtgg_obs.category == sp.all_category or |
|
72
|
|
|
race.category.name == rtgg_obs.category |
|
73
|
|
|
): |
|
74
|
|
|
yield race |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
def set_source_text(source_name: str, text: str, color: int): |
|
78
|
|
|
if source_name is None or source_name == "": |
|
79
|
|
|
return |
|
80
|
|
|
# copied and modified from scripted-text.py by UpgradeQ |
|
81
|
|
|
with source_ar(source_name) as source, data_ar() as settings: |
|
82
|
|
|
obs.obs_data_set_string(settings, "text", text) |
|
83
|
|
|
source_id = obs.obs_source_get_unversioned_id(source) |
|
84
|
|
|
if color is not None: |
|
85
|
|
|
if source_id == "text_gdiplus": |
|
86
|
|
|
obs.obs_data_set_int(settings, "color", color) # colored text |
|
87
|
|
|
|
|
88
|
|
|
# freetype2 is BGR, should be reversed for getting correct color |
|
89
|
|
|
else: |
|
90
|
|
|
number = "".join(hex(color)[2:]) |
|
91
|
|
|
color = int("0xff" f"{number}", base=16) |
|
92
|
|
|
obs.obs_data_set_int(settings, "color1", color) |
|
93
|
|
|
|
|
94
|
|
|
obs.obs_source_update(source, settings) |
|
95
|
|
|
|