Skip to content

Commit

Permalink
Merge pull request #2572 from gg447062/move-preview
Browse files Browse the repository at this point in the history
Unit movement location preview, fixes #2533
  • Loading branch information
DreadKnight authored Apr 25, 2024
2 parents dbdf9ca + c819b48 commit 159d4df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,20 @@ export class Creature {
return;
}

if (game.grid.materialize_overlay) {
const creature = game.retrieveCreatureStats(game.activeCreature.type);
game.Phaser.add
.tween(game.grid.materialize_overlay)
.to(
{
alpha: 0,
},
creature.animation.walk_speed,
Phaser.Easing.Linear.None,
)
.start();
}

game.gamelog.add({
action: 'move',
target: {
Expand Down Expand Up @@ -697,6 +711,8 @@ export class Creature {
};

const selectFlying = function (hex, args) {
const creature = game.retrieveCreatureStats(game.activeCreature.type);
game.grid.previewCreature(hex, creature, game.activePlayer);
args.creature.tracePosition({
x: hex.x,
y: hex.y,
Expand Down Expand Up @@ -738,12 +754,14 @@ export class Creature {
*/
previewPosition(hex: Hex) {
const game = this.game;

game.grid.cleanOverlay('hover h_player' + this.team);
if (!game.grid.hexes[hex.y][hex.x].isWalkable(this.size, this.id)) {
return; // Break if not walkable
}

const creat = game.retrieveCreatureStats(game.activeCreature.type);
game.grid.previewCreature(hex.pos, creat, game.activePlayer);

this.tracePosition({
x: hex.x,
y: hex.y,
Expand Down Expand Up @@ -935,6 +953,8 @@ export class Creature {
// Highlight final position
const last: any = arrayUtils.last(path);

const creature = this.game.retrieveCreatureStats(this.game.activeCreature.type);
this.game.grid.previewCreature(last, creature, this.game.activePlayer);
this.tracePosition({
x: last.x,
y: last.y,
Expand All @@ -951,7 +971,6 @@ export class Creature {
displayClass: '',
drawOverCreatureTiles: true,
};

args = $j.extend(defaultArgs, args);

for (let i = 0; i < this.size; i++) {
Expand Down
8 changes: 6 additions & 2 deletions src/utility/hexgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1609,15 +1609,19 @@ export class HexGrid {
previewCreature(pos, creatureData, player) {
const game = this.game;
const hex = this.hexes[pos.y][pos.x - (creatureData.size - 1)];
const cardboard =
creatureData.type == '--'
? creatureData.name + game.activePlayer.color + '_cardboard'
: creatureData.name + '_cardboard';

if (!this.materialize_overlay) {
// If sprite does not exists
// Adding sprite
this.materialize_overlay = this.creatureGroup.create(0, 0, creatureData.name + '_cardboard');
this.materialize_overlay = this.creatureGroup.create(0, 0, cardboard);
this.materialize_overlay.anchor.setTo(0.5, 1);
this.materialize_overlay.posy = pos.y;
} else {
this.materialize_overlay.loadTexture(creatureData.name + '_cardboard');
this.materialize_overlay.loadTexture(cardboard);
if (this.materialize_overlay.posy != pos.y) {
this.materialize_overlay.posy = pos.y;
this.orderCreatureZ();
Expand Down

0 comments on commit 159d4df

Please sign in to comment.