@webxdc/highscores
Advanced tools
Comparing version 5.0.2 to 5.1.0
{ | ||
"name": "@webxdc/highscores", | ||
"description": "Highscores API for webxdc apps", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"license": "MIT", | ||
@@ -19,19 +19,17 @@ "author": "adbenitez", | ||
"homepage": "https://github.com/webxdc/highscores", | ||
"main": "./dist/highscores.umd.js", | ||
"module": "./dist/highscores.mjs", | ||
"types": "./dist/highscores.d.ts", | ||
"main": "./src/highscores.js", | ||
"module": "./src/highscores.js", | ||
"types": "./src/highscores.d.ts", | ||
"source": "./src/highscores.js", | ||
"files": [ | ||
"dist" | ||
"src" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/highscores.mjs", | ||
"require": "./dist/highscores.umd.js" | ||
"import": "./src/highscores.js" | ||
}, | ||
"./dist/highscores.css": "./dist/highscores.css" | ||
"./src/highscores.css": "./src/highscores.css" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^3.3.3", | ||
"vite": "^5.4.10" | ||
"prettier": "^3.3.3" | ||
}, | ||
@@ -42,3 +40,2 @@ "dependencies": { | ||
"scripts": { | ||
"build": "vite build", | ||
"fix": "prettier --write .", | ||
@@ -45,0 +42,0 @@ "check": "prettier --check ." |
# Highscores | ||
[](https://npmjs.com/package/@webxdc/highscores) | ||
[](https://github.com/webxdc/highscores/actions/workflows/ci.yml) | ||
[](https://github.com/prettier/prettier) | ||
Library to facilitate the process of creating score-based webxdc games. | ||
@@ -14,4 +18,25 @@ It can handle multiple scoreboards at the same time. | ||
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 | ||
@@ -23,3 +48,2 @@ <html> | ||
<script src="webxdc.js"></script> | ||
<script type="module"> | ||
@@ -36,23 +60,4 @@ import "@webxdc/highscores"; | ||
## Usage without modules | ||
Check [dist/highscores.d.ts](https://github.com/webxdc/highscores/blob/main/dist/highscores.d.ts) file for documentation of the available API. | ||
Include webxdc-scores lib (together with `webxdc.js`) in your `index.html`: | ||
```html | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<script src="webxdc.js"></script> | ||
<script src="./node_modules/@webxdc/highscores/dist/webxdc-scores.umd.js"></script> | ||
</head> | ||
<body> | ||
... | ||
</body> | ||
</html> | ||
``` | ||
Then you can access the API via `window.highscores` object, check [dist/highscores.d.ts](https://github.com/webxdc/highscores/blob/main/dist/highscores.d.ts) file for documentation of the available API. | ||
For a full example check the [example/index.html](https://github.com/webxdc/highscores/blob/main/example/index.html) file. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
61
11471
6
227
1