Skip to content

Instantly share code, notes, and snippets.

@bostrt
Created April 6, 2022 18:31
Show Gist options
  • Save bostrt/fca7cac82c8cfd42be3361e7812bc225 to your computer and use it in GitHub Desktop.
Save bostrt/fca7cac82c8cfd42be3361e7812bc225 to your computer and use it in GitHub Desktop.
Multi-sprite avatar by room example
// The following changes will allow for multi-sprite avatars, per room.
// I've enabled the following hacks:
// - multi-sprite-avatar
// - avatar-by-room
///////////////////////////////////////
// Updates to multi-sprite-avatar hack
///////////////////////////////////////
// - Convert the pieces array to a dictionary with the key being a room ID and the value being the array of sprite pieces.
hackOptions = {
pieces: {
"bdrm_bedroom": [{x: 0, y: 0, spr: "bdrm_a"}, {x: 1, y: 0, spr: "bdrm_b"}, {x: 0, y: 1, spr: "bdrm_c"}, {x: 1, y: 1, spr: "bdrm_d"}],
"ktchn_kitchen": [{x: 0, y: 0, spr: "bdrm_a"}, {x: 1, y: 0, spr: "bdrm_b"}, {x: 0, y: 1, spr: "bdrm_c"}, {x: 1, y: 1, spr: "bdrm_d"}],
"ktchn_kitchen2": [{x: 0, y: 0, spr: "bdrm_a"}, {x: 1, y: 0, spr: "bdrm_coffeehand"}, {x: 0, y: 1, spr: "bdrm_c"}, {x: 1, y: 1, spr: "bdrm_d"}],
"ofc_office": [{x: 0, y: 0, spr: "bdrm_a"}, {x: 1, y: 0, spr: "bdrm_coffeehand"}, {x: 0, y: 1, spr: "bdrm_c"}, {x: 1, y: 1, spr: "bdrm_d"}],
},enabledOnStart: true,
};
// Modify enableBig so it gets pieces for the active room:
function enableBig(newPieces) {
disableBig();
pieces = newPieces || hackOptions.pieces[bitsy.player().room];
enabled = true;
syncPieces();
}
// Add new trigger that loads new sprite when a new room is initialized:d
after('initRoom', function() {
disableBig();
pieces = hackOptions.pieces[bitsy.player().room];
if (pieces.length == 0) {
console.warn("no big avatar!");
}
enabled = true;
syncPieces();
});
///////////////////////////////////////
// Updates to multi-sprite-avatar hack
///////////////////////////////////////
// NO CHANGES NEEDED for avatar-by-room hack but here's an example to match the sprites above
var hackOptions = {
permanent: false,
avatarByRoom: {
'myotherroom': 'myothersprite',
'ktchn_kitchen': 'bdrm_a',
'ktchn_kitchen2': 'bdrm_a',
'bdrm_bedroom': 'bdrm_a',
'ofc_office': 'bdrm_a',
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment