|
| 1 | +# ../players/engines/orangebox/cstrike.py |
| 2 | + |
| 3 | +"""Provides Team Fortress 2 specific Player based functionality.""" |
| 4 | + |
| 5 | +# ============================================================================= |
| 6 | +# >> IMPORTS |
| 7 | +# ============================================================================= |
| 8 | +# Source.Python Imports |
| 9 | +from . import Player as _Player |
| 10 | +from configobj import ConfigObj |
| 11 | +from core import GAME_NAME |
| 12 | +from paths import SP_DATA_PATH |
| 13 | + |
| 14 | +# ============================================================================= |
| 15 | +# >> CLASSES |
| 16 | +# ============================================================================= |
| 17 | +class Player(_Player): |
| 18 | + caching = True |
| 19 | + |
| 20 | + # Team |
| 21 | + _team_data = ConfigObj(SP_DATA_PATH / 'teams' / GAME_NAME + '.ini', unrepr=True) |
| 22 | + teams_by_name = _team_data.get('names') |
| 23 | + teams_by_number = {number: alias for alias, number in teams_by_name.items()} |
| 24 | + |
| 25 | + @property |
| 26 | + def team_name(self): |
| 27 | + return self.teams_by_number[self.team] |
| 28 | + |
| 29 | + @team_name.setter |
| 30 | + def team_name(self, team_name): |
| 31 | + if team_id not in self.team_by_name.keys(): |
| 32 | + raise ValueError(f"Invalid team_name: {team_name}") |
| 33 | + |
| 34 | + self.team = self.teams_by_name[team_name] |
| 35 | + |
| 36 | + # Mercanary class |
| 37 | + class_by_name = _team_data.get('classes') |
| 38 | + class_by_number = {number: alias for alias, number in class_by_name.items()} |
| 39 | + |
| 40 | + @property |
| 41 | + def player_class_name(self): |
| 42 | + return self.class_by_number[self.player_class] |
| 43 | + |
| 44 | + @player_class_name.setter |
| 45 | + def player_class_name(self, class_name): |
| 46 | + if team_id not in self.class_by_name.keys(): |
| 47 | + raise ValueError(f"Invalid class_name: {class_name}") |
| 48 | + |
| 49 | + # Does this need to be desired_player_class? |
| 50 | + self.player_class = self.class_by_name[team_name] |
0 commit comments