Skip to content

Commit

Permalink
Optional step after console command (#1910)
Browse files Browse the repository at this point in the history
+ console cleanup
  • Loading branch information
MSGhero authored and Gama11 committed Aug 21, 2016
1 parent 3e4c653 commit e802c61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
9 changes: 3 additions & 6 deletions flixel/system/debug/console/Console.hx
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ class Console extends Window
#end

#if FLX_DEBUG
#if flash
// Pause game
if (FlxG.console.autoPause)
FlxG.vcr.pause();
#end

// Block keyboard input
#if FLX_KEYBOARD
Expand All @@ -174,11 +172,10 @@ class Console extends Window
#end

#if FLX_DEBUG
#if flash
// Unpause game
if (FlxG.console.autoPause)
FlxG.vcr.resume();
#end

// Unblock keyboard input
#if FLX_KEYBOARD
FlxG.keys.enabled = true;
Expand Down Expand Up @@ -246,8 +243,8 @@ class Console extends Window
history.addCommand(input.text);

// Step forward one frame to see the results of the command
#if (flash && FLX_DEBUG)
if (FlxG.vcr.paused)
#if FLX_DEBUG
if (FlxG.vcr.paused && FlxG.console.stepAfterCommand)
FlxG.game.debugger.vcr.onStep();
#end

Expand Down
11 changes: 7 additions & 4 deletions flixel/system/debug/console/ConsoleCommands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ConsoleCommands

public function new(console:Console):Void
{
#if FLX_DEBUG
_console = console;

console.registerFunction("help", help, "Displays the help text of a registered object or function. See \"help\".");
Expand All @@ -32,6 +31,7 @@ class ConsoleCommands
console.registerFunction("listObjects", listObjects, "Lists the aliases of all registered objects.");
console.registerFunction("listFunctions", listFunctions, "Lists the aliases of all registered functions.");

console.registerFunction("step", step, "Steps the game forward one frame if currently paused. No effect if unpaused.");
console.registerFunction("pause", pause, "Toggles the game between paused and unpaused.");

console.registerFunction("clearBitmapLog", FlxG.bitmapLog.clear, "Clears the bitmapLog window.");
Expand All @@ -58,7 +58,6 @@ class ConsoleCommands
console.registerClass(FlxSprite);
console.registerClass(FlxMath);
console.registerClass(FlxTween);
#end
}

private function help(?Alias:String):String
Expand Down Expand Up @@ -91,7 +90,6 @@ class ConsoleCommands
}
}

#if FLX_DEBUG
private inline function close():Void
{
FlxG.debugger.visible = false;
Expand Down Expand Up @@ -172,6 +170,11 @@ class ConsoleCommands
ConsoleUtil.log("pause: Game paused");
}
}
#end

private function step():Void
{
if (FlxG.vcr.paused)
FlxG.game.debugger.vcr.onStep();
}
}
#end
6 changes: 6 additions & 0 deletions flixel/system/frontEnds/ConsoleFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class ConsoleFrontEnd
*/
public var autoPause:Bool = true;

/**
* Whether the console should step() the game after a command is entered.
* Setting this to false allows inputting multiple console commands within the same frame. Use the "step()" command to step the game from the console.
*/
public var stepAfterCommand:Bool = true;

/**
* Register a new function to use in any command.
*
Expand Down

0 comments on commit e802c61

Please sign in to comment.