Skip to content

Commit

Permalink
Fixed bug and implemented solution which allows for same behaviour fo…
Browse files Browse the repository at this point in the history
…r different abilities if desired
  • Loading branch information
xTammaro committed Oct 15, 2023
1 parent 3120be6 commit d565cb8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/abilities/Stomper.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default (G) => {
sourceCreature: stomper,
stopOnCreature: false,
dashedHexesUnderCreature: true,
fillOnlyHovered: true,
});
G.h

Expand Down
76 changes: 64 additions & 12 deletions src/utility/hexgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export class HexGrid {
*/
onShoutCooldown: boolean;

/**
* Last hovered creature.
*/
hoveredCreature: Creature | null = null;

display: Phaser.Group;
gridGroup: Phaser.Group;
trapGroup: Phaser.Group;
Expand Down Expand Up @@ -297,6 +302,7 @@ export class HexGrid {
queryDirection(o: Partial<QueryOptions>) {
o.isDirectionsQuery = true;
o = this.getDirectionChoices(o);
if ('fillOnlyHovered' in o) console.log('In queryDirection:', o.fillOnlyHovered);
this.queryChoice(o);
}

Expand Down Expand Up @@ -327,6 +333,7 @@ export class HexGrid {
sourceCreature: undefined,
choices: [],
optTest: () => true,
fillOnlyHovered: false,
};

const options = { ...defaultOpt, ...o };
Expand Down Expand Up @@ -524,13 +531,34 @@ export class HexGrid {
game.activeCreature.queryMove();
},
fnOnSelect: (choice) => {
choice.forEach((item) => {
if (item.creature instanceof Creature) {
if (o.fillOnlyHovered) {
choice.forEach((item) => {
if (item.creature instanceof Creature && item.creature === this.hoveredCreature) {
item.displayVisualState('creature selected player' + item.creature.team);
} else if (item.creature instanceof Creature) {
item.displayVisualState('adj');
} else if (this.hoveredCreature == null) {
console.log('hovering empty hex')
this.cleanHex(item);
item.displayVisualState('dashed');
item.overlayVisualState('hover');
}
else {
this.cleanHex(item);
item.displayVisualState('dashed');
}

});
}
else {
choice.forEach((item) => {
if (item.creature instanceof Creature && item.creature === this.hoveredCreature) {
item.displayVisualState('creature selected player' + item.creature.team);
} else {
item.displayVisualState('adj');
}
});
}
},
fnOnCancel: () => {
game.activeCreature.queryMove();
Expand All @@ -547,6 +575,7 @@ export class HexGrid {
isDirectionsQuery: false,
hideNonTarget: true,
dashedHexesUnderCreature: false,
fillOnlyHovered: false,
};

o = { ...defaultOpt, ...o };
Expand Down Expand Up @@ -627,6 +656,7 @@ export class HexGrid {
hideNonTarget: o.hideNonTarget,
id: o.id,
fillHexOnHover: false,
fillOnlyHovered: o.fillOnlyHovered,
});
}

Expand Down Expand Up @@ -790,10 +820,13 @@ export class HexGrid {
ownCreatureHexShade: false,
targeting: true,
fillHexOnHover: true,
fillOnlyHovered: false,
};

o = { ...defaultOpt, ...o };

console.log('In queryHexes:', o.fillOnlyHovered);

this.lastClickedHex = undefined;

// Save the last Query
Expand Down Expand Up @@ -862,7 +895,12 @@ export class HexGrid {
hex.overlayVisualState('reachable h_player' + hex.creature.team);
}
} else {
hex.overlayVisualState('reachable h_player' + this.game.activeCreature.team);
if (o.fillOnlyHovered) {
hex.displayVisualState('dashed');
}
else {
hex.overlayVisualState('reachable h_player' + this.game.activeCreature.team);
}
}
}
});
Expand Down Expand Up @@ -890,7 +928,7 @@ export class HexGrid {
$j('canvas').css('cursor', 'n-resize');
} else {
// Filled hex with color
hex.displayVisualState('creature player' + hex.creature.team);
hex.displayVisualState('creature player' + hex.creature.team);
}
} else if (game.activeCreature.noActionPossible) {
$j('canvas').css('cursor', 'wait');
Expand Down Expand Up @@ -946,6 +984,15 @@ export class HexGrid {
// Offset Pos
const offset = o.flipped ? o.size - 1 : 0;
const mult = o.flipped ? 1 : -1; // For flipped player

// If only fill hovered hexes, cancel if player clicks on empty hex
if (o.fillOnlyHovered) {
if (!(hex.creature instanceof Creature)) {
o.fnOnCancel(hex, o.args); // ON CANCEL
return;
}
}

// If hex is reachable & creature, reset health indicator bounce
if (hex.creature instanceof Creature) {
hex.creature.resetBounce();
Expand Down Expand Up @@ -978,6 +1025,7 @@ export class HexGrid {
const { creature } = hex;

if (creature instanceof Creature) {
this.hoveredCreature = null;
creature.resetBounce();
// toggle hover off event
if (creature.isDarkPriest()) {
Expand All @@ -989,6 +1037,8 @@ export class HexGrid {
$j('canvas').css('cursor', 'default');
};

let currentlyHoveredCreature: Creature | null = null;

// ONMOUSEOVER
const onSelectFn = (hex: Hex) => {
let { x } = hex;
Expand All @@ -1002,7 +1052,8 @@ export class HexGrid {
$j('canvas').css('cursor', 'pointer');

if (hex.creature instanceof Creature) {
// If creature
// Keep reference
this.hoveredCreature = hex.creature;

onCreatureHover(hex.creature, game.UI.xrayQueue.bind(game.UI), hex);

Expand All @@ -1011,8 +1062,14 @@ export class HexGrid {


if (hex.reachable) {
console.log("Reachable");
console.log(o.size);
console.log(o.fillOnlyHovered);
if (o.fillOnlyHovered) {
if (!(hex.creature instanceof Creature)) {
this.cleanHex(hex);
hex.overlayVisualState('hover');
$j('canvas').css('cursor', 'not-allowed');
}
}
if (o.fillHexOnHover) {
this.cleanHex(hex);
hex.displayVisualState('creature player' + this.game.activeCreature.team);
Expand All @@ -1032,11 +1089,6 @@ export class HexGrid {
x += offset - i * mult;
break;
}

if (hex.creature && hex.creature.id !== o.id) {
// This hex is occupied by a different creature, so skip the mouse-over logic.
return;
}

}

Expand Down

0 comments on commit d565cb8

Please sign in to comment.