Skip to content

Commit

Permalink
Merge pull request online-go#2763 from online-go/game-record
Browse files Browse the repository at this point in the history
Add better support for IRL game recording
  • Loading branch information
anoek authored Aug 19, 2024
2 parents 1999c8c + 3880310 commit d2ed27d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 77 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"express-http-proxy": "^2.0.0",
"fork-ts-checker-webpack-plugin": "^9.0.0",
"globals": "^15.8.0",
"goban": "=8.3.18",
"goban": "=8.3.19",
"gulp": "^5.0.0",
"gulp-clean-css": "^4.3.0",
"gulp-eslint-new": "^2.2.0",
Expand Down
90 changes: 67 additions & 23 deletions src/components/ChallengeModal/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ interface Events {}

interface ChallengeModalProperties {
mode: ChallengeModes;
game_record_mode?: boolean /* when true, if mode === "demo", we will create a game instance instead of a review instance */;
playerId?: number;
initialState?: any;
config?: ChallengeModalConfig;
autoCreate?: boolean;
playersList?: Array<{ name: string; rank: number }>;
tournamentRecordId?: number;
tournamentRecordRoundId?: number;
libraryCollectionId?: number;
created?: (c: CreatedChallengeInfo) => void;
}

Expand Down Expand Up @@ -457,41 +459,56 @@ export class ChallengeModal extends Modal<Events, ChallengeModalProperties, any>
demo: next.demo,
});

const demo: any = {};
const settings: any = {};
for (const k in next.demo) {
demo[k] = next.demo[k];
settings[k] = next.demo[k];
}

// Ignore komi value if komi is automatic.
if (demo.komi_auto !== "custom") {
delete demo.komi;
if (settings.komi_auto !== "custom") {
delete settings.komi;
}

demo.black_pro = demo.black_ranking > 1000 ? 1 : 0;
if (demo.black_pro) {
demo.black_ranking -= 1000;
settings.black_pro = settings.black_ranking > 1000 ? 1 : 0;
if (settings.black_pro) {
settings.black_ranking -= 1000;
}
demo.white_pro = demo.white_ranking > 1000 ? 1 : 0;
if (demo.white_pro) {
demo.white_ranking -= 1000;
settings.white_pro = settings.white_ranking > 1000 ? 1 : 0;
if (settings.white_pro) {
settings.white_ranking -= 1000;
}

demo.tournament_record_id = this.props.tournamentRecordId;
demo.tournament_record_round_id = this.props.tournamentRecordRoundId;
settings.tournament_record_id = this.props.tournamentRecordId;
settings.tournament_record_round_id = this.props.tournamentRecordRoundId;

if (!demo.name) {
demo.name = _("Demo Board");
if (!settings.name) {
settings.name = this.props.game_record_mode
? pgettext("Game record from real life game", "Game Record")
: _("Demo Board");
}

console.log("Sending", demo);
console.log("Sending", settings);
this.saveSettings();
this.close();
post("demos", demo)
.then((res) => {
console.log("Demo create response: ", res);
browserHistory.push(`/demo/${res.id}`);
})
.catch(errorAlerter);

if (this.props.game_record_mode) {
settings.library_collection_id = this.props.libraryCollectionId;

post("game_records/", settings)
.then((res) => {
console.log("Game record create response: ", res);
browserHistory.push(`/game/${res.id}`);
})
.catch(errorAlerter);
} else {
// Review board demo
post("demos", settings)
.then((res) => {
console.log("Demo create response: ", res);
browserHistory.push(`/demo/${res.id}`);
})
.catch(errorAlerter);
}
};
validateBoardSize() {
const next = this.next();
Expand Down Expand Up @@ -1717,7 +1734,14 @@ export class ChallengeModal extends Modal<Events, ChallengeModalProperties, any>
<div className="header">
<h2>
{mode === "open" && <span>{_("Custom Game")}</span>}
{mode === "demo" && <span>{_("Demo Board")}</span>}
{mode === "demo" && (
<span>
{this.props.game_record_mode
? pgettext("Game record from real life game", "Game Record")
: _("Demo Board")}
?
</span>
)}
{mode === "player" && (
<span className="header-with-icon">
<PlayerIcon id={player_id} size={32} />
Expand Down Expand Up @@ -1751,7 +1775,9 @@ export class ChallengeModal extends Modal<Events, ChallengeModalProperties, any>
<button onClick={this.close}>{_("Close")}</button>
{mode === "demo" && (
<button onClick={this.createDemo} className="primary">
{_("Create Demo")}
{this.props.game_record_mode
? _("Create Game Record")
: _("Create Demo")}
</button>
)}
{mode === "computer" && (
Expand Down Expand Up @@ -1867,6 +1893,24 @@ export function challenge(
/>,
);
}
export function createGameRecord(props: {
library_collection_id?: number;
players_list?: Array<{ name: string; rank: number }>;
tournament_record_id?: number;
tournament_record_round_id?: number;
}) {
const mode: ChallengeModes = "demo";
return openModal(
<ChallengeModal
mode={mode}
game_record_mode={true}
libraryCollectionId={props.library_collection_id}
playersList={props.players_list}
tournamentRecordId={props.tournament_record_id}
tournamentRecordRoundId={props.tournament_record_round_id}
/>,
);
}
export function createDemoBoard(
players_list?: Array<{ name: string; rank: number }>,
tournament_record_id?: number,
Expand Down
10 changes: 8 additions & 2 deletions src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export function NavBar(): JSX.Element {
closeNavbar();
createDemoBoard();
};
/*
const newRecord = () => {
closeNavbar();
createGameRecord();
};
*/

React.useEffect(() => {
setForceNavClose(true);
Expand Down Expand Up @@ -370,7 +376,7 @@ export function NavBar(): JSX.Element {
placeholder={_("Search")}
/>
</div>
{(search_focus || omniMouseOver || null) && (
{(search_focus || omniMouseOver) && (
<OmniSearch
search={search}
onMouseOver={() => setOmniMouseOver(true)}
Expand All @@ -385,7 +391,7 @@ export function NavBar(): JSX.Element {
<span className="spacer" />
<i className="fa fa-adjust" onClick={toggleTheme} />
<LanguagePicker />
{(show_sign_in || null) && (
{show_sign_in && (
<Link className="sign-in" to={"/sign-in#" + location.pathname}>
{_("Sign In")}
</Link>
Expand Down
45 changes: 22 additions & 23 deletions src/views/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ export function Game(): JSX.Element | null {
}
return (
<div className="rengo-header-block">
{((!goban.current?.review_id && show_title) || null) && (
{!goban.current?.review_id && show_title && (
<div className="game-state">{title}</div>
)}
</div>
Expand Down Expand Up @@ -1017,7 +1017,7 @@ export function Game(): JSX.Element | null {
</button>
</span>

{(view_mode !== "portrait" || null) && (
{view_mode !== "portrait" && (
<span className="move-number">
{interpolate(_("Move {{move_number}}"), {
move_number: goban.current?.engine.getMoveNumber(),
Expand All @@ -1031,7 +1031,7 @@ export function Game(): JSX.Element | null {
const frag_kb_shortcuts = () => {
return (
<div>
{(game_id > 0 || null) && (
{game_id > 0 && (
<UIPush event="review-added" channel={`game-${game_id}`} action={reviewAdded} />
)}
<KBShortcut shortcut="up" action={nav_up} />
Expand All @@ -1057,7 +1057,7 @@ export function Game(): JSX.Element | null {
shortcut="f9"
action={() => setAnalyzeTool("draw", analyze_pencil_color)}
/>
{(goban.current?.mode === "analyze" || null) && (
{goban.current?.mode === "analyze" && (
<KBShortcut shortcut="f10" action={clear_and_sync} />
)}
<KBShortcut shortcut="del" action={delete_branch} />
Expand Down Expand Up @@ -1698,7 +1698,7 @@ export function Game(): JSX.Element | null {
<div className="left-col"></div>

<div className="center-col">
{(view_mode === "portrait" || null) && (
{view_mode === "portrait" && (
<div>
<PlayerCards
historical_black={historical_black}
Expand All @@ -1722,22 +1722,21 @@ export function Game(): JSX.Element | null {

{frag_below_board_controls()}

{((view_mode === "square" && !squashed) || null) && CHAT}
{view_mode === "square" && !squashed && CHAT}

{((view_mode === "portrait" && !zen_mode) || null) && frag_ai_review()}
{view_mode === "portrait" && !zen_mode && frag_ai_review()}

{(view_mode === "portrait" || null) &&
{view_mode === "portrait" &&
(review ? frag_review_controls() : frag_play_controls(false))}

{((view_mode === "portrait" && !zen_mode) || null) && CHAT}
{view_mode === "portrait" && !zen_mode && CHAT}

{((view_mode === "portrait" &&
{view_mode === "portrait" &&
!zen_mode &&
user_is_player &&
phase !== "finished") ||
null) && <CancelButton className="bold reject" />}
phase !== "finished" && <CancelButton className="bold reject" />}

{((view_mode === "portrait" && !zen_mode) || null) && (
{view_mode === "portrait" && !zen_mode && (
<GameDock
annulled={annulled}
selected_ai_review_uuid={selected_ai_review_uuid}
Expand All @@ -1764,10 +1763,10 @@ export function Game(): JSX.Element | null {
)}
</div>

{(view_mode !== "portrait" || null) && (
{view_mode !== "portrait" && (
<div className={"right-col" + (experimental ? " experimental" : "")}>
{(zen_mode || null) && <div className="align-col-start"></div>}
{(view_mode === "square" || view_mode === "wide" || null) && (
{zen_mode && <div className="align-col-start"></div>}
{(view_mode === "square" || view_mode === "wide") && (
<div>
<PlayerCards
historical_black={historical_black}
Expand All @@ -1788,23 +1787,23 @@ export function Game(): JSX.Element | null {
</div>
)}

{(view_mode === "square" || view_mode === "wide" || null) &&
{(view_mode === "square" || view_mode === "wide") &&
!zen_mode &&
frag_ai_review()}

{(view_mode === "square" || view_mode === "wide" || null) &&
{(view_mode === "square" || view_mode === "wide") &&
show_game_timing &&
frag_timings()}

{(view_mode === "square" || view_mode === "wide" || null) &&
{(view_mode === "square" || view_mode === "wide") &&
show_bot_detection_results &&
frag_bot_detection_results()}

{review ? frag_review_controls() : frag_play_controls(true)}

{(view_mode === "wide" || null) && CHAT}
{((view_mode === "square" && squashed) || null) && CHAT}
{((view_mode === "square" && squashed) || null) && CHAT}
{view_mode === "wide" && CHAT}
{view_mode === "square" && squashed && CHAT}
{view_mode === "square" && squashed && CHAT}

<GameDock
annulled={annulled}
Expand All @@ -1829,7 +1828,7 @@ export function Game(): JSX.Element | null {
onDetectionResultsClicked={toggleShowBotDetectionResults}
ai_suspected={bot_detection_results?.ai_suspected.length > 0}
/>
{(zen_mode || null) && <div className="align-col-end"></div>}
{zen_mode && <div className="align-col-end"></div>}
</div>
)}

Expand Down
19 changes: 9 additions & 10 deletions src/views/Game/PlayButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ export function PlayButtons({ show_cancel = true }: PlayButtonsProps): JSX.Eleme
<span>
{cur_move_number === goban.engine.last_official_move.move_number && (
<>
{((cur_move_number >= 1 &&
{cur_move_number >= 1 &&
!engine.rengo &&
player_to_move !== data.get("user").id &&
(player_to_move !== data.get("user").id || engine.is_game_record) &&
!((engine.undo_requested ?? -1) >= engine.getMoveNumber()) &&
goban.submit_move == null) ||
null) && (
<button className="bold undo-button xs" onClick={onUndo}>
{_("Undo")}
</button>
)}
goban.submit_move == null && (
<button className="bold undo-button xs" onClick={onUndo}>
{_("Undo")}
</button>
)}
{show_undo_requested && (
<span>
{show_accept_undo && (
Expand All @@ -153,12 +152,12 @@ export function PlayButtons({ show_cancel = true }: PlayButtonsProps): JSX.Eleme
)}
</span>
<span>
{((!show_submit && is_my_move && engine.handicapMovesLeft() === 0) || null) && (
{!show_submit && is_my_move && engine.handicapMovesLeft() === 0 && (
<button className="sm primary bold pass-button" onClick={pass}>
{_("Pass")}
</button>
)}
{((show_submit && engine.undo_requested !== engine.getMoveNumber()) || null) && (
{show_submit && engine.undo_requested !== engine.getMoveNumber() && (
<button
className="sm primary bold submit-button"
id="game-submit-move"
Expand Down
Loading

0 comments on commit d2ed27d

Please sign in to comment.