From 114078c31d24708ceb1c692fdb7625684fab5201 Mon Sep 17 00:00:00 2001 From: alanwatsonforster <68709385+alanwatsonforster@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:40:05 -0600 Subject: [PATCH] Factored out position code. --- airpower/aircraft/__init__.py | 14 ++++++++++++++ airpower/aircraft/_log.py | 13 +------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/airpower/aircraft/__init__.py b/airpower/aircraft/__init__.py index c2ed7f0e..02fa6c02 100644 --- a/airpower/aircraft/__init__.py +++ b/airpower/aircraft/__init__.py @@ -87,6 +87,20 @@ def __str__(self): s += "%-16s: %s\n" % (x[0], x[1]) return s + def position(self): + + if apmap.isonmap(self._x, self._y): + sheet = apmap.tosheet(self._x, self._y) + hexcode = aphexcode.fromxy(self._x, self._y) + else: + sheet = "--" + hexcode = "----" + azimuth = apazimuth.fromfacing(self._facing) + altitude = self._altitude + altitudeband = self._altitudeband + return "%2s %-9s %-3s %2d %2s" % (sheet, hexcode, azimuth, altitude, altitudeband) + + ############################################################################# def checkforterraincollision(self): diff --git a/airpower/aircraft/_log.py b/airpower/aircraft/_log.py index f2826c28..e8974b58 100644 --- a/airpower/aircraft/_log.py +++ b/airpower/aircraft/_log.py @@ -16,18 +16,7 @@ def _logbreak(self): def _logposition(self, s, t): - if apmap.isonmap(self._x, self._y): - sheet = apmap.tosheet(self._x, self._y) - hexcode = aphexcode.fromxy(self._x, self._y) - else: - sheet = "--" - hexcode = "----" - azimuth = apazimuth.fromfacing(self._facing) - altitude = self._altitude - altitudeband = self._altitudeband - position = "%2s %-9s %-3s %2d %2s" % (sheet, hexcode, azimuth, altitude, altitudeband) - - self._log("%-5s : %-16s : %s" % (s, t, position)) + self._log("%-5s : %-16s : %s" % (s, t, self.position())) def _logevent(self, s): self._log("%-5s : %s" % ("", s))