Commit 1bcd5b79 authored by Terence Martin's avatar Terence Martin

Shift debug flag to the debugger object

This moves the flag that says if the debugger is turned on or not into
the debug object itself. This lengthens the code a bit but finishes the
isolation.
parent 272b499a
......@@ -916,6 +916,9 @@ var nurdz;
this._teleport = null;
// Create a default debug point.
this._debugPoint = new game.Point(0, 0);
// No debugging by default, but the debugging point is the upper
// left grid corner;.
this._debugTracking = false;
}
Object.defineProperty(MazeDebugger.prototype, "wall", {
/**
......@@ -964,6 +967,28 @@ var nurdz;
enumerable: true,
configurable: true
});
Object.defineProperty(MazeDebugger.prototype, "debugTracking", {
/**
* Get the current state of the debug tracking variable.
*
* When this is set to true, we display a marker on the stage at the
* current debug position.
*
* @returns {boolean} true if debugging is enabled, false otherwise.
*/
get: function () { return this._debugTracking; },
/**
* Change the current state of the debug tracking variable.
*
* True enables debugging, which causes the maze to display a red marker
* at the current debug location.
*
* @param {boolean} newValue new debugging state
*/
set: function (newValue) { this._debugTracking = newValue; },
enumerable: true,
configurable: true
});
/**
* Get the cell at the current debug location in the maze grid.
*
......@@ -2544,33 +2569,7 @@ var nurdz;
// exactly how many entities of a type we need.
for (var i = 0; i < (game.MAZE_WIDTH - 2) * 2; i++)
this._balls.addEntity(new game.Ball(stage), false);
// No debugging by default, but the debugging point is the upper
// left grid corner; the marker is created later when we know the
// grid size.
this._debugTracking = false;
}
Object.defineProperty(Maze.prototype, "debugTracking", {
/**
* Get the current state of the debug tracking variable.
*
* When this is set to true, we display a marker on the stage at the
* current debug position.
*
* @returns {boolean} true if debugging is enabled, false otherwise.
*/
get: function () { return this._debugTracking; },
/**
* Change the current state of the debug tracking variable.
*
* True enables debugging, which causes the maze to display a red marker
* at the current debug location.
*
* @param {boolean} newValue new debugging state
*/
set: function (newValue) { this._debugTracking = newValue; },
enumerable: true,
configurable: true
});
Object.defineProperty(Maze.prototype, "cellSize", {
/**
* Get the size (in pixels) of the cells in the maze based on the
......@@ -2701,7 +2700,7 @@ var nurdz;
}
// If we're not tracking debug action, the rest of these actions
// should not be allowed;
if (this._debugTracking == false)
if (this._debugger.debugTracking == false)
return;
// If this is a brick that is not hidden, vanish it. We can't bring
// it back because once it's hidden the update loop will reap it.
......@@ -3101,7 +3100,7 @@ var nurdz;
// We can render the markers now.
this.renderMazeMarkers(x, y, cSize, renderer);
// Now the debug marker, if it's turned on.
if (this._debugTracking) {
if (this._debugger.debugTracking) {
var pos = this._debugger.debugPoint;
this._debugMarker.render(x + (pos.x * cSize), y + (pos.y * cSize), renderer);
}
......@@ -3208,8 +3207,8 @@ var nurdz;
// Toggle mouse tracking of the debug location, then update the
// tracking with the last known mouse location.
case game.KeyCodes.KEY_SPACEBAR:
this._maze.debugTracking = !this._maze.debugTracking;
if (this._maze.debugTracking)
this._maze.debugger.debugTracking = !this._maze.debugger.debugTracking;
if (this._maze.debugger.debugTracking)
this._maze.setDebugPoint(this._mouse);
return true;
// Delete the contents of the current cell, if anything is
......@@ -3220,7 +3219,7 @@ var nurdz;
// delete key on the numeric keypad may or may not work.
case 8:
case 46:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugClearCell();
return true;
}
......@@ -3228,7 +3227,7 @@ var nurdz;
// Toggle the type of the entity under the debug cursor through
// its various states.
case game.KeyCodes.KEY_T:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugToggleCell();
return true;
}
......@@ -3237,7 +3236,7 @@ var nurdz;
// only works if the cell is currently empty. This will try
// to add a gray brick, and failing that a bonus brick.
case game.KeyCodes.KEY_B:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugAddBrick();
return true;
}
......@@ -3247,7 +3246,7 @@ var nurdz;
// normal arrow by default, but this can be toggled with the
// 'T" key'.
case game.KeyCodes.KEY_A:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugAddArrow();
return true;
}
......@@ -3256,7 +3255,7 @@ var nurdz;
// only works if the cell is currentlye empty. This just adds an
// extra exit point to the black hole system.
case game.KeyCodes.KEY_H:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugAddTeleport();
return true;
}
......@@ -3265,7 +3264,7 @@ var nurdz;
// 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 game.KeyCodes.KEY_L:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugAddBall();
return true;
}
......@@ -3274,7 +3273,7 @@ var nurdz;
// visible.
case game.KeyCodes.KEY_V:
case game.KeyCodes.KEY_C:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugVanishBricks(eventObj.keyCode == game.KeyCodes.KEY_V);
return true;
}
......@@ -3282,7 +3281,7 @@ var nurdz;
// Wipe the entire maze contents; this is like a reset except
// no new maze is generated first.
case game.KeyCodes.KEY_W:
if (this._maze.debugTracking) {
if (this._maze.debugger.debugTracking) {
this._maze.debugger.debugWipeMaze();
return true;
}
......@@ -3326,7 +3325,7 @@ var nurdz;
this._mouse = this._stage.calculateMousePos(eventObj, this._mouse);
// If we're tracking a debug location, tell the maze about this
// point.
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
this._maze.setDebugPoint(this._mouse);
// We handled it.
return true;
......
......@@ -28,6 +28,14 @@ module nurdz.game
*/
private _teleport : Teleport;
/**
* True if we are debugging, false otherwise.
*
* When this is true, the current debug cell in the grid (controlled via
* the mouse) has a marker to show where it is.
*/
private _debugTracking : boolean;
/**
* A point that represents a grid cell that is the current debug cell.
*
......@@ -79,6 +87,28 @@ module nurdz.game
set debugPoint (newPoint : Point)
{ this._debugPoint.setTo (newPoint); }
/**
* Get the current state of the debug tracking variable.
*
* When this is set to true, we display a marker on the stage at the
* current debug position.
*
* @returns {boolean} true if debugging is enabled, false otherwise.
*/
get debugTracking () : boolean
{ return this._debugTracking; }
/**
* Change the current state of the debug tracking variable.
*
* True enables debugging, which causes the maze to display a red marker
* at the current debug location.
*
* @param {boolean} newValue new debugging state
*/
set debugTracking (newValue : boolean)
{ this._debugTracking = newValue; }
/**
* Construct a new debugger object that can debug the provided maze object.
*
......@@ -96,6 +126,10 @@ module nurdz.game
// Create a default debug point.
this._debugPoint = new Point (0, 0);
// No debugging by default, but the debugging point is the upper
// left grid corner;.
this._debugTracking = false;
}
/**
......
......@@ -144,14 +144,6 @@ module nurdz.game
*/
private _debugger : MazeDebugger;
/**
* True if we are debugging, false otherwise.
*
* When this is true, the current debug cell in the grid (controlled via
* the mouse) has a marker to show where it is.
*/
private _debugTracking : boolean;
/**
* A special marker instance that is used to show the current debug
* point while debug tracking is turned on.
......@@ -161,28 +153,6 @@ module nurdz.game
*/
private _debugMarker : Marker;
/**
* Get the current state of the debug tracking variable.
*
* When this is set to true, we display a marker on the stage at the
* current debug position.
*
* @returns {boolean} true if debugging is enabled, false otherwise.
*/
get debugTracking () : boolean
{ return this._debugTracking; }
/**
* Change the current state of the debug tracking variable.
*
* True enables debugging, which causes the maze to display a red marker
* at the current debug location.
*
* @param {boolean} newValue new debugging state
*/
set debugTracking (newValue : boolean)
{ this._debugTracking = newValue; }
/**
* Get the size (in pixels) of the cells in the maze based on the
* current sprite set. The cells are square, so this represents both
......@@ -294,11 +264,6 @@ module nurdz.game
// exactly how many entities of a type we need.
for (let i = 0 ; i < (MAZE_WIDTH - 2) * 2 ; i++)
this._balls.addEntity (new Ball (stage), false);
// No debugging by default, but the debugging point is the upper
// left grid corner; the marker is created later when we know the
// grid size.
this._debugTracking = false;
}
/**
......@@ -446,7 +411,7 @@ module nurdz.game
// If we're not tracking debug action, the rest of these actions
// should not be allowed;
if (this._debugTracking == false)
if (this._debugger.debugTracking == false)
return;
// If this is a brick that is not hidden, vanish it. We can't bring
......@@ -932,7 +897,7 @@ module nurdz.game
this.renderMazeMarkers (x, y, cSize, renderer);
// Now the debug marker, if it's turned on.
if (this._debugTracking)
if (this._debugger.debugTracking)
{
let pos = this._debugger.debugPoint;
this._debugMarker.render (x + (pos.x * cSize),
......
......@@ -75,8 +75,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.debugTracking = !this._maze.debugTracking;
if (this._maze.debugTracking)
this._maze.debugger.debugTracking = !this._maze.debugger.debugTracking;
if (this._maze.debugger.debugTracking)
this._maze.setDebugPoint (this._mouse);
return true;
......@@ -88,7 +88,7 @@ module nurdz.game
// delete key on the numeric keypad may or may not work.
case 8:
case 46:
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugClearCell ();
return true;
......@@ -98,7 +98,7 @@ module nurdz.game
// Toggle the type of the entity under the debug cursor through
// its various states.
case KeyCodes.KEY_T:
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugToggleCell ();
return true;
......@@ -109,7 +109,7 @@ module nurdz.game
// 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.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddBrick ();
return true;
......@@ -121,7 +121,7 @@ module nurdz.game
// normal arrow by default, but this can be toggled with the
// 'T" key'.
case KeyCodes.KEY_A:
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddArrow ();
return true;
......@@ -132,7 +132,7 @@ module nurdz.game
// 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.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddTeleport ();
return true;
......@@ -143,7 +143,7 @@ module nurdz.game
// 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.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugAddBall ();
return true;
......@@ -154,7 +154,7 @@ module nurdz.game
// visible.
case KeyCodes.KEY_V:
case KeyCodes.KEY_C:
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugVanishBricks (eventObj.keyCode == KeyCodes.KEY_V);
return true;
......@@ -164,7 +164,7 @@ module nurdz.game
// Wipe the entire maze contents; this is like a reset except
// no new maze is generated first.
case KeyCodes.KEY_W:
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
{
this._maze.debugger.debugWipeMaze ();
return true;
......@@ -217,7 +217,7 @@ module nurdz.game
// If we're tracking a debug location, tell the maze about this
// point.
if (this._maze.debugTracking)
if (this._maze.debugger.debugTracking)
this._maze.setDebugPoint (this._mouse);
// We handled 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