11import React , { useEffect } from 'react'
22import { useAppContext } from './app-context'
33import { GameRenderer } from './playback/GameRenderer'
4+ import { NumInput } from './components/forms'
45
56export type ClientConfig = typeof DEFAULT_CONFIG
67
@@ -15,7 +16,8 @@ const DEFAULT_CONFIG = {
1516 showMapXY : true ,
1617 streamRunnerGames : true ,
1718 profileGames : false ,
18- validateMaps : false
19+ validateMaps : false ,
20+ resolutionScale : 100
1921}
2022
2123const configDescription : Record < keyof ClientConfig , string > = {
@@ -25,14 +27,17 @@ const configDescription: Record<keyof ClientConfig, string> = {
2527 showMapXY : 'Show X,Y when hovering a tile' ,
2628 streamRunnerGames : 'Stream each round from the runner live as the game is being played' ,
2729 profileGames : 'Enable saving profiling data when running games' ,
28- validateMaps : 'Validate maps before running a game'
30+ validateMaps : 'Validate maps before running a game' ,
31+ resolutionScale : 'Resolution scale for the game area. Decrease to help performance.'
2932}
3033
3134export function getDefaultConfig ( ) : ClientConfig {
3235 const config : ClientConfig = { ...DEFAULT_CONFIG }
3336 for ( const key in config ) {
3437 const value = localStorage . getItem ( 'config' + key )
35- if ( value ) config [ key as keyof ClientConfig ] = JSON . parse ( value )
38+ if ( value ) {
39+ ; ( config [ key as keyof ClientConfig ] as any ) = JSON . parse ( value )
40+ }
3641 }
3742 return config
3843}
@@ -55,7 +60,7 @@ export const ConfigPage: React.FC<Props> = (props) => {
5560
5661const ConfigBooleanElement : React . FC < { configKey : keyof ClientConfig } > = ( { configKey } ) => {
5762 const context = useAppContext ( )
58- const value = context . state . config [ configKey ]
63+ const value = context . state . config [ configKey ] as boolean
5964 return (
6065 < div className = { 'flex flex-row items-center mb-2' } >
6166 < input
@@ -68,7 +73,7 @@ const ConfigBooleanElement: React.FC<{ configKey: keyof ClientConfig }> = ({ con
6873 } ) )
6974 localStorage . setItem ( 'config' + configKey , JSON . stringify ( e . target . checked ) )
7075 // hopefully after the setState is done
71- setTimeout ( ( ) => GameRenderer . render ( ) , 10 )
76+ setTimeout ( ( ) => GameRenderer . fullRender ( ) , 10 )
7277 } }
7378 />
7479 < div className = { 'ml-2 text-xs' } > { configDescription [ configKey ] ?? configKey } </ div >
@@ -82,8 +87,29 @@ const ConfigStringElement: React.FC<{ configKey: string }> = ({ configKey }) =>
8287 return < div className = { 'flex flex-row items-center' } > Todo</ div >
8388}
8489
85- const ConfigNumberElement : React . FC < { configKey : string } > = ( { configKey } ) => {
90+ const ConfigNumberElement : React . FC < { configKey : keyof ClientConfig } > = ( { configKey } ) => {
8691 const context = useAppContext ( )
87- const value = context . state . config [ configKey as keyof ClientConfig ]
88- return < div className = { 'flex flex-row items-center' } > Todo</ div >
92+ const value = context . state . config [ configKey as keyof ClientConfig ] as number
93+ return (
94+ < div className = { 'flex flex-row items-center mb-2' } >
95+ < NumInput
96+ value = { value }
97+ changeValue = { ( newVal ) => {
98+ context . setState ( ( prevState ) => ( {
99+ ...prevState ,
100+ config : { ...context . state . config , [ configKey ] : newVal }
101+ } ) )
102+ localStorage . setItem ( 'config' + configKey , JSON . stringify ( newVal ) )
103+ // hopefully after the setState is done
104+ setTimeout ( ( ) => {
105+ // Trigger canvas dimension update to ensure resolution is updated
106+ GameRenderer . onMatchChange ( )
107+ } , 10 )
108+ } }
109+ min = { 10 }
110+ max = { 100 }
111+ />
112+ < div className = { 'ml-2 text-xs' } > { configDescription [ configKey ] ?? configKey } </ div >
113+ </ div >
114+ )
89115}
0 commit comments