Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client refactor #78

Open
wants to merge 5 commits into
base: client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions client/src/app-context.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import Game from './playback/Game'
import Match from './playback/Match'
import Tournament, { DEFAULT_TOURNAMENT_STATE, TournamentState } from './playback/Tournament'
import Game from './current-game/Game'
import Match from './current-game/Match'
import { ClientConfig, getDefaultConfig } from './client-config'
import Tournament, { DEFAULT_TOURNAMENT_STATE, TournamentState } from './components/game/tournament-renderer/Tournament'

export interface AppState {
queue: Game[]
Expand All @@ -11,8 +11,6 @@ export interface AppState {
tournament: Tournament | undefined
tournamentState: TournamentState
loadingRemoteContent: string
updatesPerSecond: number
paused: boolean
disableHotkeys: boolean
config: ClientConfig
}
Expand All @@ -24,8 +22,6 @@ const DEFAULT_APP_STATE: AppState = {
tournament: undefined,
tournamentState: DEFAULT_TOURNAMENT_STATE,
loadingRemoteContent: '',
updatesPerSecond: 1,
paused: true,
disableHotkeys: false,
config: getDefaultConfig()
}
Expand Down
10 changes: 5 additions & 5 deletions client/src/app-events.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useEffect } from 'react'

export enum EventType {
TURN_PROGRESS = 'turnprogress',
TILE_CLICK = 'tileclick',
NEW_TURN = 'NEW_TURN',
TILE_CLICK = 'TILE_CLICK',
TILE_DRAG = 'TILE_DRAG',
CANVAS_RIGHT_CLICK = 'CANVAS_RIGHT_CLICK',
RENDER = 'render',
INITIAL_RENDER = 'initalrender'
RENDER = 'RENDER',
MAP_RENDER = 'MAP_RENDER'
}

export function useListenEvent(
Expand All @@ -26,7 +26,7 @@ export function useListenEvent(
}, deps)
}

export function publishEvent(eventType: string, eventData: any) {
export function publishEvent(eventType: string, eventData: any = false) {
const event = new CustomEvent(eventType as string, { detail: eventData })
document.dispatchEvent(event)
}
30 changes: 16 additions & 14 deletions client/src/components/basic-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PropsWithChildren } from 'react'
import { useAppContext } from '../app-context'
import { useKeyboard } from '../util/keyboard'
import { Hotkeys, useHotkey, useKeyboard } from '../util/keyboard'

interface Props {
open: boolean
Expand All @@ -20,13 +20,15 @@ export const BasicDialog: React.FC<PropsWithChildren<Props>> = (props) => {
const context = useAppContext()
const keyboard = useKeyboard()

React.useEffect(() => {
if (!props.open) return

if (props.onCancel && keyboard.keyCode === 'Escape') {
props.onCancel()
}
}, [props.open, keyboard.keyCode])
useHotkey(
context.state,
keyboard,
Hotkeys.EscapeDialog,
() => {
if (props.open && props.onCancel) props.onCancel()
},
[props.onCancel, props.open]
)

React.useEffect(() => {
context.setState((prevState) => ({ ...prevState, disableHotkeys: props.open }))
Expand All @@ -41,12 +43,12 @@ export const BasicDialog: React.FC<PropsWithChildren<Props>> = (props) => {
widthType == 'sm'
? 'w-4/6 md:w-3/5 lg:w-6/12'
: widthType == 'md'
? 'w-5/6 md:w-3/4 lg:w-7/12'
: widthType == 'lg'
? 'w-5/6 md:w-4/5 lg:w-9/12'
: widthType == 'full'
? 'w-5/6 md:w-5/6 lg:w-11/12'
: ''
? 'w-5/6 md:w-3/4 lg:w-7/12'
: widthType == 'lg'
? 'w-5/6 md:w-4/5 lg:w-9/12'
: widthType == 'full'
? 'w-5/6 md:w-5/6 lg:w-11/12'
: ''
return (
<div className="fixed flex flex-col items-center justify-center w-full h-full top-0 left-0 bg-gray-500 bg-opacity-50 z-50">
<div
Expand Down
11 changes: 6 additions & 5 deletions client/src/components/controls-bar/controls-bar-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { useAppContext } from '../../app-context'

const TIMELINE_WIDTH = 350
interface Props {
currentUPS: number
liveUPS: number
targetUPS: number
}

export const ControlsBarTimeline: React.FC<Props> = ({ currentUPS }) => {
export const ControlsBarTimeline: React.FC<Props> = ({ liveUPS, targetUPS }) => {
const appContext = useAppContext()

let down = useRef(false)
Expand Down Expand Up @@ -67,9 +68,9 @@ export const ControlsBarTimeline: React.FC<Props> = ({ currentUPS }) => {
return (
<div className="min-h-[30px] bg-bg rounded-md mr-2 relative" style={{ minWidth: TIMELINE_WIDTH }}>
<p className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-[10px] text-xs select-none whitespace-nowrap">
Turn: <b>{turn}</b>/{maxTurn} &nbsp; {appContext.state.updatesPerSecond} UPS (
{appContext.state.updatesPerSecond < 0 && '-'}
{currentUPS})
Turn: <b>{turn}</b>/{maxTurn} &nbsp; {targetUPS} UPS (
{targetUPS < 0 && '-'}
{liveUPS})
</p>
<div className="absolute bg-white/10 left-0 right-0 bottom-0 min-h-[5px] rounded"></div>
<div
Expand Down
Loading