aboutsummaryrefslogtreecommitdiff
path: root/helpers/actions/play.py
blob: fdba95b5b9477617e85dcac8ab6ff67962ab6f8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def run(action, music=None, fade_in=0, start_at=0,
        restart_if_running=False, volume=100,
        loop=0, **kwargs):
    for music in action.music_list(music):
        if restart_if_running:
            if music.is_in_use():
                music.stop()
            music.play(
                    volume=volume,
                    fade_in=fade_in,
                    start_at=start_at,
                    loop=loop)
        elif not music.is_in_use():
            music.play(
                    volume=volume,
                    fade_in=fade_in,
                    start_at=start_at,
                    loop=loop)

def description(action, music=None, fade_in=0, start_at=0,
        restart_if_running=False, volume=100, loop=0, **kwargs):
    message = "starting "
    if music is not None:
        message += "« {} »".format(music.name)
    else:
        message += "all musics"

    if start_at != 0:
        message += " at {}s".format(start_at)

    if fade_in != 0:
        message += " with {}s fade_in".format(fade_in)

    message += " at volume {}%".format(volume)

    if loop > 0:
        message += " {} times".format(loop + 1)
    elif loop < 0:
        message += " in loop"

    if restart_if_running:
        message += " (restarting if already running)"

    return message