Skip to content

Commit

Permalink
issue #2003: rotating targeting cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaflak committed Nov 5, 2024
1 parent 41eb015 commit ee73487
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/utility/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export class Hex {
*/
displayPos: { x: number; y: number };

/**
* Set to true if cursor is outside movement range.
*/
isSpinning: boolean;

/**
* Store ID of animation frame request.
*/
spinRequest: number;

originalDisplayPos: { x: number; y: number };
tween: Phaser.Tween;
hitBox: Phaser.Sprite;
Expand Down Expand Up @@ -131,6 +141,9 @@ export class Hex {

this.originalDisplayPos = $j.extend({}, this.displayPos);

this.isSpinning = false;
this.spinRequest = null;

this.tween = null;

if (grid) {
Expand Down Expand Up @@ -499,7 +512,40 @@ export class Hex {
this.updateStyle();
}

/**
* Start spin effect for the targeting cursor
*/
startSpinning() {
this.isSpinning = true;
const spinSpeed = 2;

const rotate = () => {
if (!this.isSpinning) return;
this.overlay.angle += spinSpeed;
this.spinRequest = requestAnimationFrame(rotate);
};

this.spinRequest = requestAnimationFrame(rotate);
}

/**
* Stop spin effect for the targeting cursor
*/
stopSpinning() {
this.isSpinning = false;
if (this.spinRequest) {
cancelAnimationFrame(this.spinRequest);
this.spinRequest = null;
this.overlay.angle = 0;
}
}

updateStyle() {
// Reset spinning state
if (this.isSpinning) {
this.stopSpinning();
}

// Display Hex
let targetAlpha = this.reachable || Boolean(this.displayClasses.match(/creature/g));

Expand Down Expand Up @@ -587,6 +633,10 @@ export class Hex {
this.grid.overlayHexesGroup.bringToTop(this.overlay);
} else {
this.overlay.loadTexture('cancel');
this.overlay.anchor.set(0.5, 0.5);
if (!this.isSpinning) {
this.startSpinning();
}
}

this.overlay.alpha = targetAlpha ? 1 : 0;
Expand Down

0 comments on commit ee73487

Please sign in to comment.