Skip to content

Commit

Permalink
Update game-client.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-michie committed Jan 4, 2024
1 parent bda8597 commit 8c1d164
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app/game/game-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as Ably from 'ably';
import { Types } from "ably";
import { AblyProvider, useAbly, useChannel, usePresence } from "ably/react"
import { MouseEventHandler, MouseEvent, useState, useEffect } from 'react'
import Logger, { LogEntry } from '../../components/logger';
import GameComponent from '../../components/Game';
import PlayerInfo from "../../components/playerInfoTypes";
import Sidebar from '../../components/SidebarPresence';
Expand Down Expand Up @@ -103,12 +102,6 @@ const { presenceData, updateStatus } = usePresence(
}
);







const getDirection = (key: string): string | null => {
const keyDirectionMap: { [key: string]: string } = {
ArrowLeft: 'LEFT',
Expand All @@ -123,8 +116,12 @@ const { presenceData, updateStatus } = usePresence(
const handleKeyPress = (event: KeyboardEvent): void => {
const direction = getDirection(event.key);

if (direction === 'UP' || direction === 'DOWN') {
// Prevent default scrolling behavior for up and down arrow keys
event.preventDefault();
}

if (direction) {

userDataChannel.publish(`${clientId}-moves`, direction)
.then(() => console.log(`Published direction ${direction} to ${clientId}`))
.catch((error) => console.error('Error publishing direction:', error));
Expand Down

0 comments on commit 8c1d164

Please sign in to comment.