Skip to content

Commit

Permalink
[IMP] Improve debug information.
Browse files Browse the repository at this point in the history
  • Loading branch information
japinol7 committed Mar 24, 2024
1 parent 8174def commit 150fe0f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
^h: shows this help to the console

> Additional keys for debug mode:
^ numpad_divide: set logger to debug. Print info for hits, etc
^ L_Alt + numpad_divide: toggle logger to debug/info. Print info for hits, etc
^ n: print a list of all NPCs in all levels, ordered by level
^ + shifth + n: print a list of all NPCs in all levels, ordered by NPC name
^d: print debug information to the console
Expand Down Expand Up @@ -326,6 +326,8 @@
using the full screen display mode.
-d, --debug
debug actions, information and traces
This does not set the log level to debug.
Use the key shortcut ^ L_Alt + numpad_divide to toggle log levels.
-t, --debugtraces
show debug back traces information when something goes wrong

Expand Down
4 changes: 3 additions & 1 deletion codemaster/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def main():
'In most systems, is better to have the scaling activated when '
'using the full screen display mode')
parser.add_argument('-d', '--debug', default=None, action='store_true',
help='Debug actions, information and traces')
help='Debug actions, information and traces. '
'This does not set the log level to debug. '
'Use the key shortcut ^ L_Alt + numpad_divide to toggle log levels')
parser.add_argument('-t', '--debugtraces', default=None, action='store_true',
help='Show debug back traces information when something goes wrong')
args = parser.parse_args()
Expand Down
7 changes: 4 additions & 3 deletions codemaster/game_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ def start(self):
elif event.key == pg.K_n:
if self.is_debug and pg.key.get_mods() & pg.KMOD_LCTRL and pg.key.get_mods() & pg.KMOD_LSHIFT:
log.info("NPCs health from all levels, ordered by NPC name:")
utils.pretty_dict_print(NPC.get_npcs_health(self, sorted_by_level=False))
log.debug(utils.pretty_dict_to_string(NPC.get_npcs_health(self, sorted_by_level=False)))
elif self.is_debug and pg.key.get_mods() & pg.KMOD_LCTRL:
log.info("NPCs health from all levels, ordered by level:")
utils.pretty_dict_print(NPC.get_npcs_health(self))
log.debug(utils.pretty_dict_to_string(NPC.get_npcs_health(self)))
elif event.key == pg.K_h:
if pg.key.get_mods() & pg.KMOD_LCTRL:
self.help_info.print_help_keys()
Expand All @@ -377,7 +377,8 @@ def start(self):
self.is_paused = True
self.is_full_screen_switch = True
elif event.key == pg.K_KP_DIVIDE:
if self.is_debug and pg.key.get_mods() & pg.KMOD_LCTRL:
if self.is_debug and pg.key.get_mods() & pg.KMOD_LCTRL \
and pg.key.get_mods() & pg.KMOD_LALT:
self.player.debug = not self.player.debug
if log.level != logging.DEBUG:
log.setLevel(logging.DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion codemaster/models/actors/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def get_npcs_health(game, sorted_by_level=True):
f"level: {level.name:4}", f"{level.id + 1:3d}")
if sorted_by_level:
return OrderedDict(sorted([x for x in res.items()], key=lambda x: (x[1][3], x[0])))
return OrderedDict(sorted([x for x in res.items()]))
return OrderedDict(sorted([x for x in res.items()], key=lambda x: (x[0], x[1][3])))


class PC(MovingActor):
Expand Down
6 changes: 3 additions & 3 deletions codemaster/tools/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def pretty_dict_print(d, indent=0):
print('\t' * (indent + 1), '{:>10}'.format(str(value)))


def pretty_dict_to_string(d, indent=0, with_last_new_line=False, res='', firt_time=True):
def pretty_dict_to_string(d, indent=0, with_last_new_line=False, res='', first_time=True):
for key, value in d.items():
res = '%s%s%s%s' % (res, '\t' * indent, f"{str(key):22}", '-->')
if isinstance(value, dict):
res = '%s\n' % res
res = '%s%s' % (res, pretty_dict_to_string(value, indent + 1, res='', firt_time=False))
res = '%s%s' % (res, pretty_dict_to_string(value, indent + 1, res='', first_time=False))
else:
res = '{}{}{:>10}\n'.format(res, '\t' * (indent + 1), str(value))
if firt_time and not with_last_new_line:
if first_time and not with_last_new_line:
res = res[:-1]
return res

Expand Down
10 changes: 5 additions & 5 deletions suiteoftests/test_code_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from codemaster.models.actors.items import ClockTimerA
from codemaster.models.actors.player import Player
from codemaster.config.constants import (
APP_NAME,
APP_TECH_NAME,
FONT_DEFAULT_NAME, FONT_FIXED_DEFAULT_NAME
)
from codemaster.models.actors.text_msgs import TextMsg
Expand All @@ -26,10 +26,10 @@
PLAYER_HEALTH_SUPER_HERO = 90_000
CLOCK_TIMER_IN_SECS = 10

LOG_START_TEST_APP_MSG = f"Test app {APP_NAME} version: {version.get_version()}"
LOG_END_TEST_APP_MSG = f"End Testing {APP_NAME}"
LOG_START_TEST_APP_MSG = f"Test app {APP_TECH_NAME} version: {version.get_version()}"
LOG_END_TEST_APP_MSG = f"End Testing {APP_TECH_NAME}"

IN_GAME_START_MSG = f"Let's test app {APP_NAME}\nversion: {version.get_version()}"
IN_GAME_START_MSG = f"Let's test app {APP_TECH_NAME}\nversion: {version.get_version()}"

GROUP_DASHES_LINE = f"{'-' * 62}"
DASHES_LINE_SHORT = f"{'-' * 20}"
Expand Down Expand Up @@ -141,7 +141,7 @@ def set_up(self):
self.player.start_time = self.start_time
self.player.stats['levels_visited'].add(self.level.id)

pg.display.set_caption(f"{APP_NAME}_test_suite")
pg.display.set_caption(f"{APP_TECH_NAME}_test_suite")

def tear_down(self):
levels.Level.clean_entity_ids()
Expand Down

0 comments on commit 150fe0f

Please sign in to comment.