コード例 #1
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def do_remove_all(self, *args):

        r = safe_get(self.scoreboard_address + '/status/players')

        try:
            players = r.data.json()
        except Exception:
            print('could not remove players')
            return

        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        for player in sorted(players)[::-1]:
            player_data = {'playerNumber': player}
            r = safe_post(self.scoreboard_address + '/control/punregister',
                          data=player_data,
                          headers=headers)

            try:
                status = r.data.json()
            except Exception:
                print('Could not unregister player {}'.format(player))
                continue

            if status['status'] == 'error':
                print('Could not unregister player {}, got: {}'.format(
                    player, status['error']))
                continue
コード例 #2
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def one_shot_refresh(self):
        try:
            r = safe_get(self.scoreboard_address + '/status/sfxlist')
            status = r.data.json()
        except:
            print('error getting SFX List')
            return

        if status['status'] != 'ok':
            print('error getting SFX List')
            return

        self.sfx_list = status['sfx_list']

        self._sfx_widgets = []
        for k, v in self.sfx_list.items():
            if v is not None:
                name = v
            else:
                name = k

            widget = OneLineIconListItem(text=name)
            widget.add_widget(AvatarSampleWidget(icon='volume-high'))
            widget.bind(on_press=self.do_sfx_play)
            self._sfx_widgets.append(widget)
            self.ids['debugTabActions'].add_widget(widget)

        # create SFX reverse lookup dictionary
        self.sfx_reverse_list = {}
        for k, v in self.sfx_list.items():
            if v is not None:
                self.sfx_reverse_list[v] = k

        # get game persistance data
        try:
            r = safe_get(self.scoreboard_address + '/persist/game_list')
            status = r.data.json()
        except:
            print('error getting game persistance')
            return

        self.game_persist_list = status['game_list']
        # update spinner
        self.ids['gpersist'].values = sorted(self.game_persist_list)
        self.ids['gpersist'].disabled = False
コード例 #3
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def do_end_game(self, *args):
        r = safe_get(self.scoreboard_address + '/control/gend')

        try:
            status = r.data.json()
        except:
            print('could not parse response')
            return

        if status['status'] == 'error':
            print('could not stop game, got: {}'.format(status['error']))
            popup = Popup(title='Error!',
                          content=Label(text=status['error']),
                          size_hint=(0.25, 0.25))
            popup.open()
コード例 #4
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def do_set_score(self, player, score):

        if score > 5 or score < -10:
            print('Invalid score input')
            self.ids['setscore{}'.format(player)].text = ''
            return

        r = safe_get(self.scoreboard_address +
                     '/debug/setscore/{},{}'.format(player, score))

        try:
            response = r.data.json()
        except:
            return

        if response['status'] == 'error':
            print('Could not set score, returned {}'.format(response['error']))
コード例 #5
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def do_sfx_play(self, *args):

        if args[0].text not in self.sfx_reverse_list:
            # try directly
            sfx_name = args[0].text
        else:
            sfx_name = self.sfx_reverse_list[args[0].text]

        r = safe_get(self.scoreboard_address +
                     '/debug/sfx/{}'.format(sfx_name))

        try:
            status = r.data.json()
        except:
            print('could not parse response')
            return

        if status['status'] == 'error':
            print('Could not play SFX, got: {}'.format(status['error']))
コード例 #6
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def _do_debug_setup(self, player_num):

        player_names = ["A", "B", "C", "D"]

        # register some players

        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

        for p in range(0, player_num):

            player_data = {
                'panelTxt': player_names[p],
                'webTxt': player_names[p]
            }
            r = safe_post(self.scoreboard_address + '/control/pregister',
                          data=player_data,
                          headers=headers)

            try:
                response = r.data.json()
                if response['status'] == 'error':
                    raise ScoreboardException
            except ScoreboardException:
                Logger.error(
                    'Could not setup successfully, returned: {}'.format(
                        response['error']))
                continue
            except Exception as ex:
                Logger.error(f'DebugSetup: failed to perform debug setup with'
                             f' {player_num} players, got "{ex}"')
                return

            player_num = int(response['playerNum'])

            # force pairing
            r = safe_get(self.scoreboard_address +
                         '/debug/fpair/{},{}'.format(player_num, player_num +
                                                     1))
コード例 #7
0
    def run(self):
        """Run thread."""
        if self.root.stop_refreshing is True:
            return

        # try to contact scoreboard
        r = safe_get(self.root.scoreboard_address + '/status/all', timeout=1)
        if r.success is False:
            if is_connection_error_exception(r.data):
                self.root.disable_app(from_thread=True)
                return
            else:
                # some other exception, just ignore
                Logger.info('PanelUpdater: other exception caught: {}'.format(
                    r.data))
                return
        else:
            try:
                status = r.data.json()
                success = True
            except Exception as ex:
                # ignore
                success = False
                Logger.info('PanelUpdater: exception '
                            'caught while retriving data: {}'.format(repr(ex)))

        if self.root.disconnected:
            self.root.enable_app(from_thread=True)
            self.root.one_shot_refresh()
        if success is False:
            return

        self.disabled = False

        # first look at board status
        json_data = status['board']
        if json_data['status'] == 'error':
            self.root._scoreboard_status = 'board_err'
            return

        # get game status
        json_data = status['game']
        if json_data['status'] == 'error':
            self.root._scoreboard_status = 'game_err'
            return

        self.root_scoreboard_status = 'ok'
        server = -1
        if json_data['game'] == 'started':
            self.root.ids['gameActStart'].disabled = True
            self.root.ids['gameActPause'].disabled = False
            self.root.ids['gameActStop'].disabled = False
            self.root.ids['gameSetupRmAll'].disabled = True
            self.root.game_running = True
            self.root.game_paused = False
            self.root._game_id = str(json_data['game_id'])
            self.root._user_id = json_data['user_id']
            server = int(json_data['serving'])
            for i in range(0, 4):
                self.root.ids['pname{}'.format(i)].disabled = False
                self.root.ids['pscore{}'.format(i)].disabled = False
                self.root.ids['pindirect{}'.format(i)].disabled = False
                self.root.ids['preferee{}'.format(i)].disabled = False
        elif json_data['game'] == 'stopped' or json_data['game'] == 'paused':
            self.root._game_id = str(json_data['game_id'])
            self.root._user_id = json_data['user_id']
            self.root.game_running = False
            if json_data['game'] == 'stopped':

                if json_data['can_start']:
                    self.root.ids['gameActStart'].disabled = False
                else:
                    self.root.ids['gameActStart'].disabled = True

                self.root.ids['gameActStop'].disabled = True
                self.root.ids['gameActPause'].disabled = True
                self.root.ids['gameSetupRmAll'].disabled = False

                self.root.game_paused = False
            else:
                self.root.game_paused = True
            for i in range(0, 4):
                self.root.ids['pname{}'.format(i)].disabled = False
                self.root.ids['pscore{}'.format(i)].disabled = True
                self.root.ids['pindirect{}'.format(i)].disabled = True
                self.root.ids['preferee{}'.format(i)].disabled = True

        json_data = status['players']
        self.root.player_num = len(json_data)
        self.root.registered_player_list = json_data
        for i in range(0, 4):
            if str(i) in json_data:
                self.root.ids['pname{}'.format(i)].text =\
                    json_data[str(i)]['web_txt']
                self.root.ids['pname{}'.format(i)].md_bg_color =\
                    self.root._original_btn_color
            else:
                self.root.ids['pname{}'.format(i)].text = ''

        json_data = status['scores']
        if json_data['status'] == 'error':
            for i in range(0, 4):
                self.root.ids['pscore{}'.format(i)].update_score('-')

        for i in range(0, 4):
            if str(i) in json_data and i < self.root.player_num:
                self.root.ids['pscore{}'.format(i)].update_score(
                    str(json_data[str(i)]))
                if int(json_data[str(i)]) == -10:
                    self.root.ids['pname{}'.format(i)].disabled = True
                    self.root.ids['pscore{}'.format(i)].disabled = True
                    self.root.ids['pindirect{}'.format(i)].disabled = True
                    self.root.ids['preferee{}'.format(i)].disabled = True
            elif self.root.game_running is True:
                self.root.ids['pscore{}'.format(i)].update_score('-')
                self.root.ids['pname{}'.format(i)].disabled = True
                self.root.ids['pindirect{}'.format(i)].disabled = True
                self.root.ids['preferee{}'.format(i)].disabled = True

        if server > -1:
            player_name = self.root.ids['pname{}'.format(server)].text
            self.root.ids['pname{}'.format(server)].text = player_name
            self.root.ids['pname{}'.format(server)].md_bg_color = (1, 0, 0, 1)

        json_data = status['timer']
        if 'status' in json_data:
            if json_data['status'] == 'error':
                self.root.scoreboard_update()
                return
        else:
            timer_txt = '{:0>2d}'.format(json_data['minutes']) + ':' +\
                        '{:0>2d}'.format(json_data['seconds'])
            self.root.ids['timerlabel'].text = timer_txt
            self.root.scoreboard_update()
コード例 #8
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def register_scoring_event(self, evt_type, player):
     safe_get(self.scoreboard_address +
              '/control/scoreevt/{},{}'.format(player, evt_type))
コード例 #9
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def do_set_turn_4(self, *args):
     safe_get(self.scoreboard_address + '/debug/setturn/3')
コード例 #10
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def do_set_turn(self, player):
     safe_get(self.scoreboard_address + '/debug/setturn/{}'.format(player))
コード例 #11
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def do_force_serve(self, pnum):
     safe_get(self.scoreboard_address + '/debug/pass')
コード例 #12
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def do_decr_score(self, pnum):
     safe_get(self.scoreboard_address + '/debug/sdecr/{}'.format(pnum))
コード例 #13
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
 def do_test_score_4(self, *args):
     safe_get(self.scoreboard_address + '/debug/scoretest/3')
コード例 #14
0
ファイル: root.py プロジェクト: brunosmmm/chainball-panel
    def force_pairing(self):

        for p in range(0, 4):
            # force pairing
            safe_get(self.scoreboard_address +
                     '/debug/fpair/{},{}'.format(p, p + 1))