Skip to content

Commit

Permalink
feat: Refactoring flame_console to use terminui (#3388)
Browse files Browse the repository at this point in the history
Simplify flame_console to use `terminui` instead of implementing the
terminal interface itself.
  • Loading branch information
erickzanardo authored Dec 16, 2024
1 parent 916aa5c commit de74a93
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 398 deletions.
1 change: 1 addition & 0 deletions .github/.cspell/flame_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ vantablack # brand name for a famous super-black ink known as the darkest ever m
Weasley # Ron Weasley, a character from the book Harry Potter
Wyrmsun # An open-source real-time strategy game https://www.indiedb.com/games/wyrmsun
yarnspinner # A tool for building branching narrative and dialogue in games # https://yarnspinner.dev/
terminui # A terminal UI library for Flutter
2 changes: 1 addition & 1 deletion packages/flame_console/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _MyGameAppState extends State<MyGameApp> {
body: GameWidget(
game: _game,
overlayBuilderMap: {
'console': (BuildContext context, MyGame game) => ConsoleView(
'console': (BuildContext context, MyGame game) => FlameConsoleView(
game: game,
onClose: () {
_game.overlays.remove('console');
Expand Down
29 changes: 7 additions & 22 deletions packages/flame_console/lib/src/commands/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import 'package:flame/game.dart';
import 'package:flame_console/src/commands/commands.dart';
import 'package:flame_console/src/commands/pause_command.dart';
import 'package:flame_console/src/commands/resume_command.dart';
import 'package:terminui/terminui.dart';

export 'debug_command.dart';
export 'ls_command.dart';
export 'remove_command.dart';

abstract class ConsoleCommand<G extends FlameGame> {
ArgParser get parser;
String get description;
String get name;

abstract class FlameConsoleCommand<T extends FlameGame>
extends TerminuiCommand<T> {
List<Component> listAllChildren(Component component) {
return [
for (final child in component.children) ...[
Expand Down Expand Up @@ -50,23 +48,10 @@ abstract class ConsoleCommand<G extends FlameGame> {
}
}
}

(String?, String) run(G game, List<String> args) {
final results = parser.parse(args);
return execute(game, results);
}

(String?, String) execute(G game, ArgResults results);

int? optionalIntResult(String key, ArgResults results) {
if (results[key] != null) {
return int.tryParse(results[key] as String);
}
return null;
}
}

abstract class QueryCommand<G extends FlameGame> extends ConsoleCommand<G> {
abstract class QueryCommand<G extends FlameGame>
extends FlameConsoleCommand<G> {
(String?, String) processChildren(List<Component> children);

@override
Expand Down Expand Up @@ -100,8 +85,8 @@ abstract class QueryCommand<G extends FlameGame> extends ConsoleCommand<G> {
);
}

class ConsoleCommands {
static List<ConsoleCommand> commands = [
class FlameConsoleCommands {
static List<FlameConsoleCommand> commands = [
LsConsoleCommand(),
RemoveConsoleCommand(),
DebugConsoleCommand(),
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_console/lib/src/commands/pause_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:args/args.dart';
import 'package:flame/game.dart';
import 'package:flame_console/flame_console.dart';

class PauseConsoleCommand<G extends FlameGame> extends ConsoleCommand<G> {
class PauseConsoleCommand<G extends FlameGame> extends FlameConsoleCommand<G> {
@override
(String?, String) execute(G game, ArgResults results) {
if (game.paused) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:args/args.dart';
import 'package:flame/game.dart';
import 'package:flame_console/flame_console.dart';

class ResumeConsoleCommand<G extends FlameGame> extends ConsoleCommand<G> {
class ResumeConsoleCommand<G extends FlameGame> extends FlameConsoleCommand<G> {
@override
(String?, String) execute(G game, ArgResults results) {
if (!game.paused) {
Expand Down
172 changes: 0 additions & 172 deletions packages/flame_console/lib/src/controller.dart

This file was deleted.

1 change: 0 additions & 1 deletion packages/flame_console/lib/src/flame_console.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'commands/commands.dart';
export 'repository/repository.dart';
export 'view/view.dart';

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions packages/flame_console/lib/src/repository/repository.dart

This file was deleted.

Loading

0 comments on commit de74a93

Please sign in to comment.