Skip to content

Commit 517878c

Browse files
authored
Merge pull request #63 from code-dot-org/hbergam/paint-over-assets
Making paint render below assets
2 parents 0dbc9ee + cd51ef3 commit 517878c

File tree

2 files changed

+221
-89
lines changed

2 files changed

+221
-89
lines changed

src/neighborhood.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Subtype from './subtype';
2-
import NeighborhoodCell from './neighborhoodCell';
3-
import NeighborhoodDrawer from './neighborhoodDrawer';
4-
import { Direction } from './tiles';
1+
import Subtype from "./subtype";
2+
import NeighborhoodCell from "./neighborhoodCell";
3+
import NeighborhoodDrawer from "./neighborhoodDrawer";
4+
import { Direction } from "./tiles";
55

66
module.exports = class Neighborhood extends Subtype {
77
constructor(maze, config = {}) {
@@ -10,6 +10,7 @@ module.exports = class Neighborhood extends Subtype {
1010
this.sheetRows = this.skin_.sheetRows;
1111

1212
this.squareSize = this.skin_.squareSize;
13+
this.assetList = [];
1314
}
1415

1516
/**
@@ -18,7 +19,7 @@ module.exports = class Neighborhood extends Subtype {
1819
isNeighborhood() {
1920
return true;
2021
}
21-
22+
2223
/**
2324
* @override
2425
*/
@@ -46,19 +47,23 @@ module.exports = class Neighborhood extends Subtype {
4647

4748
const asset = this.drawer.getBackgroundTileInfo(row, col);
4849
if (asset) {
50+
// add asset id to the assetList
51+
this.assetList.push("tileElement" + `${tileId}-asset`);
4952
// add assset on top of blank tile if it exists
5053
// asset is in format {name: 'sample name', sheet: x, row: y, column: z}
5154
const assetHref = this.skin_.assetUrl(asset.sheet);
52-
const [sheetWidth, sheetHeight] = this.getDimensionsForSheet(asset.sheet);
55+
const [sheetWidth, sheetHeight] = this.getDimensionsForSheet(
56+
asset.sheet
57+
);
5358
this.drawer.drawTileHelper(
54-
svg,
55-
[asset.column, asset.row],
56-
row,
57-
col,
58-
`${tileId}-asset`,
59+
svg,
60+
[asset.column, asset.row],
61+
row,
62+
col,
63+
`${tileId}-asset`,
5964
assetHref,
60-
sheetWidth,
61-
sheetHeight,
65+
sheetWidth,
66+
sheetHeight,
6267
this.squareSize
6368
);
6469
}
@@ -67,38 +72,46 @@ module.exports = class Neighborhood extends Subtype {
6772
});
6873
}
6974

70-
/**
71-
* @override
72-
**/
75+
/**
76+
* @override
77+
**/
7378
createDrawer(svg) {
74-
this.drawer = new NeighborhoodDrawer(this.maze_.map, this.skin_, svg, this.squareSize, this);
79+
this.drawer = new NeighborhoodDrawer(
80+
this.maze_.map,
81+
this.skin_,
82+
svg,
83+
this.squareSize,
84+
this
85+
);
7586
}
7687

7788
/**
7889
* Paint the current location of the pegman with id pegmanId.
7990
* @param {String} pegmanId
80-
* @param {String} color Color to paint current location.
91+
* @param {String} color Color to paint current location.
8192
* Must be hex code or html color.
82-
**/
93+
**/
8394
addPaint(pegmanId, color) {
8495
const col = this.maze_.getPegmanX(pegmanId);
8596
const row = this.maze_.getPegmanY(pegmanId);
8697

8798
const cell = this.getCell(row, col);
8899
cell.setColor(color);
89100
this.drawer.updateItemImage(row, col, true);
101+
this.drawer.drawAssets();
90102
}
91103

92104
/**
93105
* Remove paint from the location of the pegman with id pegmanId.
94106
* @param {String} pegmanId
95-
**/
96-
removePaint(pegmanId) {
107+
**/
108+
removePaint(pegmanId) {
97109
const col = this.maze_.getPegmanX(pegmanId);
98110
const row = this.maze_.getPegmanY(pegmanId);
99111

100112
this.drawer.resetTile(row, col);
101113
this.drawer.updateItemImage(row, col, true);
114+
this.drawer.drawAssets();
102115
}
103116

104117
/**
@@ -146,4 +159,9 @@ module.exports = class Neighborhood extends Subtype {
146159
getDimensionsForSheet(sheet) {
147160
return [10 * this.squareSize, this.sheetRows[sheet] * this.squareSize];
148161
}
149-
}
162+
163+
// Retrieve the asset list
164+
getAssetList() {
165+
return this.assetList;
166+
}
167+
};

0 commit comments

Comments
 (0)