Skip to content

Commit

Permalink
feat: Expose AsepriteSpriteSheet.animation
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 12, 2024
1 parent 70e8cb5 commit 2693e9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/AsepriteResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class AsepriteResource implements Loadable<AsepriteSpriteSheet> {
if (this.isLoaded()) {
return this.data.getSpriteSheet();
} else {
Logger.getInstance().warn('AspriteResource must be loaded before .getSpriteSheet() is called');
Logger.getInstance().warn('AsepriteResource must be loaded before .getSpriteSheet() is called');
}
}

Expand All @@ -95,7 +95,7 @@ export class AsepriteResource implements Loadable<AsepriteSpriteSheet> {
return this._nativeParser!.getAnimation(name);
}
} else {
Logger.getInstance().warn('AspriteResource must be loaded before .getAnimation() is called');
Logger.getInstance().warn('AsepriteResource must be loaded before .getAnimation() is called');
}
return null;
}
Expand Down
10 changes: 4 additions & 6 deletions src/AsepriteSpriteSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@ import { SpriteSheet, Animation } from "excalibur";

export class AsepriteSpriteSheet {
private _spriteSheet!: SpriteSheet;
private _animations = new Map<string, Animation>()

constructor(spriteSheet: SpriteSheet, animations: Map<string, Animation>) {
constructor(spriteSheet: SpriteSheet, public animations: Map<string, Animation>) {
this._spriteSheet = spriteSheet;
this._animations = animations;
}

getSpriteSheet(): SpriteSheet {
return this._spriteSheet
}

getAnimation(name: string): Animation {
if (!this._animations.has(name)) {
if (!this.animations.has(name)) {
throw new Error(`No animation exists with name ${name}, check your exported Aseprite file`);
}
return this._animations.get(name) as Animation;
return this.animations.get(name) as Animation;
}

clone() {
const newAnimations = new Map<string, Animation>();
for (let [key, value] of this._animations.entries()) {
for (let [key, value] of this.animations.entries()) {
newAnimations.set(key, value.clone());
}
const newSpriteSheet = new SpriteSheet({
Expand Down

0 comments on commit 2693e9b

Please sign in to comment.