diff --git a/apps/wolf_3d_cli/lib/cli_game_loop.dart b/apps/wolf_3d_cli/lib/cli_game_loop.dart index 0b0e8a6..a49cea5 100644 --- a/apps/wolf_3d_cli/lib/cli_game_loop.dart +++ b/apps/wolf_3d_cli/lib/cli_game_loop.dart @@ -162,6 +162,13 @@ class CliGameLoop { return; } + if (input.matchesFpsToggleShortcut(bytes)) { + engine.toggleFpsCounter(); + _syncRendererFromEngine(); + unawaited(persistence?.save(engine.rendererSettings)); + return; + } + input.handleKey(bytes); } diff --git a/packages/wolf_3d_dart/lib/src/input/cli_input.dart b/packages/wolf_3d_dart/lib/src/input/cli_input.dart index feed119..1d1ce6c 100644 --- a/packages/wolf_3d_dart/lib/src/input/cli_input.dart +++ b/packages/wolf_3d_dart/lib/src/input/cli_input.dart @@ -12,6 +12,9 @@ class CliInput extends Wolf3dInput { /// Keyboard shortcut used by the CLI host to cycle ASCII themes. String asciiThemeCycleKey = 't'; + /// Keyboard shortcut used by the CLI host to toggle the FPS counter. + String fpsToggleKey = '`'; + /// Human-friendly label for [rendererToggleKey] shown in CLI hints. String get rendererToggleKeyLabel => _formatShortcutLabel(rendererToggleKey); @@ -19,6 +22,9 @@ class CliInput extends Wolf3dInput { String get asciiThemeCycleKeyLabel => _formatShortcutLabel(asciiThemeCycleKey); + /// Human-friendly label for [fpsToggleKey] shown in CLI hints. + String get fpsToggleKeyLabel => _formatShortcutLabel(fpsToggleKey); + /// Returns true when [bytes] triggers the renderer-toggle shortcut. bool matchesRendererToggleShortcut(List bytes) => _matchesShortcut(bytes, rendererToggleKey); @@ -27,6 +33,10 @@ class CliInput extends Wolf3dInput { bool matchesAsciiThemeCycleShortcut(List bytes) => _matchesShortcut(bytes, asciiThemeCycleKey); + /// Returns true when [bytes] triggers the FPS-toggle shortcut. + bool matchesFpsToggleShortcut(List bytes) => + _matchesShortcut(bytes, fpsToggleKey); + String _formatShortcutLabel(String key) { final String trimmed = key.trim(); if (trimmed.isEmpty) { diff --git a/packages/wolf_3d_dart/test/input/cli_input_shortcuts_test.dart b/packages/wolf_3d_dart/test/input/cli_input_shortcuts_test.dart new file mode 100644 index 0000000..395827b --- /dev/null +++ b/packages/wolf_3d_dart/test/input/cli_input_shortcuts_test.dart @@ -0,0 +1,21 @@ +import 'package:test/test.dart'; +import 'package:wolf_3d_dart/wolf_3d_input.dart'; + +void main() { + group('CliInput shortcuts', () { + test('matches default FPS toggle shortcut with backtick', () { + final input = CliInput(); + + expect(input.matchesFpsToggleShortcut(const [96]), isTrue); + expect(input.matchesFpsToggleShortcut(const [126]), isFalse); + expect(input.matchesFpsToggleShortcut(const [114]), isFalse); + }); + + test('matches renderer shortcut case-insensitively', () { + final input = CliInput(); + + expect(input.matchesRendererToggleShortcut(const [114]), isTrue); + expect(input.matchesRendererToggleShortcut(const [82]), isTrue); + }); + }); +}