docstrings and cleanup

This commit is contained in:
Walter 2020-10-30 16:38:53 -05:00 committed by Dan Albert
parent 73ea83bbdd
commit d519dfa5da

View File

@ -6,7 +6,7 @@ import random
import logging import logging
from dataclasses import dataclass from dataclasses import dataclass
from theater.frontline import FrontLine from theater.frontline import FrontLine
from typing import List, Dict, TYPE_CHECKING from typing import List, Dict, TYPE_CHECKING, Optional
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
from dcs.mission import Mission from dcs.mission import Mission
@ -57,16 +57,20 @@ class FrontLineInfo:
def _zero_units_sentence(self) -> str: def _zero_units_sentence(self) -> str:
'''Situation description if either side has zero units on a frontline''' '''Situation description if either side has zero units on a frontline'''
if self.player_zero: if self.player_zero:
return ("We do not have a single vehicle available to hold our position, the situation is" return ("We do not have a single vehicle available to hold our position. The situation is critical, "
"critical, and we will lose ground inevitably.") f"and we will lose ground inevitably betweeen {self.player_base.name} and {self.enemy_base.name}")
elif self.enemy_zero: elif self.enemy_zero:
return ("The enemy forces have been crushed, we will be able to make significant progress" return ("The enemy forces have been crushed, we will be able to make significant progress"
f" toward {self.enemy_base.name}.") f" toward {self.enemy_base.name}.")
return None return ''
@property @property
def _advantage_description(self) -> str: def _advantage_description(self) -> str:
'''Situation description for when player has numerical advantage on the frontline''' '''Situation description for when player has a numerical advantage
Returns:
str
'''
if self.stance == CombatStance.AGGRESSIVE: if self.stance == CombatStance.AGGRESSIVE:
return ( return (
"On this location, our ground forces will try to make " "On this location, our ground forces will try to make "
@ -94,9 +98,15 @@ class FrontLineInfo:
return '' return ''
else: else:
logging.warning('Briefing did not receive a known CombatStance') logging.warning('Briefing did not receive a known CombatStance')
return ''
@property @property
def _disadvantage_description(self): def _disadvantage_description(self) -> str:
'''Situation description for when player has a numerical disadvantage
Returns:
str
'''
if self.stance == CombatStance.AGGRESSIVE: if self.stance == CombatStance.AGGRESSIVE:
return ( return (
"On this location, our ground forces will try an audacious " "On this location, our ground forces will try an audacious "
@ -107,7 +117,7 @@ class FrontLineInfo:
return ( return (
"On this location, our ground forces will try an audacious assault against " "On this location, our ground forces will try an audacious assault against "
"enemies in superior numbers. The operation is risky, and the enemy might " "enemies in superior numbers. The operation is risky, and the enemy might "
"counter attack.\n" "counter attack."
) )
elif self.stance == CombatStance.BREAKTHROUGH: elif self.stance == CombatStance.BREAKTHROUGH:
return ( return (
@ -124,9 +134,15 @@ class FrontLineInfo:
return '' return ''
else: else:
logging.warning('Briefing did not receive a known CombatStance') logging.warning('Briefing did not receive a known CombatStance')
return ''
@property @property
def brief(self): def brief(self) -> str:
'''Situation briefing string
Returns:
str
'''
if self._zero_units_sentence: if self._zero_units_sentence:
return self._zero_units_sentence return self._zero_units_sentence
situation = self._random_frontline_sentence situation = self._random_frontline_sentence
@ -143,8 +159,9 @@ class MissionInfoGenerator:
Examples of subtypes include briefing generators, kneeboard generators, etc. Examples of subtypes include briefing generators, kneeboard generators, etc.
""" """
def __init__(self, mission: Mission) -> None: def __init__(self, mission: Mission, game: Optional['Game'] = None) -> None:
self.mission = mission self.mission = mission
self.game = game
self.awacs: List[AwacsInfo] = [] self.awacs: List[AwacsInfo] = []
self.comms: List[CommInfo] = [] self.comms: List[CommInfo] = []
self.flights: List[FlightData] = [] self.flights: List[FlightData] = []
@ -218,9 +235,8 @@ class MissionInfoGenerator:
class BriefingGenerator(MissionInfoGenerator): class BriefingGenerator(MissionInfoGenerator):
def __init__(self, mission: Mission, game: 'Game'): def __init__(self, mission: Mission, game: 'Game'):
super().__init__(mission) super().__init__(mission, game)
# self.conflict = conflict # self.conflict = conflict
self.game = game
self.title = "" self.title = ""
self.description = "" self.description = ""
self.allied_flights_by_departure: Dict[str, List[FlightData]] = {} self.allied_flights_by_departure: Dict[str, List[FlightData]] = {}
@ -234,18 +250,16 @@ class BriefingGenerator(MissionInfoGenerator):
) )
self.template = env.get_template('briefingtemplate_EN.j2') self.template = env.get_template('briefingtemplate_EN.j2')
def generate(self): def generate(self) -> None:
'''Generate the mission briefing '''Generate the mission briefing
''' '''
self._generate_frontline_info() self._generate_frontline_info()
self.generate_allied_flights_by_departure() self.generate_allied_flights_by_departure()
with open('testgen.txt', 'w') as file:
file.write(self.template.render(vars(self)))
self.mission.set_description_text(self.template.render(vars(self))) self.mission.set_description_text(self.template.render(vars(self)))
self.mission.add_picture_blue(os.path.abspath( self.mission.add_picture_blue(os.path.abspath(
"./resources/ui/splash_screen.png")) "./resources/ui/splash_screen.png"))
def _generate_frontline_info(self): def _generate_frontline_info(self) -> None:
'''Build FrontLineInfo objects from FrontLine type and append to briefing. '''Build FrontLineInfo objects from FrontLine type and append to briefing.
''' '''
for front_line in self.game.theater.conflicts(from_player=True): for front_line in self.game.theater.conflicts(from_player=True):