Skip to content

Commit 5fd1208

Browse files
authored
Merge pull request #74 from code-dot-org/molly/neighborhood-buckets
Neighborhood: add show/hide buckets
2 parents cdfb231 + 71ce60e commit 5fd1208

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ And spin up a development build of your new project:
2424

2525
yarn build
2626

27+
### Integrate with local Code Studio
28+
In this repo:
29+
30+
```
31+
yarn link
32+
```
33+
34+
In main repo's `apps/` directory:
35+
36+
```
37+
yarn link @code-dot-org/maze
38+
```
39+
40+
This will set up a symlink in main repo's apps/node_modules/ to point at your local changes.
41+
42+
Run
43+
44+
```
45+
yarn run build
46+
```
47+
48+
in this repo, and then the main repo's `apps` build should pick the changes up next time it builds.
49+
50+
If you are running `yarn start` for continuous builds in the main repo, it will pick up the changes once the build in this repo has completed.
51+
2752
### Publishing a new version
2853

2954
In /maze: npm login with an authorized npm account. If necessary, create one under your own email, login with our shared dev account and add your new account to the org. After logging in, you may need to authorize your machine (follow the prompt given):

src/neighborhood.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ module.exports = class Neighborhood extends Subtype {
146146
this.drawer.updateItemImage(row, col, true);
147147
}
148148

149+
setBucketVisibility(showBuckets) {
150+
if (this.drawer.getBucketVisibility() != showBuckets) {
151+
this.drawer.setBucketVisibility(showBuckets);
152+
this.redrawBucketTiles();
153+
}
154+
}
155+
156+
redrawBucketTiles() {
157+
this.maze_.map.forEachCell((cell, row, col) => {
158+
// if the cell has a value > 0, it has a bucket. Only update tiles with a bucket.
159+
if (cell.getCurrentValue() > 0) {
160+
this.drawer.updateItemImage(row, col, true);
161+
}
162+
});
163+
}
164+
149165
reset() {
150166
this.drawer.resetTiles();
151167
}

src/neighborhoodDrawer.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ module.exports = class NeighborhoodDrawer extends Drawer {
199199
this.squareSize = squareSize;
200200
this.neighborhood = neighborhood;
201201
this.skin_ = skin;
202+
this.showBuckets = true;
203+
}
204+
205+
setBucketVisibility(showBuckets) {
206+
this.showBuckets = showBuckets;
207+
}
208+
209+
getBucketVisibility() {
210+
return this.showBuckets;
202211
}
203212

204213
/**
@@ -223,8 +232,9 @@ module.exports = class NeighborhoodDrawer extends Drawer {
223232
*/
224233
getAsset(prefix, row, col) {
225234
const cell = this.neighborhood.getCell(row, col);
226-
// only cells with a value are handled by getAsset.
227-
if (cell.getCurrentValue()) {
235+
// If a cell has a value, it is a paint bucket. Return the paintCan asset
236+
// if we currently are showing buckets.
237+
if (cell.getCurrentValue() && this.showBuckets) {
228238
return this.skin_.paintCan;
229239
}
230240
}
@@ -254,6 +264,7 @@ module.exports = class NeighborhoodDrawer extends Drawer {
254264
* Calls resetTile for each tile in the grid, clearing all paint.
255265
*/
256266
resetTiles() {
267+
this.showBuckets = true;
257268
for (let row = 0; row < this.map_.ROWS; row++) {
258269
for (let col = 0; col < this.map_.COLS; col++) {
259270
this.resetTile(row, col);
@@ -495,8 +506,10 @@ module.exports = class NeighborhoodDrawer extends Drawer {
495506
// is a paint can square. Ensure it is shown/hidden appropriately
496507
// and with the correct value.
497508
if (cell.getOriginalValue() > 0) {
498-
const newValue = cell.getCurrentValue() > 0 ? cell.getCurrentValue() : "";
499-
// drawImage_ calls getAsset. If currentValue() is 0, getAsset will return
509+
// The new value is the number of paint units to show on the screen. If we have > 0 units and we
510+
// are showing buckets, return the value, otherwise return an empty string so we hide the bucket and value.
511+
const newValue = cell.getCurrentValue() > 0 && this.showBuckets ? cell.getCurrentValue() : "";
512+
// drawImage_ calls getAsset. If currentValue() is 0 or we want to hide buckets, getAsset will return
500513
// undefined and the paint can will be hidden. Otherwise we will get the paint can image.
501514
super.drawImage_("", row, col, this.squareSize);
502515
super.updateOrCreateText_(

0 commit comments

Comments
 (0)