Skip to content
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

Merged
merged 14 commits into from Feb 28, 2018
Merged

Separate Maze into Controller and Wrapper #20611

merged 14 commits into from Feb 28, 2018

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Feb 14, 2018

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:

animationsController.js
beeCell.js
beeItemDrawer.js
bee.js
cell.js
collectorDrawer.js
collector.js
constants.js
dirtDrawer.js
drawer.js
drawMap.js
farmer.js
gatherer.js
harvesterCell.js
harvesterDrawer.js
harvester.js
locale.js
mazeController.js
mazeMap.js
mazeUtils.js
planterCell.js
planterDrawer.js
planter.js
redux.js
scrat.js
subtype.js
tiles.js
timeoutList.js
utils.js
wordsearchDrawer.js
wordsearch.js

And the rest staying where they are.

@Hamms Hamms force-pushed the maze-controller branch 3 times, most recently from d5ec6fb to 3a66ef7 Compare February 23, 2018 02:54
@Hamms Hamms changed the title [WIP] Separate Maze into Controller and Wrapper Separate Maze into Controller and Wrapper Feb 24, 2018
Copy link
Contributor

@balderdash balderdash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

const Type = getSubtypeForSkin(config.skinId);
this.subtype = new Type(this, config);
this.controller = new MazeController(level, skin, config);
this.controller.rebindMethods({
Copy link
Contributor

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?

Copy link
Contributor

@joshlory joshlory left a 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.


this.pegmanD;
this.pegmanX;
this.pegmanY;
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

/**
* Initialize Blockly and the maze. Called on page load.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra newline.

// 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)) {
Copy link
Contributor

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...)

Copy link
Contributor Author

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;
// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

Copy link
Contributor Author

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

@Hamms
Copy link
Contributor Author

Hamms commented Feb 26, 2018

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

@Hamms Hamms merged commit a2a3048 into staging Feb 28, 2018
@Hamms Hamms deleted the maze-controller branch May 31, 2018 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants