Beispiel #1
0
def on_start_sound(cmd: pcmd.Command, args: List[str], parameters: List[str],
                   json: bool) -> None:
    """Callback for `start sound` - adds a sound effect"""
    for i, a in enumerate(parameters):
        if re.match(r'^[\d\.]*$', a):
            continue
        if not os.path.isfile(a):
            a = os.path.join(params.BPATH, 'res', 'sounds', a)
        if not os.path.isfile(a):
            if not json:
                utils.printerr(f'File "{a}" doesn\'t exist ... ')
                continue
            else:
                print(
                    JSON.dumps({
                        'error': f'File "{a}" doesn\'t exist ... "',
                    }))
                return
        try:
            if i + 1 < len(args) and re.match(r'^[\d\.]+$', args[i + 1]):
                ch.add_sound(Sound(a, float(args[i + 1])))
                continue
            ch.add_sound(Sound(a))
        except Exception as e:
            if not json:
                utils.printerr(str(e))
            else:
                print(JSON.dumps({
                    'error': str(e),
                }))
        if json:
            print(JSON.dumps({}))
Beispiel #2
0
def on_start_sound(cmd: pcmd.Command, args: List[str],
                   params: List[str]) -> None:
    """Callback for `start sound` - adds a sound effect"""
    for i, a in enumerate(params):
        if re.match(r'^[\d\.]*$', a):
            continue
        if not os.path.isfile(a):
            utils.printerr('File "{}" doesn\'t exist ... '.format(a))
        try:
            if i + 1 < len(args) and re.match(r'^[\d\.]+$', args[i + 1]):
                ch.add_sound(Sound(a, float(args[i + 1])))
                continue
            ch.add_sound(Sound(a))
        except Exception as e:
            utils.printerr(str(e))
 def __load(self, path, limit):
     with open(path, newline='') as metadatacsv:
         reader = csv.DictReader(metadatacsv)
         for row in reader:
             s = Sound(row)
             if limit == -1 or len(list(filter(lambda x: x.folder == s.folder and x.sound_class == s.sound_class,self.__metadata))) < limit:
                 self.__metadata.append(s)
Beispiel #4
0
    def _init_res(self):
        super()._init_res()
        self.key_sound = Sound(os.path.join(self.sound_dir, 'pew.wav'))
        self.bg_image = Image(
            os.path.join(self.image_dir, 'blackboard_1024_768.png')).image
        self.right_image = Image(
            os.path.join(self.image_dir, 'right_140_147.png')).image
        self.wrong_image = Image(
            os.path.join(self.image_dir, 'wrong_140_177.png')).image
        ball_path = os.path.join(self.image_dir, 'basketball_50_50.png')
        speed = 13
        rand = ((0.1 * (random.randint(5, 8))))
        vector = (0.47, speed)
        basketball = BasketBall(path=ball_path, vector=vector)
        self.basketball = pygame.sprite.RenderPlain(basketball)
        # self._init_db()

        self.voicer_name = 'ada'
        self.voice_path = os.path.join(self.sound_dir, self.voicer_name)
        self.voicer = Voicer(path=self.voice_path)