sending info?!
parent
4e76133bc6
commit
794fd4e4a6
|
|
@ -20,6 +20,7 @@
|
||||||
"sisteransi": "^1.0.5",
|
"sisteransi": "^1.0.5",
|
||||||
"typescript": "^4.3.2",
|
"typescript": "^4.3.2",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
|
"ws": "^7.4.6",
|
||||||
"yarn": "^1.22.10"
|
"yarn": "^1.22.10"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
36
src/Menu.ts
36
src/Menu.ts
|
|
@ -30,13 +30,8 @@ export class Menu implements Renderable {
|
||||||
constructor() {
|
constructor() {
|
||||||
menuPanel.on('keypress', (evt, key) => {
|
menuPanel.on('keypress', (evt, key) => {
|
||||||
log.info('keypress', key);
|
log.info('keypress', key);
|
||||||
if (key.full === 'delete') {
|
|
||||||
Game.current.removePawn(Game.current.selected);
|
if (key.full === 'left') {
|
||||||
} else if (key.full === 'up') {
|
|
||||||
Game.current.advanceSelection(-1);
|
|
||||||
} else if (key.full === 'down') {
|
|
||||||
Game.current.advanceSelection(1);
|
|
||||||
} else if (key.full === 'left') {
|
|
||||||
this.view = View[Object.keys(View)[Math.min(Math.max(Object.values(View).indexOf(this.view) - 1, 0), Object.keys(View).length - 1)]]
|
this.view = View[Object.keys(View)[Math.min(Math.max(Object.values(View).indexOf(this.view) - 1, 0), Object.keys(View).length - 1)]]
|
||||||
} else if (key.full === 'right') {
|
} else if (key.full === 'right') {
|
||||||
this.view = View[Object.keys(View)[Math.min(Math.max(Object.values(View).indexOf(this.view) + 1, 0), Object.keys(View).length - 1)]]
|
this.view = View[Object.keys(View)[Math.min(Math.max(Object.values(View).indexOf(this.view) + 1, 0), Object.keys(View).length - 1)]]
|
||||||
|
|
@ -50,6 +45,26 @@ export class Menu implements Renderable {
|
||||||
this.subMenu = SubMenu.NONE;
|
this.subMenu = SubMenu.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.view === View.PAWNS) {
|
||||||
|
if (key.full === 'delete') {
|
||||||
|
Game.current.removePawn(Game.current.selected);
|
||||||
|
} else if (key.full === 'up') {
|
||||||
|
Game.current.advanceSelection(-1);
|
||||||
|
} else if (key.full === 'down') {
|
||||||
|
Game.current.advanceSelection(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.view === View.MULTIPLAYER) {
|
||||||
|
if (key.full === 'enter') {
|
||||||
|
mdns.players[this.multiplayerSelected].sendItem(null);
|
||||||
|
} else if (key.full === 'up') {
|
||||||
|
this.multiplayerSelected --;
|
||||||
|
} else if (key.full === 'down') {
|
||||||
|
this.multiplayerSelected ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(this.subMenu === SubMenu.TREES) {
|
if(this.subMenu === SubMenu.TREES) {
|
||||||
if (key.full === '=') {
|
if (key.full === '=') {
|
||||||
this.trees ++;
|
this.trees ++;
|
||||||
|
|
@ -148,9 +163,14 @@ export class Menu implements Renderable {
|
||||||
})()}`
|
})()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multiplayerSelected = 0;
|
||||||
|
|
||||||
renderMultiplayer() {
|
renderMultiplayer() {
|
||||||
if(mdns.players.length === 0) return `{center}${tags.bright}${tags.black.fg}No friends online{/center}`;
|
if(mdns.players.length === 0) return `{center}${tags.bright}${tags.black.fg}No friends online{/center}`;
|
||||||
return mdns.players.map(player => player.toString()).join('\n');
|
return mdns.players.map((player, i) => {
|
||||||
|
if(i === this.multiplayerSelected) return '> ' + player.toString();
|
||||||
|
else return player.toString();
|
||||||
|
}).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
renderInv() {
|
renderInv() {
|
||||||
|
|
|
||||||
32
src/mDNS.ts
32
src/mDNS.ts
|
|
@ -4,10 +4,15 @@ import getPort from 'get-port';
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import faker from 'faker';
|
import faker from 'faker';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import { Item, ItemState } from './Item.js';
|
||||||
|
import WebSocket from 'ws';
|
||||||
|
import { Popup } from './Popup.js';
|
||||||
|
import { inspect } from 'util'
|
||||||
|
|
||||||
const mdns = bonjour();
|
const mdns = bonjour();
|
||||||
const ID = uuid.v4();
|
const ID = uuid.v4();
|
||||||
let devices = [];
|
let devices: Player[] = [];
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -15,7 +20,24 @@ class Player {
|
||||||
port: number;
|
port: number;
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return ` ${this.name}`;
|
return ` ${this.name} ${chalk.bold.black(`${this.host}:${this.port}`)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendItem(item: ItemState) {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
const log = new ItemState(Item.LOG, 1, {});
|
||||||
|
const json = log.toJson();
|
||||||
|
const socket = new WebSocket(`ws://${this.host}:${this.port}`);
|
||||||
|
// new Popup(`opening ws://${this.host}:${this.port}`);
|
||||||
|
socket.on('open', () => {
|
||||||
|
socket.send(json);
|
||||||
|
socket.close();
|
||||||
|
res(undefined);
|
||||||
|
});
|
||||||
|
socket.on('error', () => {
|
||||||
|
rej(log);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +56,12 @@ export async function ready(name, onThing?) {
|
||||||
name,
|
name,
|
||||||
port: port
|
port: port
|
||||||
});
|
});
|
||||||
|
const wss = new WebSocket.Server({ port });
|
||||||
|
wss.on('connection', function connection(ws) {
|
||||||
|
ws.on('message', function incoming(message) {
|
||||||
|
new Popup(inspect(message));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mdns.find({
|
mdns.find({
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,11 @@ uuid@^8.3.2:
|
||||||
version "8.3.2"
|
version "8.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
||||||
|
|
||||||
|
ws@^7.4.6:
|
||||||
|
version "7.4.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"
|
||||||
|
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==
|
||||||
|
|
||||||
yarn@^1.22.10:
|
yarn@^1.22.10:
|
||||||
version "1.22.10"
|
version "1.22.10"
|
||||||
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c"
|
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue