Added websocket to enable "Chat Plays PokeRogue"
parent
bb28d3599e
commit
f78187fe96
|
|
@ -14,7 +14,8 @@
|
||||||
"i18next-browser-languagedetector": "^7.2.1",
|
"i18next-browser-languagedetector": "^7.2.1",
|
||||||
"json-stable-stringify": "^1.1.0",
|
"json-stable-stringify": "^1.1.0",
|
||||||
"phaser": "^3.70.0",
|
"phaser": "^3.70.0",
|
||||||
"phaser3-rex-plugins": "^1.1.84"
|
"phaser3-rex-plugins": "^1.1.84",
|
||||||
|
"ws": "^8.17.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitest/coverage-istanbul": "^1.4.0",
|
"@vitest/coverage-istanbul": "^1.4.0",
|
||||||
|
|
@ -5860,10 +5861,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.16.0",
|
"version": "8.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz",
|
||||||
"integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==",
|
"integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@
|
||||||
"i18next-browser-languagedetector": "^7.2.1",
|
"i18next-browser-languagedetector": "^7.2.1",
|
||||||
"json-stable-stringify": "^1.1.0",
|
"json-stable-stringify": "^1.1.0",
|
||||||
"phaser": "^3.70.0",
|
"phaser": "^3.70.0",
|
||||||
"phaser3-rex-plugins": "^1.1.84"
|
"phaser3-rex-plugins": "^1.1.84",
|
||||||
|
"ws": "^8.17.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import Phaser, {Time} from "phaser";
|
import Phaser, {Time} from "phaser";
|
||||||
|
import WebSocket, {WebSocketServer} from 'ws';
|
||||||
import * as Utils from "./utils";
|
import * as Utils from "./utils";
|
||||||
import {initTouchControls} from './touch-controls';
|
import {initTouchControls} from './touch-controls';
|
||||||
import pad_generic from "./configs/pad_generic";
|
import pad_generic from "./configs/pad_generic";
|
||||||
|
|
@ -27,6 +28,7 @@ export class InputsController {
|
||||||
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
||||||
private gamepads: Array<string> = new Array();
|
private gamepads: Array<string> = new Array();
|
||||||
private scene: Phaser.Scene;
|
private scene: Phaser.Scene;
|
||||||
|
private wss = new WebSocketServer({ port: 9876});
|
||||||
|
|
||||||
// buttonLock ensures only a single movement key is firing repeated inputs
|
// buttonLock ensures only a single movement key is firing repeated inputs
|
||||||
// (i.e. by holding down a button) at a time
|
// (i.e. by holding down a button) at a time
|
||||||
|
|
@ -81,6 +83,15 @@ export class InputsController {
|
||||||
|
|
||||||
// Keyboard
|
// Keyboard
|
||||||
this.setupKeyboardControls();
|
this.setupKeyboardControls();
|
||||||
|
|
||||||
|
// setup WebSocket
|
||||||
|
this.wss.on('connection', function connection(ws: WebSocket) {
|
||||||
|
ws.on('message', function incoming(message: string) {
|
||||||
|
console.log('received: %s', message);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loseFocus(): void {
|
loseFocus(): void {
|
||||||
|
|
@ -168,6 +179,10 @@ export class InputsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupWebSocketControls(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
setupKeyboardControls(): void {
|
setupKeyboardControls(): void {
|
||||||
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
|
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
|
||||||
const keyConfig = {
|
const keyConfig = {
|
||||||
|
|
@ -224,6 +239,36 @@ export class InputsController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
processInputCommad(input: string): void {
|
||||||
|
const command = input.toLowerCase();
|
||||||
|
|
||||||
|
const commandMapping = {
|
||||||
|
'up' : Button.UP,
|
||||||
|
'down' : Button.DOWN,
|
||||||
|
'left' : Button.LEFT,
|
||||||
|
'right' : Button.RIGHT,
|
||||||
|
'submit' : Button.SUBMIT,
|
||||||
|
'cancel' : Button.CANCEL,
|
||||||
|
'menu' : Button.MENU,
|
||||||
|
'stats' : Button.STATS
|
||||||
|
};
|
||||||
|
|
||||||
|
if (commandMapping[command]) {
|
||||||
|
this.triggerButtonPress(commandMapping[command]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
triggerButtonPress(button: Button): void {
|
||||||
|
this.events.emit('input_down', {
|
||||||
|
controller_type: 'command',
|
||||||
|
button: button,
|
||||||
|
});
|
||||||
|
this.events.emit('input_up', {
|
||||||
|
controller_type: 'command',
|
||||||
|
button: button,
|
||||||
|
});
|
||||||
|
this.setLastProcessedMovementTime(button);
|
||||||
|
this.delLastProcessedMovementTime(button);
|
||||||
|
}
|
||||||
|
|
||||||
mapGamepad(id: string): GamepadConfig {
|
mapGamepad(id: string): GamepadConfig {
|
||||||
id = id.toLowerCase();
|
id = id.toLowerCase();
|
||||||
|
|
@ -291,4 +336,6 @@ export class InputsController {
|
||||||
if (this.buttonLock === button) this.buttonLock = null;
|
if (this.buttonLock === button) this.buttonLock = null;
|
||||||
else if (this.buttonLock2 === button) this.buttonLock2 = null;
|
else if (this.buttonLock2 === button) this.buttonLock2 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue