Skip to content

Commit

Permalink
Fix a regression on "animation by index" action when the index is not…
Browse files Browse the repository at this point in the history
… an integer (#6498)
  • Loading branch information
D8H authored Apr 3, 2024
1 parent abce34f commit eff1c1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
31 changes: 16 additions & 15 deletions GDJS/Runtime/SpriteAnimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ namespace gdjs {
/** Represents a point in a coordinate system. */
export type SpritePoint = {
/** X position of the point. */
x: number;
x: float;
/** Y position of the point. */
y: number;
y: float;
};

/** Represents a custom point in a frame. */
export type SpriteCustomPointData = {
/** Name of the point. */
name: string;
/** X position of the point. */
x: number;
x: float;
/** Y position of the point. */
y: number;
y: float;
};

/** Represents the center point in a frame. */
Expand All @@ -24,9 +24,9 @@ namespace gdjs {
/** Is the center automatically computed? */
automatic: boolean;
/** X position of the point. */
x: number;
x: float;
/** Y position of the point. */
y: number;
y: float;
};

/** Represents a {@link gdjs.SpriteAnimationFrame}. */
Expand All @@ -48,7 +48,7 @@ namespace gdjs {
/** Represents the data of a {@link gdjs.SpriteAnimationDirection}. */
export type SpriteDirectionData = {
/** Time between each frame, in seconds. */
timeBetweenFrames: number;
timeBetweenFrames: float;
/** Is the animation looping? */
looping: boolean;
/** The list of frames. */
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace gdjs {
* Represents a direction of an animation of a {@link gdjs.SpriteRuntimeObject}.
*/
export class SpriteAnimationDirection<T> {
timeBetweenFrames: number;
timeBetweenFrames: float;
loop: boolean;
frames: SpriteAnimationFrame<T>[] = [];

Expand Down Expand Up @@ -450,12 +450,13 @@ namespace gdjs {
this._onFrameChange = callback;
}

getAnimationIndex(): number {
getAnimationIndex(): integer {
return this._currentAnimation;
}

setAnimationIndex(newAnimation: number): boolean {
newAnimation = newAnimation || 0;
setAnimationIndex(newAnimation: integer): boolean {
// Truncate the index.
newAnimation = newAnimation | 0;
if (
newAnimation < this._animations.length &&
this._currentAnimation !== newAnimation &&
Expand Down Expand Up @@ -535,7 +536,7 @@ namespace gdjs {
* Change the current frame displayed by the animation
* @param newFrameIndex The index of the frame to be displayed
*/
setAnimationFrameIndex(newFrameIndex: number): boolean {
setAnimationFrameIndex(newFrameIndex: integer): boolean {
if (
this._currentAnimation >= this._animations.length ||
this._currentDirection >=
Expand Down Expand Up @@ -564,7 +565,7 @@ namespace gdjs {
* Get the index of the current frame displayed by the animation
* @return newFrame The index of the frame being displayed
*/
getAnimationFrameIndex(): number {
getAnimationFrameIndex(): integer {
return this._currentFrameIndex;
}

Expand Down Expand Up @@ -601,7 +602,7 @@ namespace gdjs {
return direction.frames.length * direction.timeBetweenFrames;
}

getAnimationFrameCount(): number {
getAnimationFrameCount(): integer {
if (this._currentAnimation >= this._animations.length) {
return 0;
}
Expand All @@ -617,7 +618,7 @@ namespace gdjs {
* @param The new angle (or direction index) to be applied
* @deprecated
*/
setDirectionOrAngle(oldValue: float, newValue: float): number | null {
setDirectionOrAngle(oldValue: float, newValue: float): float | null {
if (this._currentAnimation >= this._animations.length) {
return null;
}
Expand Down
24 changes: 12 additions & 12 deletions GDJS/Runtime/spriteruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace gdjs {
gdjs.Animatable,
gdjs.OpacityHandler {
_animator: gdjs.SpriteAnimator<any>;
_scaleX: number = 1;
_scaleY: number = 1;
_blendMode: number = 0;
_scaleX: float = 1;
_scaleY: float = 1;
_blendMode: integer = 0;
_flippedX: boolean = false;
_flippedY: boolean = false;
opacity: float = 255;
Expand Down Expand Up @@ -220,11 +220,11 @@ namespace gdjs {
* @param newAnimation The index of the new animation to be played
* @deprecated Use `setAnimationIndex` instead
*/
setAnimation(newAnimation: number): void {
setAnimation(newAnimation: integer): void {
this.setAnimationIndex(newAnimation);
}

setAnimationIndex(newAnimation: number): void {
setAnimationIndex(newAnimation: integer): void {
const hasAnimationChanged = this._animator.setAnimationIndex(
newAnimation
);
Expand Down Expand Up @@ -253,11 +253,11 @@ namespace gdjs {
* @return The index of the new animation being played
* @deprecated Use `getAnimationIndex` instead
*/
getAnimation(): number {
getAnimation(): integer {
return this.getAnimationIndex();
}

getAnimationIndex(): number {
getAnimationIndex(): integer {
return this._animator.getAnimationIndex();
}

Expand Down Expand Up @@ -308,7 +308,7 @@ namespace gdjs {
* Get the index of the current frame displayed by the animation
* @return newFrame The index of the frame being displayed
*/
getAnimationFrame(): number {
getAnimationFrame(): integer {
return this._animator.getAnimationFrameIndex();
}

Expand All @@ -324,11 +324,11 @@ namespace gdjs {
}
}

getAnimationDuration(): number {
getAnimationDuration(): float {
return this._animator.getAnimationDuration();
}

getAnimationFrameCount(): number {
getAnimationFrameCount(): integer {
return this._animator.getAnimationFrameCount();
}

Expand Down Expand Up @@ -454,7 +454,7 @@ namespace gdjs {
* @param result Array that will be updated with the result
* (x and y position of the point in global coordinates).
*/
private _transformToGlobal(x: float, y: float, result: number[]) {
private _transformToGlobal(x: float, y: float, result: float[]) {
const animationFrame = this._animator.getCurrentFrame() as SpriteAnimationFrame<
any
>;
Expand Down Expand Up @@ -656,7 +656,7 @@ namespace gdjs {
this._renderer.updateOpacity();
}

getOpacity(): number {
getOpacity(): float {
return this.opacity;
}

Expand Down

0 comments on commit eff1c1b

Please sign in to comment.