Skip to content

Commit

Permalink
fix: in game chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Reder committed Apr 8, 2020
1 parent af0f630 commit b610e6c
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/Connection.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions src/main/Connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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 }:
Expand Down
6 changes: 1 addition & 5 deletions src/main/Emulator.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ enum ConnectionFlag {
export class Emulator {
public baseAddress: number

public inGameChatEnabled = false

private readonly process: Process

public static async updateEmulators () {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/models/Message.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/Connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/views/EmulatorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class View extends React.PureComponent<EmulatorViewProps, EmulatorViewState> {
setTimeout(() => {
connector.createEmulatorConnection({
processId: emulator.pid,
characterId: this.props.characterId,
inGameChatEnabled: false
characterId: this.props.characterId
})
}, 50)
this.timerTimeout = setTimeout(() => {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/views/SettingsView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
flex: 0
}

&-setting {
width: 100%;
display: flex;
}

&-hotkeys {
display: flex;
flex-wrap: wrap;
Expand Down
16 changes: 8 additions & 8 deletions src/renderer/components/views/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
} 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))
Expand Down Expand Up @@ -197,10 +198,6 @@ class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
const connectionError = this.props.connectionError
const gamepads = gamepadManager.getConnectedGamepads()
const styles: Record<string, React.CSSProperties> = {
setting: {
width: '100%',
display: 'flex'
},
flexCenter: {
alignItems: 'center',
justifyContent: 'center'
Expand Down Expand Up @@ -231,12 +228,12 @@ class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
<WarningPanel warning={connectionError} />
}

<div style={styles.setting}>
<div className='settings-view-setting'>
<div style={styles.label}>Username:</div>
<input style={styles.input} value={this.state.username} onChange={this.onUsernameChange} />
</div>

<div style={styles.setting}>
<div className='settings-view-setting'>
<div style={styles.label}>Character:</div>
<select style={styles.input} value={this.state.characterId} onChange={this.onCharacterChange}>
<option value='0'>Mario</option>
Expand All @@ -254,7 +251,7 @@ class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
</select>
</div>

<div style={styles.setting}>
<div className='settings-view-setting'>
<div style={styles.label}>Gamepad:</div>
<select style={styles.input} value={gamepadId ?? undefined} onChange={(e) => {
gamepadManager.selectedGamepad = gamepadManager.getConnectedGamepads().find((gamepad) =>
Expand All @@ -274,14 +271,17 @@ class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
</select>
</div>

<div style={styles.setting}>
<div className='settings-view-setting'>
<div style={styles.label}>In-Game Chat View:</div>
<input
style={styles.checkBox}
type='checkbox'
checked={this.state.emuChat}
onChange={this.onEmuChatChange}
/>
</div>

<div className='settings-view-setting'>
<div style={styles.label}>Enable global character keyboard shortcuts:</div>
<input
style={styles.checkBox}
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export let store: Store<State>
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,
Expand Down

0 comments on commit b610e6c

Please sign in to comment.