Update exported interface and README
This commit is contained in:
parent
95d64831a6
commit
ebf77ca65e
4 changed files with 21 additions and 9 deletions
18
README.md
18
README.md
|
|
@ -48,13 +48,13 @@ For now there are three ways to include the viewer:
|
|||
|
||||
- By importing individual components: If you want to integrate into an existing Vue APP, for example
|
||||
- Through `index.ts`, the default export is the `launch` function: The viewer will create its own Vue App on the given selector
|
||||
- Through `unpkg.com/@gaia-project/viewer`, which will set `window.launch` or `global.launch`. All dependencies are included in the bundle, including `vue` itself.
|
||||
- Through `unpkg.com/@gaia-project/viewer`, which will set `window.gaiaViewer` or `global.gaiaViewer`. All dependencies are included in the bundle, including `vue` itself.
|
||||
|
||||
If you want something else, like an standalone bundle *without* vue, or a standalone bundle without *any* external dependency, contact us and we will add those.
|
||||
|
||||
### launch functtion
|
||||
### launch function
|
||||
|
||||
The default export, and `window.launch` / `global.launch` when included via a `script` tag, is a function taking a css selector as an argument. When executed, it instantiates a Game on the aformentioned element, and returns an `EventEmitter` that can be communicated with.
|
||||
The default export, and `window.gaiaViewer.launch` / `global.gaiaViewer.launch` when included via a `script` tag, is a function taking a css selector as an argument. When executed, it instantiates a Game on the aformentioned element, and returns an `EventEmitter` that can be communicated with.
|
||||
|
||||
The EventEmitter has this interface:
|
||||
|
||||
|
|
@ -65,4 +65,14 @@ emitter.emit('state:updated', gameData);
|
|||
emitter.on('move', (move) => {/* send move to backend and give back result */});
|
||||
```
|
||||
|
||||
Possibly more functions will be added, for example to set / unset planetFill, there could be a `preferences` event.
|
||||
Possibly more functions will be added, for example to set / unset planetFill, there could be a `preferences` event.
|
||||
|
||||
If you want a self-contained game which plays in the browser with no interaction with your code, you can do:
|
||||
|
||||
```
|
||||
// via <script>
|
||||
window.gaiaViewer.launchSelfContained("#my-selector");
|
||||
|
||||
// via import
|
||||
import {launchSelfContained} from '@gaia-project/viewer';
|
||||
```
|
||||
3
index.ts
3
index.ts
|
|
@ -2,6 +2,7 @@ import Game from './src/components/Game.vue';
|
|||
|
||||
import { gaiaViewer, makeStore } from './src/store';
|
||||
import launch from './src/launcher';
|
||||
import launchSelfContained from './src/self-contained';
|
||||
|
||||
export {Game, gaiaViewer, makeStore};
|
||||
export {Game, gaiaViewer, makeStore, launchSelfContained};
|
||||
export default launch;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import launch from './launcher';
|
||||
import Engine from '@gaia-project/engine';
|
||||
|
||||
function launchSelfContained() {
|
||||
const emitter = launch("#app");
|
||||
function launchSelfContained(selector = "#app") {
|
||||
const emitter = launch(selector);
|
||||
|
||||
let engine = new Engine();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Import vue component
|
||||
import launch from './launcher';
|
||||
import launchSelfContained from './self-contained';
|
||||
|
||||
let globalItem: any;
|
||||
if (typeof window !== 'undefined') {
|
||||
|
|
@ -9,8 +10,8 @@ if (typeof window !== 'undefined') {
|
|||
}
|
||||
|
||||
if (globalItem) {
|
||||
globalItem.launch = launch;
|
||||
globalItem.gaiaViewer = {launch, launchSelfContained};
|
||||
}
|
||||
|
||||
// To allow use as module (npm/webpack/etc.) export component
|
||||
export {launchSelfContained};
|
||||
export default launch;
|
||||
Loading…
Add table
Add a link
Reference in a new issue