From d46cc558d2c5feab1bd69dacca60c8d5b00ed156 Mon Sep 17 00:00:00 2001 From: "Sean S. LeBlanc" Date: Thu, 7 Apr 2022 22:33:19 -0400 Subject: [PATCH] fix(avatar by room): multi-sprite avatar not resetting --- src/avatar by room.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/avatar by room.js b/src/avatar by room.js index 0b227f68..6bfbccf5 100644 --- a/src/avatar by room.js +++ b/src/avatar by room.js @@ -52,17 +52,27 @@ after('load_game', function () { originalAnimation = bitsy.player().animation; }); -function updateAvatar() { +var currentRoom; +before('drawRoom', function () { var player = bitsy.player(); + if (player.room === currentRoom) { + return; + } + currentRoom = player.room; var newAvatarId = hackOptions.avatarByRoom[currentRoom]; + var shouldReset = + (!newAvatarId && !hackOptions.permanent) || // if no sprite defined + not permanent, reset + newAvatarId === player.id; // manual reset + if (window.hacks && window.hacks['multi-sprite_avatar'] && window.hacks['multi-sprite_avatar'].enableBig) { // HACK: support multi-sprite avatar by room - window.hacks['multi-sprite_avatar'].enableBig(newAvatarId); + if (shouldReset) { + window.hacks['multi-sprite_avatar'].enableBig(); + } else { + window.hacks['multi-sprite_avatar'].enableBig(newAvatarId); + } } else { - if ( - (!newAvatarId && !hackOptions.permanent) || // if no sprite defined + not permanent, reset - newAvatarId === player.id // manual reset - ) { + if (shouldReset) { player.drw = originalDrw; player.animation = originalAnimation; return; @@ -74,14 +84,4 @@ function updateAvatar() { player.drw = newAvatar.drw; player.animation = Object.assign({}, newAvatar.animation); } -} - -var currentRoom; -before('drawRoom', function () { - var player = bitsy.player(); - if (player.room === currentRoom) { - return; - } - currentRoom = player.room; - updateAvatar(currentRoom); });