mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 04:07:23 +00:00
Add hat collection message
This commit is contained in:
@@ -396,7 +396,7 @@ function startApplication(birbPixels, featherPixels, hatsPixels) {
|
||||
focusOnElement(true);
|
||||
|
||||
// TODO: This is for testing
|
||||
generateHat();
|
||||
insertHat();
|
||||
}
|
||||
|
||||
function update() {
|
||||
@@ -583,13 +583,13 @@ function startApplication(birbPixels, featherPixels, hatsPixels) {
|
||||
/**
|
||||
* Insert the hat as an item element in the document if possible
|
||||
*/
|
||||
function generateHat() {
|
||||
function insertHat() {
|
||||
if (document.querySelector("#" + HAT_ID)) {
|
||||
return;
|
||||
}
|
||||
// Select a random hat
|
||||
const hatKeys = Object.keys(HAT);
|
||||
const hatId = hatKeys[Math.floor(Math.random() * (hatKeys.length - 1)) + 1];
|
||||
const hats = Object.values(HAT);
|
||||
const hatId = hats[Math.floor(Math.random() * (hats.length - 1)) + 1];
|
||||
|
||||
// Find a random valid element to place the hat on
|
||||
const element = getRandomValidElement();
|
||||
@@ -607,6 +607,17 @@ function startApplication(birbPixels, featherPixels, hatsPixels) {
|
||||
if (!hatCtx) {
|
||||
return;
|
||||
}
|
||||
onClick(hatCanvas, () => {
|
||||
switchHat(hatId);
|
||||
hatCanvas.remove();
|
||||
const message = makeElement("birb-message-content");
|
||||
message.appendChild(document.createTextNode("You've unlocked the "));
|
||||
const bold = document.createElement("b");
|
||||
bold.textContent = HAT_METADATA[hatId].name;
|
||||
message.appendChild(bold);
|
||||
message.appendChild(document.createTextNode("! To see all of your unlocked accessories, click the Wardrobe from the menu."));
|
||||
insertModal("New Hat Found!", message);
|
||||
});
|
||||
|
||||
// Create hat animation
|
||||
const hatAnimation = createHatItemAnimation(hatId, HATS_SPRITE_SHEET);
|
||||
@@ -892,6 +903,7 @@ function startApplication(birbPixels, featherPixels, hatsPixels) {
|
||||
* @param {string} hat
|
||||
*/
|
||||
function switchHat(hat) {
|
||||
log("Switching hat to: " + hat);
|
||||
currentHat = hat;
|
||||
save();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user