def start_round(): """Prompts all users to press their buttons and responds to the first one.""" if not session.attributes['players']: return question( "I don't see any players yet. Start the roll call first.") session.attributes['activity'] = 'new round' return gadget('Press your button to buzz in.').first_button( timeout=8000, gadget_ids=[p['gid'] for p in session.attributes['players']], animations=[animation(repeat=4).crossfade(duration=200).off()])
def buzz_in(input_event): """Acknowledges the first button that was pressed with speech and a 'breathing' animation.""" gid = input_event['gadgetId'] try: pid = [p['pid'] for p in session.attributes['players'] if p['gid'] == gid][0] except LookupError: return question("I couldn't find the player associated with that button.") return gadget("Player {}, you buzzed in first.".format(pid)).set_light( targets=[gid], animations=[animation(repeat=3).breathe(duration=500, color='00FF00')] )
def test_animation_sequence(self): a = animation() a.fade_in(duration=2000, color='0000FF').off(duration=500) a.crossfade(duration=1000, colors=['FF0000', 'FFFF00']).fade_out(duration=1000) sequence = [ {'durationMs': 1, 'color': '000000', 'blend': True}, {'durationMs': 2000, 'color': '0000FF', 'blend': True}, {'durationMs': 500, 'color': '000000', 'blend': False}, {'durationMs': 1000, 'color': 'FF0000', 'blend': True}, {'durationMs': 1000, 'color': 'FFFF00', 'blend': True}, {'durationMs': 1, 'color': 'FFFFFF', 'blend': True}, {'durationMs': 1000, 'color': '000000', 'blend': True} ] self.assertEqual(a['sequence'], sequence)
def register_player(event_name, input_event): """Adds a player's button to the list of known buttons and makes the button pulse yellow.""" if input_event['action'] == 'down': button_number = event_name[-1] gid = input_event['gadgetId'] session.attributes['players'].append({'pid': button_number, 'gid': gid}) speech = "" if event_name.endswith('2'): session.attributes['activity'] = 'roll call complete' speech = 'I found {} buttons. Ready to start the round?'.format(2) return gadget(speech).set_light( targets=[gid], animations=[animation().on(color='FFFF00')] )
def set_color(button='1', color='red'): colors = { 'white': 'FFFFFF', 'red': 'FF0000', 'orange': 'FF3300', 'yellow': 'FFD400', 'green': '00FF00', 'blue': '0000FF', 'purple': '4B0098', 'black': '000000' } hex = colors.get(color, 'FFFFFF') try: gid = [ p['gid'] for p in session.attributes['players'] if p['pid'] == button ][0] except LookupError: return question("I couldn't find that button.").reprompt( "What would you like to do?") return gadget().set_light(targets=[gid], animations=[animation().on(color=hex)])
def test_animation(self): a = animation() self.assertEqual(a, {'repeat': 1, 'targetLights': ['1'], 'sequence': []})