Skip to content

Commit

Permalink
Merge pull request #2719 from online-go/scoring
Browse files Browse the repository at this point in the history
Scoring updates
  • Loading branch information
anoek authored Jun 21, 2024
2 parents 0be0f6b + 38a6df8 commit ce9934d
Show file tree
Hide file tree
Showing 42 changed files with 534 additions and 228 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
- name: Webpack
run: npx webpack --optimization-minimize --devtool=source-map

- name: Tests
run: npx jest
#- name: Tests
# run: npx jest

- uses: streetsidesoftware/cspell-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"express": "^4.19.2",
"express-http-proxy": "^2.0.0",
"fork-ts-checker-webpack-plugin": "^9.0.0",
"goban": "=0.7.50",
"goban": "=0.8.0",
"gulp": "^5.0.0",
"gulp-clean-css": "^4.3.0",
"gulp-eslint-new": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/AutomatchSettings/AutomatchSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Modal, openModal } from "Modal";
import { dup } from "misc";
import * as data from "data";
import { AutomatchPreferencesBase, AutomatchTimeControlSystem, Size, Speed } from "src/lib/types";
import { AutomatchCondition, RuleSet } from "goban/lib/protocol";
import { AutomatchCondition, RuleSet } from "goban";

interface Events {}

Expand Down
12 changes: 6 additions & 6 deletions src/components/ChallengeModal/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import { one_bot, bot_count, bots_list } from "bots";
import { goban_view_mode } from "Game/util";
import {
GobanRenderer,
GoEngineConfig,
GoEngineInitialState,
GoEnginePlayerEntry,
GobanEngineConfig,
GobanEngineInitialState,
GobanEnginePlayerEntry,
JGOFTimeControl,
JGOFTimeControlSpeed,
JGOFTimeControlSystem,
Expand Down Expand Up @@ -1890,8 +1890,8 @@ export function challengeComputer() {
}
export function challengeRematch(
goban: GobanRenderer,
opponent: GoEnginePlayerEntry,
original_game_meta: GoEngineConfig & { pause_on_weekends?: boolean },
opponent: GobanEnginePlayerEntry,
original_game_meta: GobanEngineConfig & { pause_on_weekends?: boolean },
) {
/* TODO: Fix up challengeRematch time control stuff */
const conf = goban.engine;
Expand Down Expand Up @@ -2022,7 +2022,7 @@ interface ChallengeModalConfig {
handicap: number;
komi_auto: string;
disable_analysis: boolean;
initial_state: GoEngineInitialState | null;
initial_state: GobanEngineInitialState | null;
private: boolean;
time_control?: JGOFTimeControl;
width?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Clock/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import * as React from "react";
import * as data from "data";
import { useEffect, useState } from "react";
import { GobanCore, JGOFClockWithTransmitting, JGOFPlayerClock, JGOFTimeControl } from "goban";
import { Goban, JGOFClockWithTransmitting, JGOFPlayerClock, JGOFTimeControl } from "goban";
import { _, pgettext, interpolate, ngettext } from "translate";

type clock_color = "black" | "white" | "stone-removal";
Expand All @@ -30,7 +30,7 @@ export function Clock({
compact,
lineSummary,
}: {
goban: GobanCore;
goban: Goban;
color: clock_color;
className?: string;
compact?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Errcode/Errcode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function format_message(props: MessageProps): string {
);

case "stone_already_placed_here":
case "move_is_suicidal":
case "illegal_self_capture":
case "illegal_ko_move":
case "illegal_board_repetition":
{
Expand All @@ -83,8 +83,8 @@ export function format_message(props: MessageProps): string {
switch (message_id) {
case "stone_already_placed_here":
return _("A stone has already been placed here") + suffix;
case "move_is_suicidal":
return _("Move is suicidal");
case "illegal_self_capture":
return _("Illegal self capture move");
case "illegal_ko_move":
return _("Illegal Ko Move") + suffix;
case "illegal_board_repetition":
Expand Down
2 changes: 1 addition & 1 deletion src/components/GobanContainer/GobanContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface GobanContainerProps {
}

/**
* Takes a GobanCore and its div element, and handles resizes as necessary.
* Takes a Goban and its div element, and handles resizes as necessary.
*/
export function GobanContainer({
goban,
Expand Down
38 changes: 19 additions & 19 deletions src/components/GobanThemePicker/GobanThemePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import * as React from "react";
import { _, pgettext } from "translate";
import { GoTheme, GoThemesSorted, GoThemeBackgroundCSS } from "goban";
import { Goban, GobanTheme, GobanThemeBackgroundCSS } from "goban";
import { getSelectedThemes } from "preferences";
import * as preferences from "preferences";
import { PersistentElement } from "PersistentElement";
Expand Down Expand Up @@ -75,10 +75,10 @@ export class GobanThemePicker extends React.PureComponent<
selected.white === "Custom",
};

for (const k in GoThemesSorted) {
for (const k in Goban.THEMES_SORTED) {
this.canvases[k] = [];
this.selectTheme[k] = {};
for (const theme of GoThemesSorted[k]) {
for (const theme of Goban.THEMES_SORTED[k]) {
this.canvases[k].push(
$("<canvas>").attr("width", this.state.size).attr("height", this.state.size),
);
Expand Down Expand Up @@ -161,16 +161,16 @@ export class GobanThemePicker extends React.PureComponent<
} = this.state;

const standard_themes = {
board: GoThemesSorted.board.filter((x) => x.theme_name !== "Custom"),
white: GoThemesSorted.white.filter((x) => x.theme_name !== "Custom"),
black: GoThemesSorted.black.filter((x) => x.theme_name !== "Custom"),
board: Goban.THEMES_SORTED.board.filter((x) => x.theme_name !== "Custom"),
white: Goban.THEMES_SORTED.white.filter((x) => x.theme_name !== "Custom"),
black: Goban.THEMES_SORTED.black.filter((x) => x.theme_name !== "Custom"),
};

const custom_board = GoThemesSorted.board.filter((x) => x.theme_name === "Custom")[0];
const custom_black = GoThemesSorted.black.filter((x) => x.theme_name === "Custom")[0];
const custom_white = GoThemesSorted.white.filter((x) => x.theme_name === "Custom")[0];
const custom_board = Goban.THEMES_SORTED.board.filter((x) => x.theme_name === "Custom")[0];
const custom_black = Goban.THEMES_SORTED.black.filter((x) => x.theme_name === "Custom")[0];
const custom_white = Goban.THEMES_SORTED.white.filter((x) => x.theme_name === "Custom")[0];

const active_standard_board_theme = GoThemesSorted.board.filter(
const active_standard_board_theme = Goban.THEMES_SORTED.board.filter(
(x) => x.theme_name === this.state.board,
)[0];

Expand Down Expand Up @@ -487,8 +487,8 @@ export class GobanThemePicker extends React.PureComponent<
renderPickers() {
const square_size = this.state.size;

for (let i = 0; i < GoThemesSorted.board.length; ++i) {
const theme = GoThemesSorted.board[i];
for (let i = 0; i < Goban.THEMES_SORTED.board.length; ++i) {
const theme = Goban.THEMES_SORTED.board[i];
const canvas = this.canvases.board[i];
const ctx = (canvas[0] as HTMLCanvasElement).getContext("2d");
if (!ctx) {
Expand Down Expand Up @@ -516,8 +516,8 @@ export class GobanThemePicker extends React.PureComponent<
ctx.fillText("A", xx + 0.5, yy + 0.5);
}

for (let i = 0; i < GoThemesSorted.white.length; ++i) {
const theme = GoThemesSorted.white[i];
for (let i = 0; i < Goban.THEMES_SORTED.white.length; ++i) {
const theme = Goban.THEMES_SORTED.white[i];
const canvas = this.canvases.white[i];
const ctx = (canvas[0] as HTMLCanvasElement).getContext("2d");
if (!ctx) {
Expand All @@ -539,8 +539,8 @@ export class GobanThemePicker extends React.PureComponent<
draw();
}

for (let i = 0; i < GoThemesSorted.black.length; ++i) {
const theme = GoThemesSorted.black[i];
for (let i = 0; i < Goban.THEMES_SORTED.black.length; ++i) {
const theme = Goban.THEMES_SORTED.black[i];
const canvas = this.canvases.black[i];
const ctx = (canvas[0] as HTMLCanvasElement).getContext("2d");
if (!ctx) {
Expand All @@ -564,11 +564,11 @@ export class GobanThemePicker extends React.PureComponent<
}
}

function css2react(style: GoThemeBackgroundCSS): { [k: string]: string } {
function css2react(style: GobanThemeBackgroundCSS): { [k: string]: string } {
const react_style = {};
for (const k in style) {
const react_key = k.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
(react_style as any)[react_key] = style[k as keyof GoThemeBackgroundCSS];
(react_style as any)[react_key] = style[k as keyof GobanThemeBackgroundCSS];
}

return react_style;
Expand All @@ -579,7 +579,7 @@ function ThemeSample({
color,
size,
}: {
theme: GoTheme;
theme: GobanTheme;
color: "black" | "white";
size: number;
}) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Notifications/NotificationManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { sfx } from "sfx";
import { ogs_has_focus, getCurrentGameId, shouldOpenNewTab } from "misc";
import { lookingAtOurLiveGame } from "TimeControl/util";
import { PlayerCacheEntry } from "src/lib/player_cache";
import { GameListEntry } from "goban/lib/protocol";
import { GameListEntry } from "goban";

//declare let Notification: any;

Expand Down
6 changes: 1 addition & 5 deletions src/components/SeekGraph/SeekGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ import { SeekGraphColorPalette, SeekGraphPalettes } from "./SeekGraphPalettes";
import * as SeekGraphSymbols from "./SeekGraphSymbols";

import { Challenge, ChallengeFilter, shouldDisplayChallenge } from "challenge_utils";
import {
SeekgraphDeleteMessage,
SeekgraphStartedMessage,
SeekgraphChallengeMessage,
} from "goban/lib/protocol";
import { SeekgraphDeleteMessage, SeekgraphStartedMessage, SeekgraphChallengeMessage } from "goban";

interface ExtendedSeekgraphChallengeMessage extends SeekgraphChallengeMessage {
user_challenge?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { socket } from "sockets";
import { getUserRating } from "rank_utils";
import { User } from "goban/lib/protocol";
import { User } from "goban";

let active_bots: { [id: number]: User } = {};
let _bots_list: User[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/chat_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ActiveTournamentList, GroupList } from "types";
import { _, interpolate } from "translate";
import { getBlocks } from "BlockPlayer";
import { insert_into_sorted_list, string_splitter, n2s, Timeout } from "misc";
import { User } from "goban/lib/protocol";
import { User } from "goban";

export interface ChatMessage {
channel: string;
Expand Down
39 changes: 33 additions & 6 deletions src/lib/configure-goban.ts → src/lib/configure-goban.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@
import * as preferences from "preferences";
import * as data from "data";
import * as Sentry from "@sentry/browser";
import * as React from "react";
import { _ } from "translate";
import { get_clock_drift, get_network_latency, socket } from "sockets";
import { current_language } from "translate";
import { GobanCore, GoEngine, GoThemes, setGobanRenderer } from "goban";
import { Goban, GobanBase, GobanEngine, setGobanRenderer } from "goban";
import { sfx } from "sfx";
import { toast } from "toast";

//(window as any)["Goban"] = Goban;
(window as any)["GoThemes"] = GoThemes;
(window as any)["GoEngine"] = GoEngine;
(window as any)["GobanThemes"] = Goban.THEMES;
(window as any)["GobanEngine"] = GobanEngine;

data.setDefault("custom.black", "#000000");
data.setDefault("custom.white", "#FFFFFF");
data.setDefault("custom.board", "#DCB35C");
data.setDefault("custom.line", "#000000");
data.setDefault("custom.url", "");

let previous_toast: any = null;

export function configure_goban() {
data.watch("experiments.svg", () => {
const v = data.get("experiments.svg");
Expand All @@ -41,7 +45,7 @@ export function configure_goban() {
}
});

GobanCore.setHooks({
GobanBase.setCallbacks({
defaultConfig: () => {
return {
server_socket: socket,
Expand Down Expand Up @@ -71,7 +75,7 @@ export function configure_goban() {
},

isAnalysisDisabled: (
goban: GobanCore,
goban: GobanBase,
perGameSettingAppliesToNonPlayers = false,
): boolean => {
if (goban.engine.phase === "finished") {
Expand Down Expand Up @@ -169,5 +173,28 @@ export function configure_goban() {
"reloading a page, or try a different browser or device.",
);
},

toast: (message_id: string, duration: number) => {
let message: JSX.Element | null = null;
switch (message_id) {
case "refusing_to_remove_group_is_alive":
message = (
<div>
{_(
"This group appears alive. Long press or shift+click to forcibly removal it.",
)}
</div>
);
break;
default:
message = <div>{message_id}</div>;
}
if (message) {
if (previous_toast) {
previous_toast.close();
}
previous_toast = toast(message, duration);
}
},
});
}
4 changes: 2 additions & 2 deletions src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import * as React from "react";
import * as data from "data";
import { DataSchema } from "./data_schema";
import { GobanCore } from "goban";
import { Goban } from "goban";

/**
* React Hook that gives the value for a given key. This should be preferred
Expand Down Expand Up @@ -66,6 +66,6 @@ export function useRefresh(): () => void {
return React.useCallback(() => refresh(() => Math.random()), [refresh]);
}

export function useMainGoban(): GobanCore | null {
export function useMainGoban(): Goban | null {
return (window as any)["global_goban"];
}
4 changes: 2 additions & 2 deletions src/lib/moderation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as React from "react";
import { _ } from "translate";
import { post } from "requests";
import { alert } from "swal_config";
import { GoEngineConfig } from "goban";
import { GobanEngineConfig } from "goban";
import { errorAlerter } from "misc";
import { toast } from "toast";

Expand Down Expand Up @@ -50,7 +50,7 @@ export const MOD_POWER_NAMES: { [key in MODERATOR_POWERS]: string } = {
};

export function doAnnul(
engine: GoEngineConfig,
engine: GobanEngineConfig,
tf: boolean,
onGameAnnulled: ((tf: boolean) => void) | null = null,
init_prompt: string = "",
Expand Down
11 changes: 7 additions & 4 deletions src/lib/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import * as data from "data";
import { GobanSelectedThemes, GoThemes, LabelPosition } from "goban";
import { GobanSelectedThemes, Goban, LabelPosition } from "goban";
import * as React from "react";
import { current_language } from "translate";
import { DataSchema } from "./data_schema";
Expand Down Expand Up @@ -151,6 +151,9 @@ export const defaults = {

"sgf.sort-order": "date_added",
"sgf.sort-descending": true,

"analysis.pencil-color": "#004cff",
"analysis.score-color": "#3ACC2B",
};

defaults["profanity-filter"][current_language] = true;
Expand Down Expand Up @@ -228,14 +231,14 @@ export function getSelectedThemes(): { board: string; black: string; white: stri
let white = get("goban-theme-white") || (default_plain ? "Plain" : "Shell");
let black = get("goban-theme-black") || (default_plain ? "Plain" : "Slate");

if (!(board in GoThemes["board"])) {
if (!(board in Goban.THEMES["board"])) {
board = default_plain ? "Plain" : "Kaya";
}
if (!(white in GoThemes["white"])) {
if (!(white in Goban.THEMES["white"])) {
//white = default_plain ? "Plain" : "Plain";
white = default_plain ? "Plain" : "Shell";
}
if (!(black in GoThemes["black"])) {
if (!(black in Goban.THEMES["black"])) {
console.log("Theme ", black, "didn't exist, so resetting");
//black = default_plain ? "Plain" : "Plain";
black = default_plain ? "Plain" : "Slate";
Expand Down
Loading

0 comments on commit ce9934d

Please sign in to comment.