コード例 #1
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.formation_library = OffenseLibrary()
        self.selected_personnel_key = "default"
        self.modifying_formation = Formation()
        self.composite_formation = Formation()
        self.formation_frame = FormationFrame(
            self.modifying_formation,
            self.formation_library.label_mappers['default'])
        self.scrollArea_2.setWidget(self.formation_frame)
        self.show()

        self.rb_editing.setChecked(True)
        self.rb_editing.clicked.connect(self.handle_editing_view_change)
        self.rb_composite.clicked.connect(self.handle_composite_view_change)
        self.edit_composite.returnPressed.connect(self.handle_get_composite)
        self.btn_load_composite.clicked.connect(self.handle_get_composite)

        self.list_formations.itemClicked.connect(self.handle_formation_clicked)
        self.edit_formation_name.returnPressed.connect(
            self.handle_save_formation)
        self.btn_save_formation.clicked.connect(self.handle_save_formation)
        self.btn_delete_selected_formation.clicked.connect(
            self.handle_delete_formation)

        self.actionSave_Library.triggered.connect(self.handle_save_library)

        self.init_label_mappers()
        self.combo_personnel_grouping.currentIndexChanged[str].connect(
            self.handle_personnel_change)
        self.set_personnel_cb_text(
            self.formation_library.label_mappers['default'].mappings)
コード例 #2
0
 def test_first_pass_return_invalid(self):
     formation = Formation()
     subformation = formation.subformations['MOF_RT']
     defense = Defense()
     defense.pass_number = 1
     position = first_open_gap(subformation, defense, ['Attached', 5, 'False'])
     self.assertEqual(position, INVALID_POSITION)
コード例 #3
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.formation_library = OffenseLibrary()
        self.defense_library = DefenseLibrary()

        self.current_hash = 'MOF'
        starting_formation = Formation()
        self.lh_subformation = starting_formation.subformations['LT_RT']
        self.rh_subformation = starting_formation.subformations['RT_RT']
        self.mof_subformation = starting_formation.subformations['MOF_RT']
        self.current_subformation = self.mof_subformation

        self.current_defense = Defense()
        self.defense_visual_frame = DefenseVisualFrame(
            self.current_subformation, self.current_defense,
            self.defense_library.label_mappers['default'])
        self.scroll_field.setWidget(self.defense_visual_frame)

        self.edit_formation_name.returnPressed.connect(
            self.handle_get_composite)
        self.btn_load_composite.clicked.connect(self.handle_get_composite)

        self.edit_defense_name.returnPressed.connect(self.handle_get_defense)
        self.btn_load_defense.clicked.connect(self.handle_get_composite)

        self.rb_lh.clicked.connect(lambda: self.handle_hash_change('LT'))
        self.rb_mof.clicked.connect(lambda: self.handle_hash_change('MOF'))
        self.rb_rh.clicked.connect(lambda: self.handle_hash_change('RT'))

        self.show()
コード例 #4
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.formation_library = OffenseLibrary()
        self.defense_library = DefenseLibrary()

        self.current_hash = 'MOF'
        starting_formation = Formation()
        self.lh_subformation = starting_formation.subformations['LT_RT']
        self.rh_subformation = starting_formation.subformations['RT_RT']
        self.mof_subformation = starting_formation.subformations['MOF_RT']
        self.current_subformation = self.mof_subformation

        self.modifying_defense = Defense()
        self.defense_visual_frame = DefenseVisualFrame(self.current_subformation, self.modifying_defense,
                                                       self.defense_library.label_mappers['default'])
        self.scroll_field.setWidget(self.defense_visual_frame)
        self.defender_editor = DefenderEditor(self.statusBar(), self.defense_visual_frame)
        self.scroll_defender_edit.setWidget(self.defender_editor)
        self.defender_editor.create_and_layout_condition_set_editors(self.modifying_defense.players['D1'])

        self.init_label_mappers()
        self.init_defender_combo(self.defense_library.label_mappers['default'].mappings)
        self.combo_personnel_grouping.currentIndexChanged[str].connect(self.handle_personnel_change)
        self.combo_defender_to_edit.currentIndexChanged[str].connect(self.handle_defender_change)
        self.set_personnel_cb_text(self.defense_library.label_mappers['default'].mappings)
        self.btn_save_defense.clicked.connect(self.handle_save_defense)
        self.btn_delete_selected_defense.clicked.connect(self.handle_delete_defense)
        self.edit_defense_name.returnPressed.connect(self.handle_save_defense)
        self.list_defenses.itemClicked.connect(self.handle_defense_clicked)

        self.rb_mof.setChecked(True)
        self.rb_mof.clicked.connect(lambda: self.handle_hash_change('MOF'))
        self.rb_lh.clicked.connect(lambda: self.handle_hash_change('LT'))
        self.rb_rh.clicked.connect(lambda: self.handle_hash_change('RT'))
        self.edit_formation_name.returnPressed.connect(self.handle_get_composite)
        self.btn_load_composite.clicked.connect(self.handle_get_composite)

        self.cb_d1.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d2.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d3.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d4.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d5.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d6.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d7.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d8.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d9.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d10.clicked.connect(self.handle_cb_affected_tag_clicked)
        self.cb_d11.clicked.connect(self.handle_cb_affected_tag_clicked)

        self.actionSave_Library.triggered.connect(self.handle_save_library)
        self.show()
コード例 #5
0
    def test_first_open_gap_places_correctly_for_abba(self):
        formation = Formation()
        subformation = formation.subformations['MOF_RT']
        defense = Defense()
        defense.affected_tags = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7']
        defense.players['D1'].placed_x = 2
        defense.players['D1'].placed_y = 1
        defense.players['D2'].placed_x = 6
        defense.players['D2'].placed_y = 1
        defense.players['D3'].placed_x = -2
        defense.players['D3'].placed_y = 1
        defense.players['D4'].placed_x = -6
        defense.players['D4'].placed_y = 1
        defense.pass_number = 2

        defense.players['D5'].placed_x, defense.players['D5'].placed_y = first_open_gap(subformation, defense, ['Attached', 5, 'False'])
        defense.players['D6'].placed_x, defense.players['D6'].placed_y = first_open_gap(subformation, defense, ['Attached', 5, 'True'])

        self.assertEqual(defense.players['D5'].placed_x, 10)
        self.assertEqual(defense.players['D5'].placed_y, 5)
        self.assertEqual(defense.players['D6'].placed_x, -10)
        self.assertEqual(defense.players['D6'].placed_y, 5)
コード例 #6
0
class OffensiveLibraryEditor(QMainWindow, Ui_OffensiveEditor):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.formation_library = OffenseLibrary()
        self.selected_personnel_key = "default"
        self.modifying_formation = Formation()
        self.composite_formation = Formation()
        self.formation_frame = FormationFrame(
            self.modifying_formation,
            self.formation_library.label_mappers['default'])
        self.scrollArea_2.setWidget(self.formation_frame)
        self.show()

        self.rb_editing.setChecked(True)
        self.rb_editing.clicked.connect(self.handle_editing_view_change)
        self.rb_composite.clicked.connect(self.handle_composite_view_change)
        self.edit_composite.returnPressed.connect(self.handle_get_composite)
        self.btn_load_composite.clicked.connect(self.handle_get_composite)

        self.list_formations.itemClicked.connect(self.handle_formation_clicked)
        self.edit_formation_name.returnPressed.connect(
            self.handle_save_formation)
        self.btn_save_formation.clicked.connect(self.handle_save_formation)
        self.btn_delete_selected_formation.clicked.connect(
            self.handle_delete_formation)

        self.actionSave_Library.triggered.connect(self.handle_save_library)

        self.init_label_mappers()
        self.combo_personnel_grouping.currentIndexChanged[str].connect(
            self.handle_personnel_change)
        self.set_personnel_cb_text(
            self.formation_library.label_mappers['default'].mappings)

    def handle_editing_view_change(self):
        self.formation_frame.can_edit = True
        self.formation_frame.formation = self.modifying_formation
        self.formation_frame.update()

    def handle_composite_view_change(self):
        self.formation_frame.can_edit = False
        self.formation_frame.formation = self.composite_formation
        self.formation_frame.update()

    def handle_get_composite(self):
        formation_name = self.edit_composite.text()
        #self.composite_formation = Formation()
        try:
            if len(formation_name) > 0:
                mof_composite = self.formation_library.get_composite_subformation(
                    'MOF', formation_name)[0]
                lh_composite = self.formation_library.get_composite_subformation(
                    'LH', formation_name)[0]
                rh_composite = self.formation_library.get_composite_subformation(
                    'RH', formation_name)[0]
                if not mof_composite is None:
                    self.composite_formation.subformations['MOF_RT'].copy_from(
                        mof_composite)
                    self.composite_formation.subformations['LT_RT'].copy_from(
                        lh_composite)
                    self.composite_formation.subformations['RT_RT'].copy_from(
                        rh_composite)
                    self.formation_frame.update()
        except Exception as e:
            from traceback import format_exc
            print(format_exc())

    def handle_personnel_change(self, new_personnel):
        self.formation_frame.personnel_mapper = self.formation_library.label_mappers[
            new_personnel]
        self.set_personnel_cb_text(
            self.formation_library.label_mappers[new_personnel].mappings)
        self.formation_frame.update()

    def handle_save_formation(self):
        formation_name = self.edit_formation_name.text()
        if len(formation_name) == 0:
            msg_box = QMessageBox()
            msg_box.setText('Formation needs name')
            msg_box.setWindowTitle('Error')
            msg_box.setStandardButtons(QMessageBox.Ok)
            msg_box.exec_()
            return

        affected_tags = []
        if self.cb_l1.isChecked():
            affected_tags.append('L1')
        if self.cb_l2.isChecked():
            affected_tags.append('L2')
        if self.cb_l3.isChecked():
            affected_tags.append('L3')
        if self.cb_l4.isChecked():
            affected_tags.append('L4')
        if self.cb_s1.isChecked():
            affected_tags.append('S1')
        if self.cb_s2.isChecked():
            affected_tags.append('S2')
        if self.cb_s3.isChecked():
            affected_tags.append('S3')
        if self.cb_s4.isChecked():
            affected_tags.append('S4')
        if self.cb_s5.isChecked():
            affected_tags.append('S5')
        if self.cb_s6.isChecked():
            affected_tags.append('S6')

        self.modifying_formation.affected_tags = affected_tags
        self.formation_library.save_formation_from_going_rt(
            self.modifying_formation, formation_name)
        self.load_formation_names_into_list()

    def handle_delete_formation(self):
        if self.list_formations.currentItem():
            formation_name = self.list_formations.currentItem().text()

            del self.formation_library.formations[formation_name]
            self.load_formation_names_into_list()

    def load_formation_names_into_list(self):
        formation_names = [
            name for name in self.formation_library.formations.keys()
        ]
        formation_names.sort()
        self.list_formations.clear()

        for formation_name in formation_names:
            self.list_formations.addItem(formation_name)

    def handle_formation_clicked(self, formation_clicked):
        formation_name = formation_clicked.data(0)
        self.rb_editing.setChecked(True)
        self.edit_formation_name.setText(formation_name)
        self.modifying_formation.copy_from(
            self.formation_library.formations[formation_name])
        self.formation_frame.formation = self.modifying_formation
        self.formation_frame.can_edit = True
        self.formation_frame.update()

        self.cb_l1.setChecked(
            True if 'L1' in self.modifying_formation.affected_tags else False)
        self.cb_l2.setChecked(
            True if 'L2' in self.modifying_formation.affected_tags else False)
        self.cb_l3.setChecked(
            True if 'L3' in self.modifying_formation.affected_tags else False)
        self.cb_l4.setChecked(
            True if 'L4' in self.modifying_formation.affected_tags else False)
        self.cb_s1.setChecked(
            True if 'S1' in self.modifying_formation.affected_tags else False)
        self.cb_s2.setChecked(
            True if 'S2' in self.modifying_formation.affected_tags else False)
        self.cb_s3.setChecked(
            True if 'S3' in self.modifying_formation.affected_tags else False)
        self.cb_s4.setChecked(
            True if 'S4' in self.modifying_formation.affected_tags else False)
        self.cb_s5.setChecked(
            True if 'S5' in self.modifying_formation.affected_tags else False)
        self.cb_s6.setChecked(
            True if 'S6' in self.modifying_formation.affected_tags else False)

    def handle_save_library(self):
        with open('offense_library.json', 'w') as file:
            json.dump(self.formation_library.to_dict(), file, indent=3)

    def load_library_from_dict(self, library_dict):
        self.formation_library = OffenseLibrary.from_dict(library_dict)
        self.load_formation_names_into_list()
        self.init_label_mappers()

    def init_label_mappers(self):
        # Must block signals because clear sends index changed signal which then references the now empty(null) combo box
        self.combo_personnel_grouping.blockSignals(True)
        self.combo_personnel_grouping.clear()
        self.combo_personnel_grouping.blockSignals(False)

        for personnel_grouping_key in self.formation_library.label_mappers.keys(
        ):
            self.combo_personnel_grouping.addItem(personnel_grouping_key)

    def set_personnel_cb_text(self, personnel_mapping):
        self.cb_l1.setText(f'L1 ( {personnel_mapping["L1"]} )')
        self.cb_l2.setText(f'L2 ( {personnel_mapping["L2"]} )')
        self.cb_l3.setText(f'L3 ( {personnel_mapping["L3"]} )')
        self.cb_l4.setText(f'L4 ( {personnel_mapping["L4"]} )')
        self.cb_s1.setText(f'S1 ( {personnel_mapping["S1"]} )')
        self.cb_s2.setText(f'S2 ( {personnel_mapping["S2"]} )')
        self.cb_s3.setText(f'S3 ( {personnel_mapping["S3"]} )')
        self.cb_s4.setText(f'S4 ( {personnel_mapping["S4"]} )')
        self.cb_s5.setText(f'S5 ( {personnel_mapping["S5"]} )')
        self.cb_s6.setText(f'S6 ( {personnel_mapping["S6"]} )')
コード例 #7
0
def export_to_football_trainer(file_name, plays, offense_library,
                               defense_library):
    script_plays = []
    play_info_plays = []
    default_subformation = Formation().subformations['MOF_RT']
    for play in plays:
        ## Play ##
        offense_info = f'{play["Number"]} {play["Personnel"]} {play["Hash"]} {play["Dnd"]} {play["Formation"]} {play["Play"]}'
        defense_info = f'{play["Defense"]} --- {play["Note"]}'

        play_dict = {'offenseInfo': offense_info, 'defenseInfo': defense_info}
        formation_name = play["Card Maker Formation"]
        defense_name = play["Card Maker Defense"]
        subformation, error_message = offense_library.get_composite_subformation(
            play['Hash'], formation_name)

        if not subformation:
            subformation = default_subformation

        if subformation.hash_mark == 'LT':
            hash_type = 0
        elif subformation.hash_mark == 'MOF':
            hash_type = 1
        else:
            hash_type = 2
        play_dict['hashType'] = hash_type

        players = []
        for tag, player in subformation.players.items():
            player_dict = {
                'tag': tag,
                'pose': determine_pose(player, subformation),
                'x': player.x,
                'y': player.y
            }
            players.append(player_dict)

        composite_defense = defense_library.get_composite_defense(defense_name)
        composite_defense.place_defenders(subformation)
        for tag, defender in composite_defense.players.items():
            player_dict = {
                'tag': tag,
                'pose': determine_pose(defender, subformation),
                'x': defender.placed_x,
                'y': -defender.placed_y
            }
            players.append(player_dict)

        play_dict['players'] = players
        script_plays.append(play_dict)

        ## Play Info ##
        play_info = {
            'l1TimelineName': '',
            'l2TimelineName': '',
            'l3TimelineName': '',
            'l4TimelineName': '',
            'cTimelineName': '',
            's1TimelineName': '',
            's2TimelineName': '',
            's3TimelineName': '',
            's4TimelineName': '',
            's5TimelineName': '',
            's6TimelineName': '',
            'd1TimelineName': '',
            'd2TimelineName': '',
            'd3TimelineName': '',
            'd4TimelineName': '',
            'd5TimelineName': '',
            'd6TimelineName': '',
            'd7TimelineName': '',
            'd8TimelineName': '',
            'd9TimelineName': '',
            'd10TimelineName': '',
            'd11TimelineName': '',
        }
        line_info = play['VR Trainer Play Line'].split()
        skill_info = play['VR Trainer Play Skill'].split()
        defender_info = play['VR Trainer Play Defender'].split()

        for i, player_animation_key in enumerate(line_info):
            if i == 0:
                play_info['l1TimelineName'] = player_animation_key
            if i == 1:
                play_info['l2TimelineName'] = player_animation_key
            if i == 2:
                play_info['cTimelineName'] = player_animation_key
            if i == 3:
                play_info['l3TimelineName'] = player_animation_key
            if i == 4:
                play_info['l4TimelineName'] = player_animation_key

        for i, player_animation_key in enumerate(skill_info):
            if i == 0:
                play_info['s1TimelineName'] = player_animation_key
            if i == 1:
                play_info['s2TimelineName'] = player_animation_key
            if i == 2:
                play_info['s3TimelineName'] = player_animation_key
            if i == 3:
                play_info['s4TimelineName'] = player_animation_key
            if i == 4:
                play_info['s5TimelineName'] = player_animation_key
            if i == 5:
                play_info['s6TimelineName'] = player_animation_key

        for i, player_animation_key in enumerate(defender_info):
            play_info[f'd{i+1}TimelineName'] = player_animation_key

        play_info['flashMessage'] = play['VR Trainer Flash Message']
        play_info['flashMessageTime'] = play['VR Trainer Flash Time']

        play_info_plays.append(play_info)

    script = {'plays': script_plays, 'playInfos': play_info_plays}

    with open(file_name, 'w') as file:
        json.dump(script, file, indent=3)