Skip to content

Commit

Permalink
Merge pull request online-go#2794 from GreenAsJade/abandon_forced_sco…
Browse files Browse the repository at this point in the history
…ring_game_summary_update

"Abandon forced scoring" - game summary update
  • Loading branch information
anoek authored Aug 20, 2024
2 parents 368e9f7 + 8037dd3 commit 8fc35e4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 35 deletions.
19 changes: 16 additions & 3 deletions src/views/Game/GameLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ const TRUNCATED_GAME_LOG_LENGTH = 25;

interface GameLogProps {
goban_config: GobanEngineConfig;
onContainsTimeout?: (player_id: number) => void;
onContainsTimeout?: (player_id: number | null) => void;
onContainsAbandonment?: (contains_abandonment: boolean) => void;
}

export function GameLog({ goban_config, onContainsTimeout }: GameLogProps): JSX.Element {
export function GameLog({
goban_config,
onContainsTimeout,
onContainsAbandonment,
}: GameLogProps): JSX.Element {
const [log, setLog] = React.useState<LogEntry[]>([]);
const [shouldDisplayFullLog, setShouldDisplayFullLog] = React.useState(false);

Expand All @@ -42,11 +47,19 @@ export function GameLog({ goban_config, onContainsTimeout }: GameLogProps): JSX.
React.useEffect(() => {
socket.send(`game/log`, { game_id }, (log) => {
setLog(log);

onContainsTimeout && onContainsTimeout(null);
onContainsAbandonment && onContainsAbandonment(false);
const timeout_entry = log.find((entry) => entry.event === "timed_out");
if (timeout_entry && onContainsTimeout) {
onContainsTimeout(timeout_entry.data.player_id);
}
const abandoned_entry = log.find(
(entry) => entry.event === "force_stone_removal_acceptance_abandoned",
);
if (abandoned_entry && onContainsAbandonment) {
console.log("GameLog: Found an abandonment event");
onContainsAbandonment(true);
}
});
}, [game_id]);

Expand Down
92 changes: 60 additions & 32 deletions src/views/ReportsCenter/ReportedGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
useCurrentMove,
game_control,
GameLog,
useGoban,
} from "Game";
import { GobanRenderer } from "goban";
import { Resizable } from "Resizable";
Expand Down Expand Up @@ -64,6 +65,7 @@ export function ReportedGame({
const [annulled, setAnnulled] = React.useState<boolean>(false);
const [finalActionTime, setFinalActionTime] = React.useState<moment.Duration | null>(null);
const [timedOutPlayer, setTimedOutPlayer] = React.useState<number | null>(null);
const [scoringAbandoned, setScoringAbandoned] = React.useState<boolean>(false);

const user = useUser();

Expand Down Expand Up @@ -180,38 +182,14 @@ export function ReportedGame({
<div>White: {game && <Player user={game.white} />}</div>
<div>Game Phase: {goban.engine.phase}</div>
{(goban.engine.phase === "finished" || null) && (
<>
<div>
{_("Game Outcome:") + ` ${winner} (`}
<Player user={goban!.engine.winner as number} />
{` ) ${pgettext(
"use like: they won 'by' this much",
"by",
)} `}
{goban.engine.outcome}
{annulled ? _(" annulled") : ""}
</div>
<div>
{_("The last event took: ") +
showSecondsResolution(finalActionTime)}
</div>

{timedOutPlayer && (
<div>
{_("Player timed out:")}
<Player user={timedOutPlayer} />
{timedOutPlayer === reported_by
? pgettext(
"A note of surprise telling a moderator that the person who timed out is the reporter",
" (reporter!)",
)
: pgettext(
"A label next to a player name telling a moderator that a they are the one who was reported",
" (the reported player)",
)}
</div>
)}
</>
<GameSummary
winner={winner}
finalActionTime={finalActionTime}
timedOutPlayer={timedOutPlayer}
reported_by={reported_by}
annulled={annulled}
scoringAbandoned={scoringAbandoned}
/>
)}
{user.is_moderator && (
<>
Expand Down Expand Up @@ -289,6 +267,7 @@ export function ReportedGame({
<GameLog
goban_config={goban.config}
onContainsTimeout={setTimedOutPlayer}
onContainsAbandonment={setScoringAbandoned}
/>
</div>

Expand All @@ -306,3 +285,52 @@ export function ReportedGame({
</div>
);
}

interface GameSummaryProps {
winner: string;
finalActionTime: moment.Duration | null;
timedOutPlayer: number | null;
reported_by: number;
annulled: boolean;
scoringAbandoned: boolean;
}

function GameSummary({
winner,
finalActionTime,
timedOutPlayer,
reported_by,
annulled,
scoringAbandoned,
}: GameSummaryProps): JSX.Element {
const goban = useGoban();
return (
<div className="GameSummary">
<div>
{_("Game Outcome:") + ` ${winner} (`}
<Player user={goban!.engine.winner as number} />
{` ) ${pgettext("use like: they won 'by' this much", "by")} `}
{goban.engine.outcome}
{annulled ? _(" annulled") : ""}
</div>
<div>{_("The last event took: ") + showSecondsResolution(finalActionTime)}</div>

{timedOutPlayer && (
<div>
{_("Player timed out:")}
<Player user={timedOutPlayer} />
{timedOutPlayer === reported_by
? pgettext(
"A note of surprise telling a moderator that the person who timed out is the reporter",
" (reporter!)",
)
: pgettext(
"A label next to a player name telling a moderator that a they are the one who was reported",
" (the reported player)",
)}
</div>
)}
{scoringAbandoned && <div>{_("Scoring abandoned by both players")}</div>}
</div>
);
}

0 comments on commit 8fc35e4

Please sign in to comment.