From b610e6c9e59bd70c5fd5654b9f72bca439bc1aa9 Mon Sep 17 00:00:00 2001 From: Mario Reder Date: Wed, 8 Apr 2020 07:55:41 +0200 Subject: [PATCH] fix: in game chat --- src/main/Connection.ts | 2 +- src/main/Connector.ts | 15 ++++++++++++--- src/main/Emulator.ts | 6 +----- src/main/index.ts | 6 +++--- src/models/Message.model.ts | 1 + src/renderer/Connector.ts | 10 +++++++--- src/renderer/components/views/EmulatorView.tsx | 3 +-- src/renderer/components/views/SettingsView.scss | 5 +++++ src/renderer/components/views/SettingsView.tsx | 16 ++++++++-------- src/renderer/index.tsx | 2 ++ 10 files changed, 41 insertions(+), 25 deletions(-) mode change 100644 => 100755 src/main/Connection.ts mode change 100644 => 100755 src/main/Emulator.ts diff --git a/src/main/Connection.ts b/src/main/Connection.ts old mode 100644 new mode 100755 index 15fd172..51983c2 --- a/src/main/Connection.ts +++ b/src/main/Connection.ts @@ -545,7 +545,7 @@ export class Connection { if (!message || senderId == null) return switch (chat.chatType) { case Chat.ChatType.GLOBAL: - if (emulator!.inGameChatEnabled) { + if (connector.inGameChatEnabled) { emulator!.displayChatMessage(message) } connector.globalChatMessage(message, senderId) diff --git a/src/main/Connector.ts b/src/main/Connector.ts index a40495e..bae40f7 100644 --- a/src/main/Connector.ts +++ b/src/main/Connector.ts @@ -20,11 +20,14 @@ export class Connector { ipcMain.on(RendererMessage.PASSWORD, this.onSendPassword) ipcMain.on(RendererMessage.CHAT_GLOBAL, this.onSendGlobalChatMessage) ipcMain.on(RendererMessage.CHAT_COMMAND, this.onSendCommandMessage) + ipcMain.on(RendererMessage.EMU_CHAT, this.onEmuChatChanged) ipcMain.on(RendererMessage.HOTKEYS_CHANGED, this.onHotkeysChanged) ipcMain.on(RendererMessage.CHARACTER_CYCLING_ORDER_CHANGED, this.onCharacterCyclingOrderChanged) ipcMain.on(RendererMessage.GAMEPAD_BUTTON_STATE_CHANGED, this.onGamepadButtonStateChanged) } + public inGameChatEnabled = false + private hotkeyManager = new HotkeyManager() private readonly onCreateConnection = ( @@ -50,10 +53,10 @@ export class Connector { private readonly onCreateEmulatorConnection = ( _: Electron.Event, - { processId, characterId, inGameChatEnabled }: - { processId: number, characterId: number, inGameChatEnabled: boolean } + { processId, characterId }: + { processId: number, characterId: number } ) => { - createEmulator({ processId, characterId, inGameChatEnabled }) + createEmulator({ processId, characterId }) } private readonly onDisconnectEmulator = () => { @@ -81,6 +84,12 @@ export class Connector { this.onPlayerUpdate({} as any, { username, characterId }) } + private readonly onEmuChatChanged = ( + _: Electron.Event, + { emuChat }: { emuChat: boolean}) => { + this.inGameChatEnabled = emuChat + } + private readonly onHotkeysChanged = ( _: Electron.Event, { hotkeyBindings, globalHotkeysEnabled, username }: diff --git a/src/main/Emulator.ts b/src/main/Emulator.ts old mode 100644 new mode 100755 index 86da864..59ab708 --- a/src/main/Emulator.ts +++ b/src/main/Emulator.ts @@ -31,8 +31,6 @@ enum ConnectionFlag { export class Emulator { public baseAddress: number - public inGameChatEnabled = false - private readonly process: Process public static async updateEmulators () { @@ -115,10 +113,8 @@ export class Emulator { * * @param {number} processId - Process ID to load * @param {number} characterId - Character ID from settings - * @param {boolean} [inGameChatEnabled=false] - Whether in game chat should be enabled */ - constructor (processId: number, characterId: number, inGameChatEnabled = false) { - this.inGameChatEnabled = inGameChatEnabled + constructor (processId: number, characterId: number) { this.process = processId === testEmulatorPid ? new TestProcess() : winProcess.Process(processId) this.process.open() this.baseAddress = -1 diff --git a/src/main/index.ts b/src/main/index.ts index 2d7fc1b..1093618 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -21,11 +21,11 @@ export let emulator: Emulator | undefined export let connection: Connection | undefined export const createEmulator = ( - { processId, characterId, inGameChatEnabled }: - { processId: number, characterId: number, inGameChatEnabled: boolean } + { processId, characterId }: + { processId: number, characterId: number } ) => { try { - emulator = new Emulator(processId, characterId, inGameChatEnabled) + emulator = new Emulator(processId, characterId) emulator.displayChatMessage('- Net64 connected -') } catch (err) { console.warn(err) diff --git a/src/models/Message.model.ts b/src/models/Message.model.ts index c5738e9..fc3c2ff 100644 --- a/src/models/Message.model.ts +++ b/src/models/Message.model.ts @@ -31,6 +31,7 @@ export enum RendererMessage { PASSWORD = 'PASSWORD', CHAT_GLOBAL = 'CHAT_GLOBAL', CHAT_COMMAND = 'CHAT_COMMAND', + EMU_CHAT = 'EMU_CHAT', HOTKEYS_CHANGED = 'HOTKEYS_CHANGED', CHARACTER_CYCLING_ORDER_CHANGED = 'CHARACTER_CYCLING_ORDER_CHANGED', GAMEPAD_BUTTON_STATE_CHANGED = 'GAMEPAD_BUTTON_STATE_CHANGED' diff --git a/src/renderer/Connector.ts b/src/renderer/Connector.ts index 1855bc1..9e16da8 100644 --- a/src/renderer/Connector.ts +++ b/src/renderer/Connector.ts @@ -198,10 +198,10 @@ is incompatible with your client API version (${process.env.MAJOR}.${process.env } public createEmulatorConnection ( - { processId, characterId, inGameChatEnabled }: - { processId: number, characterId: number, inGameChatEnabled: boolean } + { processId, characterId }: + { processId: number, characterId: number } ): void { - ipcRenderer.send(RendererMessage.CREATE_EMULATOR_CONNECTION, { processId, characterId, inGameChatEnabled }) + ipcRenderer.send(RendererMessage.CREATE_EMULATOR_CONNECTION, { processId, characterId }) } public disconnectEmulator (): void { @@ -224,6 +224,10 @@ is incompatible with your client API version (${process.env.MAJOR}.${process.env ipcRenderer.send(RendererMessage.CHAT_COMMAND, { message, args }) } + public changeEmuChat (emuChat: boolean): void { + ipcRenderer.send(RendererMessage.EMU_CHAT, { emuChat }) + } + public changeHotkeyBindings ( { hotkeyBindings, globalHotkeysEnabled, username }: { hotkeyBindings: { [shortcut in HotkeyShortcut]: string[] }, globalHotkeysEnabled: boolean, username?: string } diff --git a/src/renderer/components/views/EmulatorView.tsx b/src/renderer/components/views/EmulatorView.tsx index 72198bd..311978a 100644 --- a/src/renderer/components/views/EmulatorView.tsx +++ b/src/renderer/components/views/EmulatorView.tsx @@ -96,8 +96,7 @@ class View extends React.PureComponent { setTimeout(() => { connector.createEmulatorConnection({ processId: emulator.pid, - characterId: this.props.characterId, - inGameChatEnabled: false + characterId: this.props.characterId }) }, 50) this.timerTimeout = setTimeout(() => { diff --git a/src/renderer/components/views/SettingsView.scss b/src/renderer/components/views/SettingsView.scss index c05c649..1dadca6 100644 --- a/src/renderer/components/views/SettingsView.scss +++ b/src/renderer/components/views/SettingsView.scss @@ -15,6 +15,11 @@ flex: 0 } + &-setting { + width: 100%; + display: flex; + } + &-hotkeys { display: flex; flex-wrap: wrap; diff --git a/src/renderer/components/views/SettingsView.tsx b/src/renderer/components/views/SettingsView.tsx index 8d2cf94..8b572b6 100644 --- a/src/renderer/components/views/SettingsView.tsx +++ b/src/renderer/components/views/SettingsView.tsx @@ -164,6 +164,7 @@ class View extends React.PureComponent { } else { const { dispatch } = this.props connector.playerUpdate({ username, characterId: this.state.characterId }) + connector.changeEmuChat(this.state.emuChat) connector.changeHotkeyBindings({ hotkeyBindings, globalHotkeysEnabled }) connector.changeCharacterCyclingOrder({ characterCyclingOrder }) dispatch(setUsername(username)) @@ -197,10 +198,6 @@ class View extends React.PureComponent { const connectionError = this.props.connectionError const gamepads = gamepadManager.getConnectedGamepads() const styles: Record = { - setting: { - width: '100%', - display: 'flex' - }, flexCenter: { alignItems: 'center', justifyContent: 'center' @@ -231,12 +228,12 @@ class View extends React.PureComponent { } -
+
Username:
-
+
Character:
-
+
Gamepad:
-
+
In-Game Chat View:
{ checked={this.state.emuChat} onChange={this.onEmuChatChange} /> +
+ +
Enable global character keyboard shortcuts:
export const connector = new Connector() export let gamepadManager: GamepadManager +// eslint-disable-next-line @typescript-eslint/no-floating-promises ;(async () => { const history: History = createHistory() const save: SaveState = await loadSaveData() + connector.changeEmuChat(save.appSaveData.emuChat) connector.changeHotkeyBindings({ hotkeyBindings: save.appSaveData.hotkeyBindings || {}, globalHotkeysEnabled: !!save.appSaveData.globalHotkeysEnabled,