Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Nov 14, 2024
1 parent 758b5ac commit 136adb3
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@ npm install @webxdc/highscores

## Usage

Import `@webxdc/highscores` lib (`webxdc.js` also needs to be included) in your `index.html`:
Quick overview of the API:

```js
import "@webxdc/highscores";

// always do this first, only use the API after init() finishes
await window.highscores.init();

// get current player's highscore
const score = window.highscores.getScore();
console.log(`your score: ${score}`);

// this will cause an announcement in chat only if it's a new highscore
window.highscores.setScore(score + 100);

const scoreboard = window.highscores.getHighScores();
scoreboard.forEach((player) => {
console.log(`${player.pos}. ${player.name} - ${player.score}`);
});
```

The `webxdc.js` lib also needs to be included in your `index.html`:

```html
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<script src="webxdc.js"></script>

<script type="module">
import "@webxdc/highscores";
// you can use window.highscores here
</script>
</head>
<body>
...
</body>
<body>...</body>
</html>
```

Expand Down

0 comments on commit 136adb3

Please sign in to comment.