diff --git a/src/components/AutomatchSettings/AutomatchSettings.styl b/src/components/AutomatchSettings/AutomatchSettings.styl deleted file mode 100644 index 9b24b138c6..0000000000 --- a/src/components/AutomatchSettings/AutomatchSettings.styl +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) Online-Go.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - - -.AutomatchSettings { - width: 44rem; - max-width: 100vw; - margin-top: 2rem; - - .body { - display: flex; - flex-direction: column; - align-items: center; - margin-bottom: 1rem; - } - - .automatch-settings { - margin-top: 2rem; - td { - padding-left: 1rem; - } - th { - text-align: right; - padding-right: 1rem; - vertical-align: top; - padding-top: 0.3rem; - } - td { - width: 20rem; - padding-bottom: 1.5rem; - } - i { - font-size: font-size-small; - } - - input[type="number"] { - width: 2.5rem; - } - - select { - width: 12rem; - } - } -} diff --git a/src/components/AutomatchSettings/AutomatchSettings.tsx b/src/components/AutomatchSettings/AutomatchSettings.tsx deleted file mode 100644 index f4e2278095..0000000000 --- a/src/components/AutomatchSettings/AutomatchSettings.tsx +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright (C) Online-Go.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import * as React from "react"; -import { _ } from "@/lib/translate"; -import { Modal, openModal } from "@/components/Modal"; -import { dup } from "@/lib/misc"; -import * as data from "@/lib/data"; -import { AutomatchPreferencesBase, AutomatchTimeControlSystem, Size, Speed } from "@/lib/types"; -import { AutomatchCondition, JGOFTimeControlSpeed, RuleSet } from "goban"; - -interface Events {} - -interface AutomatchSettingsProperties {} - -export type AutomatchPreferences = AutomatchPreferencesBase & { size_options: Size[] }; - -interface AutomatchSettingsState { - tab: Speed; - blitz_settings: AutomatchPreferences; - live_settings: AutomatchPreferences; - correspondence_settings: AutomatchPreferences; -} - -const default_blitz: AutomatchPreferences = { - upper_rank_diff: 3, - lower_rank_diff: 3, - size_options: ["19x19"], - rules: { - condition: "no-preference", - value: "japanese", - }, - time_control: { - condition: "no-preference", - value: { - system: "byoyomi", - }, - }, - handicap: { - condition: "no-preference", - value: "disabled", - }, -}; -const default_live: AutomatchPreferences = { - upper_rank_diff: 3, - lower_rank_diff: 3, - size_options: ["19x19"], - rules: { - condition: "no-preference", - value: "japanese", - }, - time_control: { - condition: "no-preference", - value: { - system: "byoyomi", - }, - }, - handicap: { - condition: "no-preference", - value: "enabled", - }, -}; -const default_correspondence: AutomatchPreferences = { - upper_rank_diff: 3, - lower_rank_diff: 3, - size_options: ["19x19"], - rules: { - condition: "no-preference", - value: "japanese", - }, - time_control: { - condition: "no-preference", - value: { - system: "fischer", - }, - }, - handicap: { - condition: "no-preference", - value: "enabled", - }, -}; - -const ConditionSelect = (props: { value: any; onChange: (x: any) => void }) => ( -
- -
-); - -export function getAutomatchSettings(speed: JGOFTimeControlSpeed) { - switch (speed) { - case "blitz": - return dup(data.get("automatch.blitz", default_blitz)); - case "rapid": - throw new Error("Rapid is not supported yet"); - case "live": - return dup(data.get("automatch.live", default_live)); - case "correspondence": - return dup(data.get("automatch.correspondence", default_correspondence)); - } -} - -export class AutomatchSettings extends Modal< - Events, - AutomatchSettingsProperties, - AutomatchSettingsState -> { - constructor(props: AutomatchSettingsProperties) { - super(props); - this.state = { - tab: data.get("automatch.last-tab", "live") as Speed, - blitz_settings: data.get("automatch.blitz", default_blitz), - live_settings: data.get("automatch.live", default_live), - correspondence_settings: data.get("automatch.correspondence", default_correspondence), - }; - } - - setTab = (tab: JGOFTimeControlSpeed) => { - data.set("automatch.last-tab", tab); - this.setState({ tab: tab }); - }; - - getSelectedSettings(): AutomatchPreferences { - switch (this.state.tab) { - case "blitz": - return dup(this.state.blitz_settings); - case "live": - return dup(this.state.live_settings); - case "correspondence": - return dup(this.state.correspondence_settings); - } - throw new Error("Invalid tab"); - } - setSelectedSettings(settings: AutomatchPreferences) { - settings = dup(settings); - switch (this.state.tab) { - case "blitz": - data.set("automatch.blitz", settings); - this.setState({ blitz_settings: settings }); - break; - case "live": - data.set("automatch.live", settings); - this.setState({ live_settings: settings }); - break; - case "correspondence": - data.set("automatch.correspondence", settings); - this.setState({ correspondence_settings: settings }); - break; - } - } - setLowerRankDiff = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - const diff = Math.max(0, Math.min(9, parseInt(ev.target.value))); - settings.lower_rank_diff = diff; - this.setSelectedSettings(settings); - }; - setUpperRankDiff = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - const diff = Math.max(0, Math.min(9, parseInt(ev.target.value))); - settings.upper_rank_diff = diff; - this.setSelectedSettings(settings); - }; - setHandicapCondition = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.handicap.condition = ev.target.value as AutomatchCondition; - this.setSelectedSettings(settings); - }; - setTimeControlCondition = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.time_control.condition = ev.target.value as AutomatchCondition; - this.setSelectedSettings(settings); - }; - setRulesCondition = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.rules.condition = ev.target.value as AutomatchCondition; - this.setSelectedSettings(settings); - }; - /* - toggleSize(size) { - const settings = this.getSelectedSettings(); - if (settings.size_options.indexOf(size) >= 0) { - settings.size_options = settings.size_options.filter((x) => x !== size); - } else { - settings.size_options.push(size); - } - if (settings.size_options.length === 0) { - settings.size_options.push("19x19"); - } - this.setSelectedSettings(settings); - } - */ - - setHandicapValue = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.handicap.value = ev.target.value as "enabled" | "disabled"; - this.setSelectedSettings(settings); - }; - setRulesValue = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.rules.value = ev.target.value as RuleSet; - this.setSelectedSettings(settings); - }; - setTimeControlSystem = (ev: React.ChangeEvent) => { - const settings = this.getSelectedSettings(); - settings.time_control.value.system = ev.target.value as AutomatchTimeControlSystem; - this.setSelectedSettings(settings); - }; - - render() { - const settings = this.getSelectedSettings(); - const tab = this.state.tab; - - return ( -
-
-

{_("Automatch Settings")}

-
-
-
- - - -
- -
- - - - - - - - - - - - - - - - - - - - - -
{_("Opponent rank range")} - - - - - -     - - + - - -
{_("Handicap")} - - {settings.handicap.condition === "no-preference" ? ( - - {tab === "blitz" - ? _("Default is disabled") - : _("Default is enabled")}{" "} - - ) : ( - - )} -
{_("Time Control")} - - {settings.time_control.condition === "no-preference" ? ( - - {tab === "correspondence" - ? _("Default is to use Fischer") - : _("Default is to use Byo-Yomi")} - - ) : ( - - )} -
{_("Rules")} - - {settings.rules.condition === "no-preference" ? ( - {_("Default is to use Japanese rules")} - ) : ( - - )} -
-
-
- -
- -
-
- ); - } -} - -export function openAutomatchSettings() { - return openModal(); -} diff --git a/src/components/ChallengeModal/ChallengeModal.tsx b/src/components/ChallengeModal/ChallengeModal.tsx index bc94dd8edc..ecf0cb04e7 100644 --- a/src/components/ChallengeModal/ChallengeModal.tsx +++ b/src/components/ChallengeModal/ChallengeModal.tsx @@ -61,6 +61,7 @@ import { saveTimeControlSettings, updateSystem, } from "@/components/TimeControl/TimeControlUpdates"; +import { Link } from "react-router-dom"; export type ChallengeDetails = rest_api.ChallengeDetails; @@ -84,7 +85,7 @@ interface ChallengeModalProperties { /* These rejection details come from gtp2ogs and allows bots to * be clear about why a challenge is being rejected. */ -interface RejectionDetails { +export interface RejectionDetails { rejection_code: | "blacklisted" | "board_size_not_square" @@ -1741,6 +1742,7 @@ export class ChallengeModalBody extends React.Component< }; render() { + const user = data.get("user"); const mode = this.props.mode; const player_id = this.props.playerId; const player = player_id && player_cache.lookup(player_id); @@ -1807,24 +1809,36 @@ export class ChallengeModalBody extends React.Component< ) : ( )} - {mode === "demo" && ( + + {user?.anonymous && ( +
+ {_("Please sign in to play")} +
+ {_("Register for Free")} + {" | "} + {_("Sign in")} +
+
+ )} + + {!user?.anonymous && mode === "demo" && ( )} - {mode === "computer" && ( + {!user?.anonymous && mode === "computer" && ( )} - {mode === "player" && ( + {!user?.anonymous && mode === "player" && ( )} - {mode === "open" && ( + {!user?.anonymous && mode === "open" && (