Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moroboxai/moroboxai-player-web
Embeddable player for running MoroboxAI games on the web
https://github.com/moroboxai/moroboxai-player-web
ai artificial-intelligence game javascript moroboxai npm sandbox-environment typescript
Last synced: about 2 months ago
JSON representation
Embeddable player for running MoroboxAI games on the web
- Host: GitHub
- URL: https://github.com/moroboxai/moroboxai-player-web
- Owner: moroboxai
- License: mit
- Created: 2022-04-08T07:53:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-02T07:31:36.000Z (about 1 year ago)
- Last Synced: 2024-10-13T08:04:55.731Z (3 months ago)
- Topics: ai, artificial-intelligence, game, javascript, moroboxai, npm, sandbox-environment, typescript
- Language: TypeScript
- Homepage:
- Size: 6.74 MB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# moroboxai-player-web
[![NPM version](https://img.shields.io/npm/v/moroboxai-player-web.svg)](https://www.npmjs.com/package/moroboxai-player-web)
![Node.js CI](https://github.com/moroboxai/moroboxai-player-web/workflows/Node.js%20CI/badge.svg)
[![gitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/moroboxai/moroboxai-player-web/blob/master/LICENSE)
[![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/moroboxai/moroboxai-player-web.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/moroboxai/moroboxai-player-web/context:javascript)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/moroboxai/moroboxai-player-web.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/moroboxai/moroboxai-player-web/alerts)Embeddable player for running [MoroboxAI](https://github.com/moroboxai) games on the web.
## Install
Using npm:
```bash
npm install moroboxai-player-web --save
```## Usage
```html
// Initialize the player on our div
const player = MoroboxAIPlayer.init({
element: document.getElementById("player"),
url: "https://raw.githubusercontent.com/moroboxai/moroboxai-games/master/games/pong/",
splashart:
"https://raw.githubusercontent.com/moroboxai/moroboxai-games/master/games/pong/assets/splashart.png",
width: 256,
height: 256
});// Will be called when the game is ready
player.onReady = () => console.log("game is loaded and ready");// Optionally start the game
player.play();
```
## Arguments
| Name | Type | Default | Description |
| :-------- | :------ | :------ | :---------------------------------------------------------------------------------------- |
| element | Element | | DOM element to attach the player to |
| url | string | | URL of the game |
| header | object | | Game header |
| splashart | string | | URL of the placeholder image displayed before the game is loaded |
| width | number | | Width of the `div` element |
| height | number | | Height of the `div` element |
| resizable | boolean | true | If the game can resize the player |
| autoPlay | boolean | false | Auto play the game after the player is initialized |
| speed | number | 1 | Speed of the game |
| agents | array | | Agents to load into controllers |
| onReady | func | noop | **Signature: function() => void**
Function called when the game is loaded and ready |## Pause
```js
const player = MoroboxAIPlayer.init({...});pauseButton.onclick = () => player.pause();
playButton.onclick = () => player.play();
```## Stop
```js
const player = MoroboxAIPlayer.init({...});stopButton.onclick = () => player.stop();
```## Reload
```js
const player = MoroboxAIPlayer.init({...});reloadButton.onclick = () => player.reload();
```## Stop & Load another game
```js
const player = MoroboxAIPlayer.init({...});button.onclick = () => player.play("http://url/to/game");
```## Resize
```js
const player = MoroboxAIPlayer.init({...});
player.width = 128;
player.height = 128;
player.resize({width: 256, height: 256});
```## Change speed
```js
const player = MoroboxAIPlayer.init({...});
player.speed = 2;
```## Cleanup
```js
const player = MoroboxAIPlayer.init({...});
player.remove();
```## License
This content is released under the [MIT](http://opensource.org/licenses/MIT) License.