Skip to content

Commit

Permalink
Merge pull request #492 from Facug03/codes
Browse files Browse the repository at this point in the history
Añadir MiduCode al componente KonamiCode
  • Loading branch information
midudev authored Mar 13, 2024
2 parents 1af3dcc + a493aa8 commit 13671fd
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 107 deletions.
54 changes: 53 additions & 1 deletion src/components/KonamiCode.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
<style is:global>
.bubbles {
border-radius: 50%;
object-fit: cover;
object-position: center;
position: absolute;
width: 60px;
height: 60px;
opacity: 1;
bottom: -50px;
display: block;
animation: bubble linear forwards 3s;
}

#midu {
width: 150px;
height: 150px;
left: 50%;
transform: translateX(-50%);
}

@keyframes bubble {
from {
opacity: 1;
bottom: -50px;
}

to {
opacity: 0;
bottom: 80vh;
transform: rotate(0deg);
}
}
</style>

<script>
import { konamiCodes } from "@/consts/konami-codes"
import { Konami } from "@/function/konami"
import { checkAndRemoveContainer, showContributors } from "@/function/miduCode"
import { $ } from "@/consts/dom-selector"

const { rotateY, gloveCursor, amongUsCursor, lolCursor } = konamiCodes
const { rotateY, gloveCursor, amongUsCursor, lolCursor, midu } = konamiCodes

const $container = $("#main-content")
const $miduContainer = document.createElement("div")

document.addEventListener("keydown", ({ key }) => {
Konami({
Expand Down Expand Up @@ -45,5 +82,20 @@
$("body").style.cursor = "url('/img/cursor/among-us.cur'), auto"
},
})

Konami({
code: midu,
keyPressed: key,
onFinishTime: 1500,
onSuccess: () => {
$miduContainer.style.cssText =
"position: fixed; width: 100dvw; height: 100vh; background: rgba(0,0,0,0.3); z-index: 10; inset: 0"
document.body.appendChild($miduContainer)
showContributors($miduContainer)
},
onFinish: () => {
checkAndRemoveContainer($miduContainer)
},
})
})
</script>
105 changes: 0 additions & 105 deletions src/components/MiduCode.astro

This file was deleted.

1 change: 1 addition & 0 deletions src/consts/konami-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const konamiCodes = {
gloveCursor: ["g", "l", "o", "v", "e"],
amongUsCursor: ["a", "m", "o", "n", "g", "u", "s"],
lolCursor: ["l", "o", "l"],
midu: ["m", "i", "d", "u"],
}
48 changes: 48 additions & 0 deletions src/function/miduCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
interface Contributor {
avatar_url: string
login: string
}

export async function showContributors($miduContainer: HTMLDivElement) {
const url = "https://api.github.com/repos/midudev/la-velada-web-oficial/contributors"

const response = await fetch(url)
const contributors = (await response.json()) as Contributor[]

for (let i = 0; i < contributors.length; i++) {
setTimeout(() => {
const { avatar_url, login } = contributors[i]
const img = document.createElement("img")
img.src = avatar_url
img.alt = login
img.title = login
img.classList.add("bubbles")
if (login === "midudev") {
img.setAttribute("id", "midu")
} else {
img.style.left = `${generateRandomNumber()}vw`
const startRotation = Math.floor(Math.random() * (90 - -90 + 1)) + -45
img.style.transform = `rotate(${startRotation}deg)`
}
img.addEventListener("animationend", () => {
$miduContainer.removeChild(img)
})
$miduContainer.appendChild(img)
}, i * 300)
}
}

export function checkAndRemoveContainer($miduContainer: HTMLDivElement) {
if ($miduContainer.childElementCount === 0) {
$miduContainer.remove()
return
}

setTimeout(() => {
checkAndRemoveContainer($miduContainer)
}, 1000)
}

function generateRandomNumber() {
return Math.floor(Math.random() * 91) + 5
}
1 change: 0 additions & 1 deletion src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const { title, description, preloadImgLCP } = Astro.props
<slot />
<Footer />
<KonamiCode />
<MiduCode />
</div>
<ButtonUp />
<style is:global>
Expand Down

0 comments on commit 13671fd

Please sign in to comment.