Add additional playerClicked event
This commit is contained in:
parent
87cc95c183
commit
cd105529cf
3 changed files with 8 additions and 14 deletions
|
|
@ -69,6 +69,8 @@ emitter.emit('player', {auth: "xxx"});
|
|||
emitter.emit('player', {index: 0});
|
||||
// Listen for move actions
|
||||
emitter.on('move', (move) => {/* send move to backend and give back result */});
|
||||
// Signals that a player's name was clicked
|
||||
emitter.on('player:clicked', ({name, index, auth}) => {/* ... */});
|
||||
```
|
||||
|
||||
If you want a self-contained game which plays in the browser with no interaction with your code, you can do:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import Vue from "vue";
|
||||
import { Store } from "vuex";
|
||||
import BootstrapVue from 'bootstrap-vue';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
|
|
@ -25,6 +26,11 @@ function launch(selector: string) {
|
|||
|
||||
if (type === "gaiaViewer/move") {
|
||||
item.emit("move", payload);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "gaiaViewer/playerClick") {
|
||||
item.emit("player:clicked", {name: payload.name, auth: payload.auth, index: (store as Store<any>).state.gaiaViewer.data?.players?.findIndex(pl => pl === payload)});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
14
src/store.ts
14
src/store.ts
|
|
@ -117,20 +117,6 @@ function makeStore() {
|
|||
return new Vuex.Store({
|
||||
modules: {
|
||||
gaiaViewer
|
||||
},
|
||||
state: {
|
||||
options: {spaceShips: false} as EngineOptions,
|
||||
error: null as string,
|
||||
info: null as string,
|
||||
errorIssued: null as Date,
|
||||
infoIssued: null as Date
|
||||
},
|
||||
mutations: {
|
||||
options: (state, options: EngineOptions) => state.options = options,
|
||||
error: (state, error: string) => { state.error = error; state.errorIssued = new Date(); },
|
||||
info: (state, info: string) => { state.info = info; state.infoIssued = new Date(); },
|
||||
removeError: state => state.error = state.errorIssued = null,
|
||||
removeInfo: state => state.info = state.infoIssued = null
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue