Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Oct 23, 2024
1 parent be7b157 commit 86cfa9a
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 18 deletions.
23 changes: 22 additions & 1 deletion packages/flame_console/LICENSE
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions packages/flame_console/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

devtools_options.yaml
3 changes: 0 additions & 3 deletions packages/flame_console/example/devtools_options.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/flame_console/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
15 changes: 8 additions & 7 deletions packages/flame_console/lib/src/commands/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'remove_command.dart';
abstract class ConsoleCommand<G extends FlameGame> {
ArgParser get parser;
String get description;
String get name;

List<Component> listAllChildren(Component component) {
return [
Expand Down Expand Up @@ -103,11 +104,11 @@ abstract class QueryCommand<G extends FlameGame> extends ConsoleCommand<G> {
}

class ConsoleCommands {
static Map<String, ConsoleCommand> commands = {
'ls': LsConsoleCommand(),
'rm': RemoveConsoleCommand(),
'debug': DebugConsoleCommand(),
'pause': PauseConsoleCommand(),
'resume': ResumeConsoleCommand(),
};
static List<ConsoleCommand> commands = [
LsConsoleCommand(),
RemoveConsoleCommand(),
DebugConsoleCommand(),
PauseConsoleCommand(),
ResumeConsoleCommand(),
];
}
3 changes: 3 additions & 0 deletions packages/flame_console/lib/src/commands/debug_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class DebugConsoleCommand<G extends FlameGame> extends QueryCommand<G> {
return (null, '');
}

@override
String get name => 'debug';

@override
String get description => 'Toggle debug mode on the matched components.';
}
3 changes: 3 additions & 0 deletions packages/flame_console/lib/src/commands/ls_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class LsConsoleCommand<G extends FlameGame> extends QueryCommand<G> {
return (null, out.toString());
}

@override
String get name => 'ls';

@override
String get description => 'List components that match the query arguments.';
}
3 changes: 3 additions & 0 deletions packages/flame_console/lib/src/commands/pause_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class PauseConsoleCommand<G extends FlameGame> extends ConsoleCommand<G> {
@override
ArgParser get parser => ArgParser();

@override
String get name => 'pause';

@override
String get description => 'Pauses the game loop.';
}
3 changes: 3 additions & 0 deletions packages/flame_console/lib/src/commands/remove_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class RemoveConsoleCommand<G extends FlameGame> extends QueryCommand<G> {
return (null, '');
}

@override
String get name => 'rm';

@override
String get description =>
'Removes components that match the query arguments.';
Expand Down
3 changes: 3 additions & 0 deletions packages/flame_console/lib/src/commands/resume_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ResumeConsoleCommand<G extends FlameGame> extends ConsoleCommand<G> {
@override
ArgParser get parser => ArgParser();

@override
String get name => 'resume';

@override
String get description => 'Resumes the game loop.';
}

This file was deleted.

16 changes: 11 additions & 5 deletions packages/flame_console/lib/src/view/console_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConsoleView<G extends FlameGame> extends StatefulWidget {
}) : repository = repository ?? const MemoryConsoleRepository();

final G game;
final Map<String, ConsoleCommand<G>>? customCommands;
final List<ConsoleCommand<G>>? customCommands;
final VoidCallback onClose;
final ConsoleRepository repository;
final ConsoleController? controller;
Expand Down Expand Up @@ -64,16 +64,22 @@ class _ConsoleKeyboardHandler extends Component with KeyboardHandler {
}

class _ConsoleViewState extends State<ConsoleView> {
late final List<ConsoleCommand> _commandList = [
...ConsoleCommands.commands,
if (widget.customCommands != null) ...widget.customCommands!,
];

late final Map<String, ConsoleCommand> _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();
Expand Down
3 changes: 3 additions & 0 deletions packages/flame_console/test/src/commands_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class _NoopCommand extends ConsoleCommand {
@override
String get description => '';

@override
String get name => '';

@override
(String?, String) execute(FlameGame<World> game, ArgResults results) {
return (null, '');
Expand Down

0 comments on commit 86cfa9a

Please sign in to comment.