From 060f0cc1210699ab8f48e535bc872c28ccdf7c15 Mon Sep 17 00:00:00 2001 From: Joao Paulo Oliveira Fernandes Date: Sun, 14 Apr 2024 21:16:22 -0300 Subject: [PATCH] improving sprite base checks --- base/ControllableChar.ts | 4 +++- base/SpriteBase.ts | 10 +++++++++- static/phaser.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/base/ControllableChar.ts b/base/ControllableChar.ts index 95c71d4ba..071764ce7 100644 --- a/base/ControllableChar.ts +++ b/base/ControllableChar.ts @@ -773,7 +773,9 @@ export abstract class ControllableChar { } const animation_key = this.sprite_info.getAnimationKey(action, animation); if (!this.sprite.animations.getAnimation(animation_key)) { - this.sprite_info.setAnimation(this.sprite, action); + if (!this.sprite_info.setAnimation(this.sprite, action)) { + return null; + } } const animation_obj = this.sprite.animations.getAnimation(animation_key); if (!animation_obj) { diff --git a/base/SpriteBase.ts b/base/SpriteBase.ts index eae8908e0..83d75b945 100644 --- a/base/SpriteBase.ts +++ b/base/SpriteBase.ts @@ -125,7 +125,7 @@ export class SpriteBase { const action_key = this.getSpriteKey(action); if (game.cache.checkImageKey(action_key)) { this.data.logger.log_message( - `Sprite key '/' '${action_key} is already registered in the engine. Please consider renaming it.'`, + `Sprite key '/' '${action_key}' is already registered in the engine. Please consider renaming it.`, msg_types.ERROR ); } @@ -162,10 +162,18 @@ export class SpriteBase { Array.isArray(loop) ? loop[i] : loop, false ); + if (!sprite.animations.frameData.getFrameByName(`${anim_key}${SpriteBase.ACTION_ANIM_SEPARATOR}00`)) { + this.data.logger.log_message( + `Animation '${anim_key}' is not valid for action '${action}' for sprite '${this.key_name}'.`, + msg_types.ERROR + ); + return false; + } } } else { this.data.logger.log_message(`Action '${action}' not available for '${this.key_name}'.`); } + return true; } generateAllFrames() { diff --git a/static/phaser.js b/static/phaser.js index 4eaf97652..d7a293f11 100644 --- a/static/phaser.js +++ b/static/phaser.js @@ -73458,7 +73458,7 @@ Phaser.FrameData.prototype = { */ checkFrameName: function (name) { - if (this._frameNames[name] == null) + if (this._frameNames[name] == null || this._frameNames[name] === undefined) { return false; }