Commit cf426ef5 authored by Terence Martin's avatar Terence Martin

Clean up debugging calls

Shift the onus of checking to see if debugging is turned on or not
from the calling class to the MazeDebugger class, which leaves without
doing anything if debugging is not turned on.

A boolean return tells you if anything was done or not, so that the
Scene can eat keys as needed.
parent 1bcd5b79
This diff is collapsed.
......@@ -159,20 +159,25 @@ module nurdz.game
}
/**
* DEBUG METHOD
*
* Remove the contents of an existing cell from the maze, returning the
* object back into its pool.
*
* This currently does not work on Teleport entities, since they need
* special action to work.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugClearCell () : void
debugClearCell () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// Get the debug cell and leave if there isn't one.
let cell = this.getDebugCell ();
if (cell == null)
return;
return true;
// There is a single Teleport entity, so all we have to do is remove
// the current location as a destination.
......@@ -190,41 +195,55 @@ module nurdz.game
else
{
console.log ("Cannot delete boundary bricks");
return;
return true;
}
// Clear the contents of the cell now.
this.setDebugCell (null);
return true;
}
/**
* Wipe the entire contents of the maze, killing all entities. This will
* leave only the bounding bricks that stop the ball from going out of
* bounds.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugWipeMaze ()
debugWipeMaze () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// Reset all entities, then generate walls into the maze to clear it
// back to a known state.
this._maze.resetMazeEntities ();
this._maze.generator.emptyMaze ();
return true;
}
/**
* DEBUG METHOD
*
* Toggle an existing cell through its subtypes (for cells that support
* this).
*
* If the debug point is empty or not of a toggle-able type, this does
* nothing.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugToggleCell () : void
debugToggleCell () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// Get the debug cell and leave if there isn't one.
let cell = this.getDebugCell ();
if (cell == null)
return;
return true;
// If the cell is an arrow, toggle the type. Doing this will also
// implicitly set an auto-flip timer on the arrow when it becomes
......@@ -236,7 +255,7 @@ module nurdz.game
arrow.arrowType = ArrowType.ARROW_NORMAL;
else
arrow.arrowType = ArrowType.ARROW_AUTOMATIC;
return;
return true;
}
// If the cell is a ball, toggle the type.
......@@ -248,7 +267,7 @@ module nurdz.game
else
ball.ballType = BallType.BALL_PLAYER;
ball.appear ();
return;
return true;
}
// If the cell is a brick, toggle the type. This will change the visual
......@@ -283,15 +302,14 @@ module nurdz.game
else
console.log ("Cannot toggle brick; not enough entities in currentBrickPool");
return;
return true;
}
console.log ("Cannot toggle entity; it does not support toggling");
return true;
}
/**
* DEBUG METHOD
*
* Add a brick to the maze at the current debug location (assuming one
* is available).
*
......@@ -299,9 +317,16 @@ module nurdz.game
* in which case it will try to add a bonus brick instead.
*
* If the current location is not empty, this does nothing.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugAddBrick () : void
debugAddBrick () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// We can only add a brick if the current cell is empty.
if (this.getDebugCell () == null)
{
......@@ -322,6 +347,8 @@ module nurdz.game
}
else
console.log ("Cannot add brick; cell is not empty");
return true;
}
/**
......@@ -330,9 +357,16 @@ module nurdz.game
*
* @param {boolean} grayBricks true to vanish gray bricks, false to
* vanish bonus bricks.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugVanishBricks (grayBricks : boolean) : void
debugVanishBricks (grayBricks : boolean) : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
for (let row = 0 ; row < MAZE_HEIGHT ; row++)
{
for (let col = 0 ; col < MAZE_WIDTH ; col++)
......@@ -347,11 +381,11 @@ module nurdz.game
}
}
}
return true;
}
/**
* DEBUG METHOD
*
* Add a teleport destination to the maze at the current debug location
* (assuming one is available).
*
......@@ -359,9 +393,16 @@ module nurdz.game
* just adds another potential destination to the list.
*
* If the current location is not empty, this does nothing.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugAddTeleport () : void
debugAddTeleport () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// We can only add an exit point if the current cell is empty.
if (this.getDebugCell () == null)
{
......@@ -371,11 +412,11 @@ module nurdz.game
}
else
console.log ("Cannot add teleport; cell is not empty");
return true;
}
/**
* DEBUG METHOD
*
* Add an arrow to the maze at the current debug location (assuming one
* is available).
*
......@@ -383,9 +424,16 @@ module nurdz.game
* be toggled with the toggle command.
*
* If the current location is not empty, this does nothing.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugAddArrow () : void
debugAddArrow () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// We can only add an arrow if the current cell is empty.
if (this.getDebugCell () == null)
{
......@@ -403,18 +451,25 @@ module nurdz.game
}
else
console.log ("Cannot add arrow; cell is not empty");
return true;
}
/**
* DEBUG METHOD
*
* Add a player ball to the maze at the current debug location (assuming
* one is available).
*
* If the current location is not empty, this does nothing.
*
* @returns {boolean} true if debugging was turned on and we tried to
* handle the command, false if debugging is turned off.
*/
debugAddBall () : void
debugAddBall () : boolean
{
// Do nothing if tracking is turned off.
if (this._debugTracking == false)
return false;
// We can only add a ball if the current cell is empty.
if (this.getDebugCell () == null)
{
......@@ -432,7 +487,8 @@ module nurdz.game
}
else
console.log ("Cannot add ball; cell is not empty");
}
return true;
}
}
}
\ No newline at end of file
......@@ -11,6 +11,11 @@ module nurdz.game
*/
private _maze : Maze;
/**
* The debugger for our maze. We store a reference to make access easier.
*/
private _debugger : MazeDebugger;
/**
* The last known position of the mouse on the stage.
*/
......@@ -40,6 +45,9 @@ module nurdz.game
// Start out with a default mouse location.
this._mouse = new Point (0, 0);
// Stash the debugger.
this._debugger = this._maze.debugger;
}
/**
......@@ -75,8 +83,8 @@ module nurdz.game
// Toggle mouse tracking of the debug location, then update the
// tracking with the last known mouse location.
case KeyCodes.KEY_SPACEBAR:
this._maze.debugger.debugTracking = !this._maze.debugger.debugTracking;
if (this._maze.debugger.debugTracking)
this._debugger.debugTracking = !this._debugger.debugTracking;
if (this._debugger.debugTracking)
this._maze.setDebugPoint (this._mouse);
return true;
......@@ -88,88 +96,48 @@ module nurdz.game
// delete key on the numeric keypad may or may not work.
case 8:
case 46:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugClearCell ();
return true;
}
break;
return this._debugger.debugClearCell ();
// Toggle the type of the entity under the debug cursor through
// its various states.
case KeyCodes.KEY_T:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugToggleCell ();
return true;
}
break;
return this._debugger.debugToggleCell ();
// Add a brick to the maze at the current debug cursor; this
// only works if the cell is currently empty. This will try
// to add a gray brick, and failing that a bonus brick.
case KeyCodes.KEY_B:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddBrick ();
return true;
}
break;
return this._debugger.debugAddBrick ();
// Add an arrow to the maze at the current debug cursor; this
// only works if the cell is currentlye empty. This will add a
// normal arrow by default, but this can be toggled with the
// 'T" key'.
case KeyCodes.KEY_A:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddArrow ();
return true;
}
break;
return this._debugger.debugAddArrow ();
// Add a teleport to the maze at the current debug cursor; this
// only works if the cell is currentlye empty. This just adds an
// extra exit point to the black hole system.
case KeyCodes.KEY_H:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddTeleport ();
return true;
}
break;
return this._debugger.debugAddTeleport ();
// Add a ball to the maze at the current debug cursor; this only
// works if the cell is currently empty. This will add a player
// ball by default, but this can be toggled with the 'T' key.
case KeyCodes.KEY_L:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddBall ();
return true;
}
break;
return this._debugger.debugAddBall ();
// Vanish away all of the gray or bonus bricks that are still
// visible.
case KeyCodes.KEY_V:
case KeyCodes.KEY_C:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugVanishBricks (eventObj.keyCode == KeyCodes.KEY_V);
return true;
}
break;
return this._debugger.debugVanishBricks (eventObj.keyCode == KeyCodes.KEY_V);
// Wipe the entire maze contents; this is like a reset except
// no new maze is generated first.
case KeyCodes.KEY_W:
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugWipeMaze ();
return true;
}
break;
return this._debugger.debugWipeMaze ();
}
// We did not handle it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment