New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate Maze into Controller and Wrapper #20611
Conversation
d5ec6fb
to
3a66ef7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
apps/src/maze/maze.js
Outdated
const Type = getSubtypeForSkin(config.skinId); | ||
this.subtype = new Type(this, config); | ||
this.controller = new MazeController(level, skin, config); | ||
this.controller.rebindMethods({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these just be (optional?) constructor arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome refactor! I have some reservations about extracting redux.js along with the other logic (do we need the standalone Maze app to have a Redux dependency?).
Added a few nit comments, nothing blocking this PR.
apps/src/maze/mazeController.js
Outdated
|
||
this.pegmanD; | ||
this.pegmanX; | ||
this.pegmanY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this appropriately add these properties to the object shape? My understanding is that without an assignment this is a no-op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct; I put these here for readability, not functionality. Do you have a preference for a more useful way to call out which properties are declared on a given instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure... can we set them to null
/undefined
for clarity?
// their own complex syntax. This way is deprecated for new levels, | ||
// and only exists for backwards compatibility for not-yet-updated | ||
// levels. | ||
if (this.level.serializedMaze) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass in level
as an argument instead of adding it to this
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably, yes; in fact, the way it currently works is that we pass in level
, skin
, and config
to the constructor despite the fact that level
and skin
are actually just properties on config
.
I did it this way because that's what most closely mirrors how the current version of Maze is initialized, and I wanted this PR to be just a reorganization with as few functional changes as possible, with the intention of doing cleanups like that when things are more cleanly separated.
apps/src/maze/mazeController.js
Outdated
/** | ||
* Initialize Blockly and the maze. Called on page load. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extra newline.
apps/src/maze/mazeController.js
Outdated
// Play sound and animation for hitting wall or obstacle | ||
var squareType = this.map.getTile(targetY, targetX); | ||
if (squareType === tiles.SquareType.WALL || squareType === undefined || | ||
(this.subtype.isScrat() && squareType === tiles.SquareType.OBSTACLE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😕 might be good to call into something like this.subtype.handleHitObstacle
make the subtype override the behavior if it's different from the default. (Future PR...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A thousand times yes. I would like in general to remove these subtype identification methods entirely and update everything that's currently using them to instead leverage overridable methods
@@ -43,7 +43,7 @@ module.exports = { | |||
testResult: TestResults.ALL_PASS | |||
}, | |||
// customValidator: function () { | |||
// return Maze.subtype.nectars_.length === 2 && Maze.subtype.honey_ === 2; | |||
// return Maze.controller.subtype.nectars_.length === 2 && Maze.controller.subtype.honey_ === 2; | |||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but I figured this PR was already large enough without doing misc cleanup
I'm intending to address the redux dependency separately; I intentionally deferred any changes to that functionality in this PR to prevent it from becoming even larger than it already is |
Where the MazeController is responsible for handling all the maze stuff like animating and drawing the map and enforcing all the maze rules like bumping into walls and only collecting from collectable tiles, and the MazeWrapper is responsible for all the stuff external to make like hooking up to the Run button and turning Blockly into actions and rendering feedback.
…o live to Maze where they now actually live
… longer be so, since they are now intended to be public
6a0f940
to
b72f871
Compare
Where the MazeController is responsible for handling all the maze stuff
like animating and drawing the map and enforcing all the maze rules like
bumping into walls and only collecting from collectable tiles, and the
MazeWrapper is responsible for all the stuff external to make like
hooking up to the Run button and turning Blockly into actions and
rendering feedback.
The ultimate goal with this PR is to prepare for us to split the Maze directory in half, with the following files all moving into the external repo:
And the rest staying where they are.