Skip to content

Commit

Permalink
Merge pull request #1828 from CKillen/issue-633
Browse files Browse the repository at this point in the history
Show active unit range when hovering marker + code reuse, fixes #633
  • Loading branch information
DreadKnight committed Dec 21, 2020
2 parents 3b7971d + fa867b9 commit d37ad47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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

0 comments on commit d37ad47

Please sign in to comment.