Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions src/neighborhood.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Subtype from './subtype';
import NeighborhoodCell from './neighborhoodCell';
import NeighborhoodDrawer from './neighborhoodDrawer';
import { Direction } from './tiles';
import Subtype from "./subtype";
import NeighborhoodCell from "./neighborhoodCell";
import NeighborhoodDrawer from "./neighborhoodDrawer";
import { Direction } from "./tiles";

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

this.squareSize = this.skin_.squareSize;
this.assetList = [];
}

/**
Expand All @@ -18,7 +19,7 @@ module.exports = class Neighborhood extends Subtype {
isNeighborhood() {
return true;
}

/**
* @override
*/
Expand Down Expand Up @@ -46,19 +47,23 @@ module.exports = class Neighborhood extends Subtype {

const asset = this.drawer.getBackgroundTileInfo(row, col);
if (asset) {
// add asset id to the assetList
this.assetList.push("tileElement" + `${tileId}-asset`);
// add assset on top of blank tile if it exists
// asset is in format {name: 'sample name', sheet: x, row: y, column: z}
const assetHref = this.skin_.assetUrl(asset.sheet);
const [sheetWidth, sheetHeight] = this.getDimensionsForSheet(asset.sheet);
const [sheetWidth, sheetHeight] = this.getDimensionsForSheet(
asset.sheet
);
this.drawer.drawTileHelper(
svg,
[asset.column, asset.row],
row,
col,
`${tileId}-asset`,
svg,
[asset.column, asset.row],
row,
col,
`${tileId}-asset`,
assetHref,
sheetWidth,
sheetHeight,
sheetWidth,
sheetHeight,
this.squareSize
);
}
Expand All @@ -67,38 +72,46 @@ module.exports = class Neighborhood extends Subtype {
});
}

/**
* @override
**/
/**
* @override
**/
createDrawer(svg) {
this.drawer = new NeighborhoodDrawer(this.maze_.map, this.skin_, svg, this.squareSize, this);
this.drawer = new NeighborhoodDrawer(
this.maze_.map,
this.skin_,
svg,
this.squareSize,
this
);
}

/**
* Paint the current location of the pegman with id pegmanId.
* @param {String} pegmanId
* @param {String} color Color to paint current location.
* @param {String} color Color to paint current location.
* Must be hex code or html color.
**/
**/
addPaint(pegmanId, color) {
const col = this.maze_.getPegmanX(pegmanId);
const row = this.maze_.getPegmanY(pegmanId);

const cell = this.getCell(row, col);
cell.setColor(color);
this.drawer.updateItemImage(row, col, true);
this.drawer.drawAssets();
}

/**
* Remove paint from the location of the pegman with id pegmanId.
* @param {String} pegmanId
**/
removePaint(pegmanId) {
**/
removePaint(pegmanId) {
const col = this.maze_.getPegmanX(pegmanId);
const row = this.maze_.getPegmanY(pegmanId);

this.drawer.resetTile(row, col);
this.drawer.updateItemImage(row, col, true);
this.drawer.drawAssets();
}

/**
Expand Down Expand Up @@ -146,4 +159,9 @@ module.exports = class Neighborhood extends Subtype {
getDimensionsForSheet(sheet) {
return [10 * this.squareSize, this.sheetRows[sheet] * this.squareSize];
}
}

// Retrieve the asset list
getAssetList() {
return this.assetList;
}
};
Loading