Skip to content

Commit

Permalink
Merge pull request #6 from EGAMAGZ/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
EGAMAGZ authored May 6, 2024
2 parents 867e902 + 7d9eacc commit a2403c2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 32 deletions.
70 changes: 41 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,65 @@ Check the [JSR page for more details](https://jsr.io/@egamagz/paska-ovo).
import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";

const paskaOvo = new PaskaOvo()
.addCallback((easterEgg) => {
console.log("Actual easter egg:", easterEgg.tag);
console.log("Easter egg's code:", easterEgg.code);
.addCode({
code: HistoricalCodes.BarrelRoll,
onFound: () => {
//...
},
onFinish() {
// ...
},
duration: 1000,
tag: "Barrel Roll"
})
.addCode(
HistoricalCodes.Iddqd,
() => {
alert("God Mode");
.addCode({
code: HistoricalCodes.Konami,
onFound: () => {
// ...
},
"Doom",
)
.addCode("left,up,right,down", () => {
alert("Do a Barrel Roll");
}, "Barrel Roll");
tag: "Konami"
})
.addCode({
code: ["a", "w", "e", "s", "o", "m", "e"],
onFound: () => {
// ...
},
tag: "Awesome"
})
.addCallback((easterEgg) => {
alert(`You found the easter egg: ${easterEgg.tag}`)
});

// Listen to keyboard events
document.getElementById("add-easter-egg")
.addEventListener("click", () => {
paskaOvo.listen();
});
document.getElementById("add-easter-egg").addEventListener("click", () => {
paskaOvo.listen();
});

// Stop listening to keyboard events
document.getElementById("remove-easter-egg")
document
.getElementById("remove-easter-egg")
.addEventListener("click", () => {
paskaOvo.stop();
});

```

Alternatively, it's possible to define the easter egg using the constructor:

```typescript
import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";

const paskaOvo = new PaskaOvo(
HistoricalCodes.Konami,
() => {
alert("Gradius");
const paskaOvo = new PaskaOvo({
code: HistoricalCodes.Konami,
onFound: () => {
alert("Gradius");
},
"konami-code",
)
.addCallback((easterEgg) => {
console.log("Actual easter egg:", easterEgg.tag);
console.log("Easter egg's code:", easterEgg.code);
});
tag: "konami-code",
}).addCallback((easterEgg) => {
console.log("Actual easter egg:", easterEgg.tag);
console.log("Easter egg's code:", easterEgg.code);
});

paskaOvo.listen();
paskaOvo.listen();
```

Check the [example](https://egamagz.github.io/paska-ovo/) with [source code](https://github.com/EGAMAGZ/paska-ovo/tree/master/example).
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egamagz/paska-ovo",
"version": "1.0.0",
"version": "1.0.1",
"exports": "./mod.ts",
"lock": false,
"compilerOptions": {
Expand Down
49 changes: 48 additions & 1 deletion src/paska-ovo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,54 @@ import { codeToChars } from "./util/code.ts";

/**
* Class that is used to manage easter eggs.
*/
*
* @example
* ```typescript
* import { HistoricalCodes, PaskaOvo } from "@egamagz/paska-ovo";
*
* const paskaOvo = new PaskaOvo()
* .addCode({
* code: HistoricalCodes.BarrelRoll,
* onFound: () => {
* //...
* },
* onFinish() {
* // ...
* },
* duration: 1000,
* tag: "Barrel Roll"
* })
* .addCode({
* code: HistoricalCodes.Konami,
* onFound: () => {
* // ...
* },
* tag: "Konami"
* })
* .addCode({
* code: ["a", "w", "e", "s", "o", "m", "e"],
* onFound: () => {
* // ...
* },
* tag: "Awesome"
* })
* .addCallback((easterEgg) => {
* alert(`You found the easter egg: ${easterEgg.tag}`)
* });
*
* // Listen to keyboard events
* document.getElementById("add-easter-egg").addEventListener("click", () => {
* paskaOvo.listen();
* });
*
* // Stop listening to keyboard events
* document
* .getElementById("remove-easter-egg")
* .addEventListener("click", () => {
* paskaOvo.stop();
* });
*```
* */
export class PaskaOvo {
/**
* List of easter eggs registered.
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type EasterEgg = {
* */
onFinish?: () => void,
/**
* Duration of the easter egg. Once it is finished, onFinish will be called.
* Duration in milliseconds of the easter egg. Once it is finished, onFinish will be called.
* */
duration?: number,
};
Expand Down

0 comments on commit a2403c2

Please sign in to comment.