From 287560068bee49614af5c251765e5d74bf3c7080 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Fri, 13 Oct 2023 14:58:36 +1100 Subject: [PATCH 01/11] Found source of bug --- src/abilities/Stomper.js | 1 + src/utility/hexgrid.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index b5de4172e..97e363e80 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -115,6 +115,7 @@ export default (G) => { y: stomper.y, distance: 3, sourceCreature: stomper, + stopOnCreature: true, dashedHexesUnderCreature: true, }); } // Once upgraded, can hit any ennemy within 3hex in any direction diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index c9146015b..1990937bc 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -10,6 +10,7 @@ import { DEBUG } from '../debug'; import { HEX_WIDTH_PX } from './const'; import { Point } from './pointfacade'; import { AugmentedMatrix } from './matrices'; +import { Ability } from '../ability'; interface GridDefinition { numRows: number; @@ -859,6 +860,9 @@ export class HexGrid { if (hex.creature instanceof Creature) { if (hex.creature.id != this.game.activeCreature.id) { hex.overlayVisualState('reachable h_player' + hex.creature.team); + if (!hex.hovered) { + hex.cleanOverlayVisualState('hover h_player' + hex.creature.team); + } } } else { hex.overlayVisualState('reachable h_player' + this.game.activeCreature.team); @@ -1012,7 +1016,7 @@ export class HexGrid { this.cleanHex(hex); hex.displayVisualState('creature player' + this.game.activeCreature.team); } - + // Offset Pos const offset = o.flipped ? o.size - 1 : 0; const mult = o.flipped ? 1 : -1; // For flipped player From 3120be6d8fc2b12cf64589d555509a1792f9d8d6 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Sat, 14 Oct 2023 19:15:37 +1100 Subject: [PATCH 02/11] Figured out how to fill in only single hex, but still having issues filling in all of a creatures hexes --- src/abilities/Stomper.js | 3 +++ src/utility/hexgrid.ts | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index 97e363e80..dee347b38 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -5,6 +5,7 @@ import * as matrices from '../utility/matrices'; import * as arrayUtils from '../utility/arrayUtils'; import { Effect } from '../effect'; import { getDirectionFromDelta } from '../utility/position'; +import { forEach } from 'underscore'; /** Creates the abilities * @param {Object} G the game object @@ -146,6 +147,8 @@ export default (G) => { stopOnCreature: false, dashedHexesUnderCreature: true, }); + G.h + } }, diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 1990937bc..44b30a020 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -859,10 +859,7 @@ export class HexGrid { if (o.targeting) { if (hex.creature instanceof Creature) { if (hex.creature.id != this.game.activeCreature.id) { - hex.overlayVisualState('reachable h_player' + hex.creature.team); - if (!hex.hovered) { - hex.cleanOverlayVisualState('hover h_player' + hex.creature.team); - } + hex.overlayVisualState('reachable h_player' + hex.creature.team); } } else { hex.overlayVisualState('reachable h_player' + this.game.activeCreature.team); @@ -1006,12 +1003,16 @@ export class HexGrid { if (hex.creature instanceof Creature) { // If creature + onCreatureHover(hex.creature, game.UI.xrayQueue.bind(game.UI), hex); hex.creature.startBounce(); } + if (hex.reachable) { + console.log("Reachable"); + console.log(o.size); if (o.fillHexOnHover) { this.cleanHex(hex); hex.displayVisualState('creature player' + this.game.activeCreature.team); @@ -1031,10 +1032,17 @@ 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; + } + } hex = this.hexes[y][x]; // New coords o.fnOnSelect(hex, o.args); + } else if (!hex.reachable) { if (this.materialize_overlay) { this.materialize_overlay.alpha = 0; From d565cb89c5a3fa3f4a44a4f100013171b1373316 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Sun, 15 Oct 2023 15:49:36 +1100 Subject: [PATCH 03/11] Fixed bug and implemented solution which allows for same behaviour for different abilities if desired --- src/abilities/Stomper.js | 1 + src/utility/hexgrid.ts | 76 +++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index dee347b38..347768138 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -146,6 +146,7 @@ export default (G) => { sourceCreature: stomper, stopOnCreature: false, dashedHexesUnderCreature: true, + fillOnlyHovered: true, }); G.h diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 44b30a020..855993910 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -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; @@ -297,6 +302,7 @@ export class HexGrid { queryDirection(o: Partial) { o.isDirectionsQuery = true; o = this.getDirectionChoices(o); + if ('fillOnlyHovered' in o) console.log('In queryDirection:', o.fillOnlyHovered); this.queryChoice(o); } @@ -327,6 +333,7 @@ export class HexGrid { sourceCreature: undefined, choices: [], optTest: () => true, + fillOnlyHovered: false, }; const options = { ...defaultOpt, ...o }; @@ -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(); @@ -547,6 +575,7 @@ export class HexGrid { isDirectionsQuery: false, hideNonTarget: true, dashedHexesUnderCreature: false, + fillOnlyHovered: false, }; o = { ...defaultOpt, ...o }; @@ -627,6 +656,7 @@ export class HexGrid { hideNonTarget: o.hideNonTarget, id: o.id, fillHexOnHover: false, + fillOnlyHovered: o.fillOnlyHovered, }); } @@ -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 @@ -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); + } } } }); @@ -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'); @@ -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(); @@ -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()) { @@ -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; @@ -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); @@ -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); @@ -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; - } } From 720fc5aaa455f4f4a00ad5f6df6bb64ca233873d Mon Sep 17 00:00:00 2001 From: xTammaro Date: Sun, 15 Oct 2023 16:05:16 +1100 Subject: [PATCH 04/11] Cleaned up the code, removed logs --- src/abilities/Stomper.js | 2 +- src/utility/hexgrid.ts | 28 +++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index 347768138..06ce1415b 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -146,7 +146,7 @@ export default (G) => { sourceCreature: stomper, stopOnCreature: false, dashedHexesUnderCreature: true, - fillOnlyHovered: true, + fillOnlyHoveredCreature: true, }); G.h diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 855993910..6421549d9 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -302,7 +302,6 @@ export class HexGrid { queryDirection(o: Partial) { o.isDirectionsQuery = true; o = this.getDirectionChoices(o); - if ('fillOnlyHovered' in o) console.log('In queryDirection:', o.fillOnlyHovered); this.queryChoice(o); } @@ -333,7 +332,7 @@ export class HexGrid { sourceCreature: undefined, choices: [], optTest: () => true, - fillOnlyHovered: false, + fillOnlyHoveredCreature: false, }; const options = { ...defaultOpt, ...o }; @@ -531,14 +530,13 @@ export class HexGrid { game.activeCreature.queryMove(); }, fnOnSelect: (choice) => { - if (o.fillOnlyHovered) { + if (o.fillOnlyHoveredCreature) { 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'); @@ -575,7 +573,7 @@ export class HexGrid { isDirectionsQuery: false, hideNonTarget: true, dashedHexesUnderCreature: false, - fillOnlyHovered: false, + fillOnlyHoveredCreature: false, }; o = { ...defaultOpt, ...o }; @@ -656,7 +654,7 @@ export class HexGrid { hideNonTarget: o.hideNonTarget, id: o.id, fillHexOnHover: false, - fillOnlyHovered: o.fillOnlyHovered, + fillOnlyHoveredCreature: o.fillOnlyHoveredCreature, }); } @@ -820,12 +818,11 @@ export class HexGrid { ownCreatureHexShade: false, targeting: true, fillHexOnHover: true, - fillOnlyHovered: false, + fillOnlyHoveredCreature: false, }; o = { ...defaultOpt, ...o }; - console.log('In queryHexes:', o.fillOnlyHovered); this.lastClickedHex = undefined; @@ -895,7 +892,7 @@ export class HexGrid { hex.overlayVisualState('reachable h_player' + hex.creature.team); } } else { - if (o.fillOnlyHovered) { + if (o.fillOnlyHoveredCreature) { hex.displayVisualState('dashed'); } else { @@ -985,8 +982,8 @@ export class HexGrid { 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 only filling hovered creatures hexes, cancel if player clicks on empty hex + if (o.fillOnlyHoveredCreature) { if (!(hex.creature instanceof Creature)) { o.fnOnCancel(hex, o.args); // ON CANCEL return; @@ -1062,14 +1059,7 @@ export class HexGrid { if (hex.reachable) { - 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); From ffae2777b98e64cae24e708b0d0ab68b82425a92 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Mon, 16 Oct 2023 12:04:11 +1100 Subject: [PATCH 05/11] Small edits --- src/abilities/Stomper.js | 1 - src/utility/hexgrid.ts | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index 06ce1415b..7c13c1e3a 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -116,7 +116,6 @@ export default (G) => { y: stomper.y, distance: 3, sourceCreature: stomper, - stopOnCreature: true, dashedHexesUnderCreature: true, }); } // Once upgraded, can hit any ennemy within 3hex in any direction diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 6421549d9..cd31b19bf 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -550,7 +550,7 @@ export class HexGrid { } else { choice.forEach((item) => { - if (item.creature instanceof Creature && item.creature === this.hoveredCreature) { + if (item.creature instanceof Creature) { item.displayVisualState('creature selected player' + item.creature.team); } else { item.displayVisualState('adj'); @@ -1034,8 +1034,6 @@ export class HexGrid { $j('canvas').css('cursor', 'default'); }; - let currentlyHoveredCreature: Creature | null = null; - // ONMOUSEOVER const onSelectFn = (hex: Hex) => { let { x } = hex; From ac80f16c13c755f174fc84fb2a50f3e25cda8582 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Mon, 16 Oct 2023 12:46:54 +1100 Subject: [PATCH 06/11] Added cancel cursor when hovering empty hex --- src/abilities/Stomper.js | 6 ++---- src/utility/hexgrid.ts | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/abilities/Stomper.js b/src/abilities/Stomper.js index 7c13c1e3a..d69dcafc8 100644 --- a/src/abilities/Stomper.js +++ b/src/abilities/Stomper.js @@ -102,7 +102,7 @@ export default (G) => { const stomper = this.creature; const ability = this; - // Take the closest ennemy in each direction within 3hex + // Take the closest enemy in each direction within 3hex if (!this.isUpgraded()) { G.grid.queryDirection({ fnOnConfirm: function () { @@ -118,7 +118,7 @@ export default (G) => { sourceCreature: stomper, dashedHexesUnderCreature: true, }); - } // Once upgraded, can hit any ennemy within 3hex in any direction + } // Once upgraded, can hit any enemy within 3hex in any direction else { G.grid.queryDirection({ fnOnConfirm: function () { @@ -147,8 +147,6 @@ export default (G) => { dashedHexesUnderCreature: true, fillOnlyHoveredCreature: true, }); - G.h - } }, diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index cd31b19bf..4eff5fb76 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -1057,6 +1057,10 @@ export class HexGrid { if (hex.reachable) { + + if (o.fillOnlyHoveredCreature && !(hex instanceof Creature)) { + $j('canvas').css('cursor', 'not-allowed'); + } if (o.fillHexOnHover) { this.cleanHex(hex); From 84eb2ec426409930eb32f10f0f26a6c0335d4711 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Mon, 16 Oct 2023 13:57:38 +1100 Subject: [PATCH 07/11] Fixed cursor on empty hex --- src/utility/hexgrid.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 4eff5fb76..5b7bf8ba7 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -1058,9 +1058,12 @@ export class HexGrid { if (hex.reachable) { - if (o.fillOnlyHoveredCreature && !(hex instanceof Creature)) { + if (o.fillOnlyHoveredCreature && !(hex.creature instanceof Creature)) { $j('canvas').css('cursor', 'not-allowed'); } + //else if (o.fillOnlyHoveredCreature && (hex.creature instanceof Creature)) { + // $j('canvas').css('cursor', 'pointer'); + // } if (o.fillHexOnHover) { this.cleanHex(hex); From 56c5e01d70561abfb07b1b5013103452e8b826ff Mon Sep 17 00:00:00 2001 From: xTammaro Date: Mon, 16 Oct 2023 14:39:35 +1100 Subject: [PATCH 08/11] Remove commented code --- src/utility/hexgrid.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 5b7bf8ba7..341d16b69 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -1057,13 +1057,10 @@ export class HexGrid { if (hex.reachable) { - if (o.fillOnlyHoveredCreature && !(hex.creature instanceof Creature)) { $j('canvas').css('cursor', 'not-allowed'); } - //else if (o.fillOnlyHoveredCreature && (hex.creature instanceof Creature)) { - // $j('canvas').css('cursor', 'pointer'); - // } + if (o.fillHexOnHover) { this.cleanHex(hex); From 6fd1a36e61523bad6fe7555909bc892125babe90 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Tue, 17 Oct 2023 09:32:25 +1100 Subject: [PATCH 09/11] Fixed multiple cancel cursor bug --- src/utility/hexgrid.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 341d16b69..eeca97a41 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -536,13 +536,12 @@ export class HexGrid { item.displayVisualState('creature selected player' + item.creature.team); } else if (item.creature instanceof Creature) { item.displayVisualState('adj'); - } else if (this.hoveredCreature == null) { - this.cleanHex(item); - item.displayVisualState('dashed'); - item.overlayVisualState('hover'); - } + } //else if (this.hoveredCreature == null) { + //this.cleanHex(item); + //item.displayVisualState('dashed'); + //item.overlayVisualState('hover'); + //} else { - this.cleanHex(item); item.displayVisualState('dashed'); } @@ -1059,6 +1058,7 @@ export class HexGrid { if (hex.reachable) { if (o.fillOnlyHoveredCreature && !(hex.creature instanceof Creature)) { $j('canvas').css('cursor', 'not-allowed'); + hex.overlayVisualState('hover'); } From d77caf25af1072e2692af125a11ae27a8539bf85 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Tue, 17 Oct 2023 12:42:07 +1100 Subject: [PATCH 10/11] Fixed visual behaviour for empty hexes before first creature --- src/utility/hexgrid.ts | 60 ++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index eeca97a41..c74149daa 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -530,23 +530,27 @@ export class HexGrid { game.activeCreature.queryMove(); }, fnOnSelect: (choice) => { + // When only filling the hovered creature if (o.fillOnlyHoveredCreature) { - choice.forEach((item) => { + choice.forEach((item, index) => { 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) { - //this.cleanHex(item); - //item.displayVisualState('dashed'); - //item.overlayVisualState('hover'); - //} - else { - item.displayVisualState('dashed'); + } else { + // Split the choice into two parts, before and after the empty hex + const beforeEmpty = choice.slice(0, index); + const afterEmpty = choice.slice(index + 1); + // Check conditions + if (beforeEmpty.some(hex => hex.creature instanceof Creature)) { + item.displayVisualState('dashed'); + } else if (afterEmpty.some(hex => hex.creature instanceof Creature)) { + item.displayVisualState('adj'); + } } - }); } + // Normal behavior else { choice.forEach((item) => { if (item.creature instanceof Creature) { @@ -879,6 +883,19 @@ export class HexGrid { } } + // Function to determine if an empty hex is before or after the first creature in path + const emptyHexBeforeCreature = (hex) => { + const index = o.hexes.indexOf(hex); + const beforeEmpty = o.hexes.slice(0, index); + const afterEmpty = o.hexes.slice(index + 1); + // Check conditions + if (beforeEmpty.some(hex => hex.creature instanceof Creature)) { + return false; + } else if (afterEmpty.some(hex => hex.creature instanceof Creature)) { + return true; + } + } + // Set reachable the given hexes o.hexes.forEach((hex) => { hex.setReachable(); @@ -891,7 +908,7 @@ export class HexGrid { hex.overlayVisualState('reachable h_player' + hex.creature.team); } } else { - if (o.fillOnlyHoveredCreature) { + if (o.fillOnlyHoveredCreature && !emptyHexBeforeCreature(hex)) { hex.displayVisualState('dashed'); } else { @@ -932,6 +949,7 @@ export class HexGrid { queueEffect(creature.id); }; + // ONCLICK const onConfirmFn = (hex: Hex) => { // Debugger @@ -981,8 +999,8 @@ export class HexGrid { const offset = o.flipped ? o.size - 1 : 0; const mult = o.flipped ? 1 : -1; // For flipped player - // If only filling hovered creatures hexes, cancel if player clicks on empty hex - if (o.fillOnlyHoveredCreature) { + // If only filling hovered creatures hexes, cancel if player clicks on empty hex after first creature + if (o.fillOnlyHoveredCreature && !emptyHexBeforeCreature(hex)) { if (!(hex.creature instanceof Creature)) { o.fnOnCancel(hex, o.args); // ON CANCEL return; @@ -1057,8 +1075,22 @@ export class HexGrid { if (hex.reachable) { if (o.fillOnlyHoveredCreature && !(hex.creature instanceof Creature)) { - $j('canvas').css('cursor', 'not-allowed'); - hex.overlayVisualState('hover'); + if (!emptyHexBeforeCreature(hex)) { + $j('canvas').css('cursor', 'not-allowed'); + hex.overlayVisualState('hover'); + } + else { + const index = o.hexes.indexOf(hex); + const afterEmpty = o.hexes.slice(index + 1); + // Find the next creature after the empty hex + const nextCreature = afterEmpty.find(hex => hex.creature instanceof Creature)?.creature; + if (nextCreature) { + // Apply the desired behavior to all hexes the next creature occupies + nextCreature.hexagons.forEach(creatureHex => { + creatureHex.displayVisualState('creature selected player' + nextCreature.team); + }); + } + } } From 4d720bbc7b668529e771eb2df1546e95c4f4ab13 Mon Sep 17 00:00:00 2001 From: xTammaro Date: Tue, 17 Oct 2023 15:46:14 +1100 Subject: [PATCH 11/11] Multi directional fix --- src/utility/hexgrid.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index c74149daa..6cd5bc05a 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -883,11 +883,29 @@ export class HexGrid { } } + + // Function to find the path of a given hex + const findDirectionalPathOfHex = (hex) => { + let startIndex = o.hexes.indexOf(hex); + let endIndex = startIndex; + // Find the start of the path + while (startIndex > 0 && o.hexes[startIndex - 1].direction === hex.direction) { + startIndex--; + } + // Find the end of the path + while (endIndex < o.hexes.length - 1 && o.hexes[endIndex + 1].direction === hex.direction) { + endIndex++; + } + // Extract the path + return o.hexes.slice(startIndex, endIndex + 1); + }; + // Function to determine if an empty hex is before or after the first creature in path const emptyHexBeforeCreature = (hex) => { - const index = o.hexes.indexOf(hex); - const beforeEmpty = o.hexes.slice(0, index); - const afterEmpty = o.hexes.slice(index + 1); + const path = findDirectionalPathOfHex(hex); + const index = path.findIndex(h => h === hex); + const beforeEmpty = path.slice(0, index); + const afterEmpty = path.slice(index + 1); // Check conditions if (beforeEmpty.some(hex => hex.creature instanceof Creature)) { return false;