-
Notifications
You must be signed in to change notification settings - Fork 3
179 server create chess puzzle framework #210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
70aae37
Short update
ymmot239 4509c90
intermediate push
ymmot239 f10e501
Merge branch 'main' of https://github.com/Comet-Robotics/chessBot int…
ymmot239 cdc3039
fix object problems
LQNguyen05-max c01eaec
Merge branch '179-server-create-chess-puzzle-framework' of https://gi…
ymmot239 0ca599e
Added game ended message handler
ymmot239 e992406
Finished puzzle page
ymmot239 60651c9
Puzzle cleanup
ymmot239 f2cf906
added ratings
ymmot239 8207d23
readability changes
ymmot239 d41f7b9
navbar fix
ymmot239 27bba3d
Update puzzles.json
ymmot239 c9e4728
Update setup-base.tsx
ymmot239 c3586d1
Merge branch 'main' into 179-server-create-chess-puzzle-framework
ymmot239 5191b5f
fixed merge mistakes
ymmot239 f21eb54
Added spectator support
ymmot239 5f286a8
Update game-manager.ts
ymmot239 92614b4
Added new puzzle
ymmot239 9794573
Merge branch 'main' into 179-server-create-chess-puzzle-framework
ymmot239 dcc13e3
Update game-manager.ts
ymmot239 aa681e9
Merge branch 'main' into 179-server-create-chess-puzzle-framework
ymmot239 67155ca
Load Fen
ymmot239 3bdc67f
Merge branch 'main' into 179-server-create-chess-puzzle-framework
democat3457 641eb83
Re-add removed comments
democat3457 436a4f9
Merge remote-tracking branch 'origin/main' into 179-server-create-che…
jasonappah aa97663
Rename AI props
jasonappah 4878053
Remove unused branch
jasonappah 8c9abc6
address nits
jasonappah 5e416bc
Lint/Format
jasonappah f6bf221
added functionality
ymmot239 752b2a1
colin said i should get it done
jasonappah 99014cc
bye
jasonappah cb0a913
Add comment to set chess message
jasonappah 7b4f97d
format.
jasonappah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Button, MenuItem } from "@blueprintjs/core"; | ||
import { ItemRenderer, Select } from "@blueprintjs/select"; | ||
import { post } from "../api"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { PuzzleComponents } from "../../server/api/api"; | ||
|
||
const renderPuzzleOptions: ItemRenderer<string> = ( | ||
puzzleNumber, | ||
{ modifiers, handleFocus, handleClick }, | ||
) => { | ||
return ( | ||
<MenuItem | ||
key={puzzleNumber} | ||
active={modifiers.active} | ||
roleStructure="listoption" | ||
text={puzzleNumber} | ||
onFocus={handleFocus} | ||
onClick={handleClick} | ||
/> | ||
); | ||
}; | ||
|
||
interface SelectPuzzleProps { | ||
puzzles: Record<string, PuzzleComponents>; | ||
selectedPuzzle: string | undefined; | ||
onPuzzleSelected: (puzzle: string) => void; | ||
} | ||
|
||
export function SelectPuzzle(props: SelectPuzzleProps) { | ||
const navigate = useNavigate(); | ||
const hasSelection = props.selectedPuzzle !== undefined; | ||
|
||
const submit = ( | ||
<Button | ||
text="Play" | ||
icon="arrow-right" | ||
intent="primary" | ||
onClick={async () => { | ||
if (props.selectedPuzzle && props.puzzles) { | ||
//convert puzzle to map and send to start puzzles | ||
const puzzle = props.puzzles as Record< | ||
string, | ||
PuzzleComponents | ||
>; | ||
const promise = post("/start-puzzle-game", { | ||
puzzle: JSON.stringify(puzzle[props.selectedPuzzle]), | ||
}); | ||
promise.then(() => { | ||
navigate("/game"); | ||
}); | ||
} | ||
}} | ||
/> | ||
); | ||
return ( | ||
<> | ||
<Select<string> | ||
items={[...Object.keys(props.puzzles)]} | ||
itemRenderer={renderPuzzleOptions} | ||
onItemSelect={props.onPuzzleSelected} | ||
filterable={false} | ||
popoverProps={{ minimal: true }} | ||
> | ||
<Button | ||
text={ | ||
hasSelection ? | ||
props.selectedPuzzle | ||
: "Select a puzzle..." | ||
} | ||
endIcon="double-caret-vertical" | ||
/> | ||
</Select> | ||
{submit} | ||
</> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useState } from "react"; | ||
import { SetupBase } from "../setup/setup-base"; | ||
import { SelectPuzzle } from "./select-puzzle"; | ||
import { NonIdealState, Spinner } from "@blueprintjs/core"; | ||
import { get, useEffectQuery } from "../api"; | ||
import { Navigate } from "react-router-dom"; | ||
import { PuzzleComponents } from "../../server/api/api"; | ||
|
||
export function SetupPuzzle() { | ||
const [selectedPuzzle, setSelectedPuzzle] = useState<string | undefined>(); | ||
|
||
//get puzzles from api | ||
const { isPending, data, isError } = useEffectQuery( | ||
"get-puzzles", | ||
async () => | ||
(await get("/get-puzzles")) as Record<string, PuzzleComponents>, | ||
false, | ||
); | ||
|
||
if (isPending) { | ||
return ( | ||
<NonIdealState | ||
icon={<Spinner intent="primary" />} | ||
title="Loading..." | ||
/> | ||
); | ||
} else if (isError || data === undefined) { | ||
return <Navigate to="/home" />; | ||
} | ||
|
||
return ( | ||
<SetupBase> | ||
<SelectPuzzle | ||
puzzles={data} | ||
selectedPuzzle={selectedPuzzle} | ||
onPuzzleSelected={setSelectedPuzzle} | ||
/> | ||
</SetupBase> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not your problem to handle in this PR, but since I am looking at this code consciously, in general it would be nice to store all these reasons in one state hook and union the types. my current assumption is that there should only be one of a interrupted/ended/hold reason at a given time. if my assumption is wrong this is a useless comment :)