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

Fixed Issue 633, Slight refactor in hexgrid to remove duplicate code #1828

Merged
merged 1 commit into from
Dec 21, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ui/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -2428,11 +2428,14 @@ export class UI {
.find('.vignette.roundmarker')
.unbind('mouseover')
.unbind('mouseleave')
.bind('mouseover', () => {
.bind('mouseover', (e) => {
game.grid.showGrid(true);
game.grid.showMovementRangeInOverlay(game.activeCreature);
})
.bind('mouseleave', () => {
game.grid.showGrid(false);
game.grid.cleanOverlay();
game.grid.showMovementRange(game.activeCreature.id);
});

// Add shift keydown effect like above, onkeydown => showGrid
Expand Down
39 changes: 25 additions & 14 deletions src/utility/hexgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,36 +1056,47 @@ export class HexGrid {

// TODO: Rewrite methods used here to only require the creature as an argument.
showMovementRange(id) {
let creature = this.game.creatures[id],
hexes;
let creature = this.game.creatures[id];
let hexes = this.findCreatureMovementHexes(creature);

// Block all hexes
this.forEachHex((hex) => {
hex.unsetReachable();
});

// Set reachable the given hexes
hexes.forEach((hex) => {
hex.setReachable();
});
}

showMovementRangeInOverlay(creature) {
let hexes = this.findCreatureMovementHexes(creature);

// Set reachable the given hexes
hexes.forEach((hex) => {
hex.overlayVisualState('hover h_player' + creature.team);
});
}

findCreatureMovementHexes(creature) {
if (creature.movementType() === 'flying') {
hexes = this.getFlyingRange(
return this.getFlyingRange(
creature.x,
creature.y,
creature.stats.movement,
creature.size,
creature.id,
);
} else {
hexes = this.getMovementRange(
return this.getMovementRange(
creature.x,
creature.y,
creature.stats.movement,
creature.size,
creature.id,
);
}

// Block all hexes
this.forEachHex((hex) => {
hex.unsetReachable();
});

// Set reachable the given hexes
hexes.forEach((hex) => {
hex.setReachable();
});
}

selectHexUp() {
Expand Down