Skip to content

Commit 5811bde

Browse files
committed
Add timer effect
1 parent 66fab0c commit 5811bde

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

scripted_text.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from random import choice
66
from contextlib import contextmanager
77
from random import seed
8+
from datetime import timedelta
9+
from string import Template
810

911
__author__ = "upgradeQ"
10-
__version__ = "0.5.0"
12+
__version__ = "0.6.0"
1113
HOTKEY_ID = obs.OBS_INVALID_HOTKEY_ID
1214

1315
# auto release context managers
@@ -98,6 +100,7 @@ def load(self):
98100
"typewriter",
99101
"scrmbl",
100102
"fastread",
103+
"timer",
101104
]
102105
for i in effects_list:
103106
mapping[i] = getattr(self, i + "_" + "effect")
@@ -289,6 +292,21 @@ def wpm_chars(self):
289292
m = len(max(s, key=len))
290293
return [i.center(m, " ") for i in s]
291294

295+
def timer_effect(self):
296+
""" timer syntax "seconds = $s , centisecond = $cs"
297+
"""
298+
m_s = self.duration
299+
d = timedelta(milliseconds=m_s)
300+
s = d.seconds
301+
cs = str(d.microseconds)[:2]
302+
n = self.scripted_text
303+
ts = Template(n)
304+
try:
305+
time_data = ts.substitute(s=s, cs=cs)
306+
self.update_text(time_data)
307+
except:# skip errors when incorrect substitition happens
308+
self.update_text(self.scripted_text)
309+
292310
def hotkey_hook(self):
293311
""" trigger hotkey event"""
294312
self.play_sound()

0 commit comments

Comments
 (0)