diff --git a/addons/source-python/data/source-python/teams/tf.ini b/addons/source-python/data/source-python/teams/tf.ini index a8c82e62f..ecc96d37a 100644 --- a/addons/source-python/data/source-python/teams/tf.ini +++ b/addons/source-python/data/source-python/teams/tf.ini @@ -5,3 +5,14 @@ un = 0 spec = 1 red = 2 blue = 3 + +[classes] +scout = 1 +sniper = 2 +soldier = 3 +demoman = 4 +medic = 5 +heavy = 6 +pyro = 7 +spy = 8 +engineer = 9 diff --git a/addons/source-python/packages/source-python/players/engines/orangebox/tf.py b/addons/source-python/packages/source-python/players/engines/orangebox/tf.py new file mode 100644 index 000000000..93a2608e6 --- /dev/null +++ b/addons/source-python/packages/source-python/players/engines/orangebox/tf.py @@ -0,0 +1,49 @@ +# ../players/engines/orangebox/cstrike.py + +"""Provides Team Fortress 2 specific Player based functionality.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Imports +from . import Player as _Player +from configobj import ConfigObj +from core import GAME_NAME +from paths import SP_DATA_PATH + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class Player(_Player): + caching = True + + # Team + _team_data = ConfigObj(SP_DATA_PATH / 'teams' / GAME_NAME + '.ini', unrepr=True) + + _teams_names = _team_data.get('names') + _class_names = _team_data.get('classes') + + @property + def team_name(self): + teams_by_number = dict(zip(self._teams_names.values(), self._teams_names.keys())) + return teams_by_number[self.team] + + @team_name.setter + def team_name(self, team_name): + if team_name not in self._teams_names: + raise ValueError(f"Invalid team_name: {team_name}") + + self.team = self._teams_names[team_name] + + @property + def player_class_name(self): + class_by_number = dict(zip(self._class_names.values(), self._class_names.keys())) + return class_by_number[self.player_class] + + @player_class_name.setter + def player_class_name(self, class_name): + if class_name not in self._class_names: + raise ValueError(f"Invalid class_name: {class_name}") + + # Does this need to be desired_player_class or should there b a setter for desired class? + self.player_class = self._class_names[class_name]