From 86cfa9a8d864b8f89417663212317bd115880483 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Wed, 23 Oct 2024 14:04:06 -0300 Subject: [PATCH] some fixes --- packages/flame_console/LICENSE | 23 ++++++++++++++++++- packages/flame_console/example/.gitignore | 2 ++ .../example/devtools_options.yaml | 3 --- packages/flame_console/example/lib/main.dart | 2 +- .../lib/src/commands/commands.dart | 15 ++++++------ .../lib/src/commands/debug_command.dart | 3 +++ .../lib/src/commands/ls_command.dart | 3 +++ .../lib/src/commands/pause_command.dart | 3 +++ .../lib/src/commands/remove_command.dart | 3 +++ .../lib/src/commands/resume_command.dart | 3 +++ .../src/repository/debug_command_test.dart | 1 - .../lib/src/view/console_view.dart | 16 +++++++++---- .../flame_console/test/src/commands_test.dart | 3 +++ 13 files changed, 62 insertions(+), 18 deletions(-) delete mode 100644 packages/flame_console/example/devtools_options.yaml delete mode 100644 packages/flame_console/lib/src/repository/debug_command_test.dart diff --git a/packages/flame_console/LICENSE b/packages/flame_console/LICENSE index ba75c69f7f2..3897c4d092d 100644 --- a/packages/flame_console/LICENSE +++ b/packages/flame_console/LICENSE @@ -1 +1,22 @@ -TODO: Add your license here. +MIT License + +Copyright (c) 2021 Blue Fire + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/packages/flame_console/example/.gitignore b/packages/flame_console/example/.gitignore index 29a3a5017f0..18c4f270eb7 100644 --- a/packages/flame_console/example/.gitignore +++ b/packages/flame_console/example/.gitignore @@ -41,3 +41,5 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +devtools_options.yaml diff --git a/packages/flame_console/example/devtools_options.yaml b/packages/flame_console/example/devtools_options.yaml deleted file mode 100644 index fa0b357c4f4..00000000000 --- a/packages/flame_console/example/devtools_options.yaml +++ /dev/null @@ -1,3 +0,0 @@ -description: This file stores settings for Dart & Flutter DevTools. -documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states -extensions: diff --git a/packages/flame_console/example/lib/main.dart b/packages/flame_console/example/lib/main.dart index 1f746c6ef80..bfcf5bbe2b0 100644 --- a/packages/flame_console/example/lib/main.dart +++ b/packages/flame_console/example/lib/main.dart @@ -1,6 +1,6 @@ -import 'package:example/game.dart'; import 'package:flame/game.dart'; import 'package:flame_console/flame_console.dart'; +import 'package:flame_console_example/game.dart'; import 'package:flutter/material.dart'; void main() { diff --git a/packages/flame_console/lib/src/commands/commands.dart b/packages/flame_console/lib/src/commands/commands.dart index f160a5a1716..2a83949e36b 100644 --- a/packages/flame_console/lib/src/commands/commands.dart +++ b/packages/flame_console/lib/src/commands/commands.dart @@ -12,6 +12,7 @@ export 'remove_command.dart'; abstract class ConsoleCommand { ArgParser get parser; String get description; + String get name; List listAllChildren(Component component) { return [ @@ -103,11 +104,11 @@ abstract class QueryCommand extends ConsoleCommand { } class ConsoleCommands { - static Map commands = { - 'ls': LsConsoleCommand(), - 'rm': RemoveConsoleCommand(), - 'debug': DebugConsoleCommand(), - 'pause': PauseConsoleCommand(), - 'resume': ResumeConsoleCommand(), - }; + static List commands = [ + LsConsoleCommand(), + RemoveConsoleCommand(), + DebugConsoleCommand(), + PauseConsoleCommand(), + ResumeConsoleCommand(), + ]; } diff --git a/packages/flame_console/lib/src/commands/debug_command.dart b/packages/flame_console/lib/src/commands/debug_command.dart index a92ee40e820..6bb1df6de27 100644 --- a/packages/flame_console/lib/src/commands/debug_command.dart +++ b/packages/flame_console/lib/src/commands/debug_command.dart @@ -11,6 +11,9 @@ class DebugConsoleCommand extends QueryCommand { return (null, ''); } + @override + String get name => 'debug'; + @override String get description => 'Toggle debug mode on the matched components.'; } diff --git a/packages/flame_console/lib/src/commands/ls_command.dart b/packages/flame_console/lib/src/commands/ls_command.dart index 7fa737df5fb..43a47317918 100644 --- a/packages/flame_console/lib/src/commands/ls_command.dart +++ b/packages/flame_console/lib/src/commands/ls_command.dart @@ -14,6 +14,9 @@ class LsConsoleCommand extends QueryCommand { return (null, out.toString()); } + @override + String get name => 'ls'; + @override String get description => 'List components that match the query arguments.'; } diff --git a/packages/flame_console/lib/src/commands/pause_command.dart b/packages/flame_console/lib/src/commands/pause_command.dart index 515bf997844..84d459949d4 100644 --- a/packages/flame_console/lib/src/commands/pause_command.dart +++ b/packages/flame_console/lib/src/commands/pause_command.dart @@ -16,6 +16,9 @@ class PauseConsoleCommand extends ConsoleCommand { @override ArgParser get parser => ArgParser(); + @override + String get name => 'pause'; + @override String get description => 'Pauses the game loop.'; } diff --git a/packages/flame_console/lib/src/commands/remove_command.dart b/packages/flame_console/lib/src/commands/remove_command.dart index 139bfbacfff..d320b63822b 100644 --- a/packages/flame_console/lib/src/commands/remove_command.dart +++ b/packages/flame_console/lib/src/commands/remove_command.dart @@ -11,6 +11,9 @@ class RemoveConsoleCommand extends QueryCommand { return (null, ''); } + @override + String get name => 'rm'; + @override String get description => 'Removes components that match the query arguments.'; diff --git a/packages/flame_console/lib/src/commands/resume_command.dart b/packages/flame_console/lib/src/commands/resume_command.dart index a3004fd4bad..b5bb0e7a13b 100644 --- a/packages/flame_console/lib/src/commands/resume_command.dart +++ b/packages/flame_console/lib/src/commands/resume_command.dart @@ -16,6 +16,9 @@ class ResumeConsoleCommand extends ConsoleCommand { @override ArgParser get parser => ArgParser(); + @override + String get name => 'resume'; + @override String get description => 'Resumes the game loop.'; } diff --git a/packages/flame_console/lib/src/repository/debug_command_test.dart b/packages/flame_console/lib/src/repository/debug_command_test.dart deleted file mode 100644 index 8b137891791..00000000000 --- a/packages/flame_console/lib/src/repository/debug_command_test.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/flame_console/lib/src/view/console_view.dart b/packages/flame_console/lib/src/view/console_view.dart index 793e2f22b8e..9878eef5897 100644 --- a/packages/flame_console/lib/src/view/console_view.dart +++ b/packages/flame_console/lib/src/view/console_view.dart @@ -35,7 +35,7 @@ class ConsoleView extends StatefulWidget { }) : repository = repository ?? const MemoryConsoleRepository(); final G game; - final Map>? customCommands; + final List>? customCommands; final VoidCallback onClose; final ConsoleRepository repository; final ConsoleController? controller; @@ -64,16 +64,22 @@ class _ConsoleKeyboardHandler extends Component with KeyboardHandler { } class _ConsoleViewState extends State { + late final List _commandList = [ + ...ConsoleCommands.commands, + if (widget.customCommands != null) ...widget.customCommands!, + ]; + + late final Map _commandsMap = { + for (final command in _commandList) command.name: command, + }; + late final _controller = widget.controller ?? ConsoleController( repository: widget.repository, game: widget.game, scrollController: _scrollController, onClose: widget.onClose, - commands: { - ...ConsoleCommands.commands, - if (widget.customCommands != null) ...widget.customCommands!, - }, + commands: _commandsMap, ); late final _scrollController = ScrollController(); diff --git a/packages/flame_console/test/src/commands_test.dart b/packages/flame_console/test/src/commands_test.dart index b7a0525134c..73b92aa08b2 100644 --- a/packages/flame_console/test/src/commands_test.dart +++ b/packages/flame_console/test/src/commands_test.dart @@ -10,6 +10,9 @@ class _NoopCommand extends ConsoleCommand { @override String get description => ''; + @override + String get name => ''; + @override (String?, String) execute(FlameGame game, ArgResults results) { return (null, '');