Skip to content

Commit

Permalink
Merge pull request #7 from EGAMAGZ/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
EGAMAGZ authored May 22, 2024
2 parents a2403c2 + fad905b commit d0e6f67
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
7 changes: 0 additions & 7 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@astrojs/check": "^0.5.10",
"@astrojs/preact": "^3.2.0",
"@astrojs/tailwind": "^5.1.0",
"@egamagz/paska-ovo": "npm:@jsr/egamagz__paska-ovo@^0.1.2",
"@preact/signals": "^1.2.3",
"@preact/signals-core": "^1.6.0",
"@tabler/icons-preact": "^3.3.0",
Expand Down
7 changes: 7 additions & 0 deletions example/src/components/EasterEgg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export default function EasterEgg() {
},
tag: "Konami"
})
.addCode({
code: ["up", "up", "down", "down", "left", "right", "left", "right", "b", "a", "c"],
onFound: () => {
alert("Nothing to show here... Sorry :(")
},
tag: "Konami+C"
})
.addCode({
code: ["a", "w", "e", "s", "o", "m", "e"],
onFound: () => {
Expand Down
2 changes: 1 addition & 1 deletion example/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="paska-ovo/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<meta
Expand Down
11 changes: 3 additions & 8 deletions src/paska-ovo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ export class PaskaOvo {
* @param {EasterEgg[]} easterEggs - List of easter eggs to trigger.
*/
private handleKeyEvent(event: KeyboardEvent, easterEggs: EasterEgg[]) {
if (easterEggs.length === 0) {
return;
}

const { key } = event;

easterEggs.forEach((easterEgg) => {
for (const easterEgg of easterEggs) {
const actualCodePosition = this.easterEggState[easterEgg.tag] || 0;
const actualCode = easterEgg.code[actualCodePosition];

if (key !== actualCode) {
this.easterEggState[easterEgg.tag] = 0;
return;
continue;
}

const nextCodePosition = actualCodePosition + 1;
Expand All @@ -136,7 +131,7 @@ export class PaskaOvo {
} else {
this.easterEggState[easterEgg.tag] = nextCodePosition;
}
});
}
}

/**
Expand Down
44 changes: 43 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,52 @@
/**
* Type with the properties of an easter egg.
*
* @example
* A simple easter egg:
* ```typescript
* import { EasterEgg } from "@egamagz/paska-ovo";
*
* const easterEgg: EasterEgg = {
* code: ["up", "up", "down", "down", "left", "right", "left", "right", "b", "a"],
* onFound: () => {
* // Do something when the easter egg is found
* },
* tag: "Konami",
* }
* ```
*
* @example
* An easter egg with a duration:
* ```typescript
* const easterEgg: EasterEgg = {
* code: ["up", "right", "down", "left"],
* onFound: () => {
* // Do something when the easter egg is found
* },
* onFinish() {
* // Do something when the duration of the easter egg is over
* },
* duration: 1000,
* tag: "Barrel Roll"
* }
* ```
*/
export type EasterEgg = {
/**
* Sequence of keys that will trigger the easter egg.
* Key sequence that will activate the easter egg. The code can contain
* letters (which will only be detected as lowercase), numbers and navigation
* and control keys. The navigation and control keys are indicated by the following nomenclature:
* * `up`: `ArrowUp`
* * `down`: `ArrowDown`
* * `left`: `ArrowLeft`
* * `right`: `ArrowRight`
* * `enter`: `Enter`
* * `space`: `Space`
* * `ctrl`: `Control`
* * `alt`: `Alt`
* * `tab`: `Tab`
* * `esc`: `Escape`
* * `slash`: `/`
*/
code: string[],
/**
Expand Down
1 change: 0 additions & 1 deletion src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ export const SPECIAL_KEYS: Record<string, string> = {
"tab": "Tab",
"esc": "Escape",
} as const;

0 comments on commit d0e6f67

Please sign in to comment.