Skip to content

Commit

Permalink
Merge branch 'gamemode'
Browse files Browse the repository at this point in the history
  • Loading branch information
outkine committed Mar 10, 2024
2 parents 24b0e6a + bfe4963 commit c629ff8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/garage/components/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Bar = () => {
<For each={LANGS}>
{(lang) => (
<button
class="me-3"
class="me-3 no-bold"
id={`select-${lang}`}
onClick={() => actions.selectLang(lang)}
>
Expand Down
5 changes: 5 additions & 0 deletions src/garage/components/SettingsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Index } from 'solid-js'
import { useStore } from '../store'
import { GAME_MODES } from '../utils/constants'
import { KEYMAPS, THEMES, TURN_TIMEOUT_ENABLED } from '../utils/settings'

function createSelect<T>(
Expand Down Expand Up @@ -38,6 +39,10 @@ export const SettingsMenu = () => {
<p>turn timeout</p>
{createSelect(TURN_TIMEOUT_ENABLED, state.settings.timeoutEnabled, actions.setTimeoutEnabled)}
</div>
<div>
<p>game mode</p>
{createSelect(GAME_MODES, state.settings.gameMode, actions.setGameMode)}
</div>
</div>
<button class="button mt-2" onClick={actions.toggleSettingsMenu}>
close
Expand Down
4 changes: 4 additions & 0 deletions src/garage/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,7 @@
}
}
}

.no-bold {
font-weight: normal;
}
9 changes: 7 additions & 2 deletions src/garage/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, ParentProps, useContext } from 'solid-js'
import { createStore, SetStoreFunction } from 'solid-js/store'
import { captureException } from '@sentry/browser'
import { WorkerWrapper } from './worker/workerWrapper'
import { Lang, OUR_TEAM } from './utils/constants'
import { GameMode, Lang, OUR_TEAM } from './utils/constants'
import { CallbackParams, EvalInfo, SimulationSettings } from './worker/match.worker'
import {
KeyMap,
Expand Down Expand Up @@ -170,6 +170,10 @@ const createActions = (state: State, setState: SetStoreFunction<State>) => ({
setState('settings', { timeoutEnabled })
saveSettings(state.settings)
},
setGameMode(gameMode: GameMode) {
setState('settings', { gameMode })
saveSettings(state.settings)
},
initWorker(
finishedDownloadingCb: () => void,
finishedLoadingCb: () => void,
Expand Down Expand Up @@ -247,7 +251,8 @@ const createActions = (state: State, setState: SetStoreFunction<State>) => ({
// This converts the Proxy object into a regular Javascript object,
// which is necessary to be able to pass it through Comlink's Proxy
settings: JSON.parse(JSON.stringify(settings)),
timeoutEnabled: state.settings.timeoutEnabled === 'turn timeout enabled'
timeoutEnabled: state.settings.timeoutEnabled === 'turn timeout enabled',
gameMode: state.settings.gameMode
})
},

Expand Down
3 changes: 3 additions & 0 deletions src/garage/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const LANGS = ['Python', 'Javascript'] as const
export type Lang = typeof LANGS[number]

export const GAME_MODES = ['Normal', 'NormalHeal'] as const
export type GameMode = typeof GAME_MODES[number]

export const OUR_TEAM = 'Blue'
6 changes: 5 additions & 1 deletion src/garage/utils/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GameMode } from "./constants"

export const THEMES = ['light', 'dark'] as const
export type Theme = typeof THEMES[number]

Expand All @@ -11,12 +13,14 @@ export interface Settings {
theme: Theme
keyMap: KeyMap
timeoutEnabled: TurnTimeoutEnabled
gameMode: GameMode
}

const DEFAULT_SETTINGS: Settings = {
theme: 'light',
keyMap: 'default',
timeoutEnabled: 'turn timeout enabled'
timeoutEnabled: 'turn timeout enabled',
gameMode: 'Normal'
}

const KEY = 'settings'
Expand Down
8 changes: 5 additions & 3 deletions src/garage/worker/match.worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Comlink from 'comlink'

import fetchRunner from './fetchRunner'
import { Lang } from '../utils/constants'
import { Lang, GameMode } from '../utils/constants'
import { convertObjectKeysToSnakeCase } from '../utils/snakeCase'

// @ts-ignore
Expand Down Expand Up @@ -59,6 +59,7 @@ export interface RunParams {
turnNum: number
settings: SimulationSettings | null
timeoutEnabled: boolean
gameMode: GameMode
}

export interface CallbackParams {
Expand All @@ -72,7 +73,7 @@ export class MatchWorker {
}

async run(
{ assetsPath, evalInfo1, evalInfo2, turnNum, settings, timeoutEnabled }: RunParams,
{ assetsPath, evalInfo1, evalInfo2, turnNum, settings, timeoutEnabled, gameMode }: RunParams,
cb: (params: CallbackParams) => void,
) {
try {
Expand Down Expand Up @@ -124,7 +125,8 @@ export class MatchWorker {
turnCallback,
turnNum,
snakeCaseSettings,
timeoutEnabled
timeoutEnabled,
JSON.stringify(gameMode)
)
console.log('done')

Expand Down
1 change: 1 addition & 0 deletions src/site/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ table._battles {
._header {
margin-bottom: -2px;
background: var(--grey-3);
justify-content: space-between;
}

._footer {
Expand Down

0 comments on commit c629ff8

Please sign in to comment.