This commit is contained in:
Maciej Caderek
2022-02-22 18:47:18 +01:00
parent 707b9cce61
commit ce3167fc7c
10 changed files with 37 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -21,7 +21,6 @@ const defaultConfig: BoardConfig = {
showChecks: true, showChecks: true,
showCoords: true, showCoords: true,
flipped: false, flipped: false,
anonymous: false,
}; };
const defaultHeader: Header = { const defaultHeader: Header = {
@@ -41,6 +40,7 @@ const defaultHeader: Header = {
class Board { class Board {
private cfg: BoardConfig = defaultConfig; private cfg: BoardConfig = defaultConfig;
private _anonymous: boolean = false;
private scale: number = 1; private scale: number = 1;
@@ -90,6 +90,11 @@ class Board {
} }
} }
set anonymous(value: boolean) {
this._anonymous = value;
this.refresh();
}
async refresh() { async refresh() {
await this.renderBackground(); await this.renderBackground();
@@ -197,7 +202,7 @@ class Board {
} }
private getFinalHeader() { private getFinalHeader() {
return this.cfg.anonymous return this._anonymous
? { ? {
...this.header, ...this.header,
White: "Anonymous", White: "Anonymous",

View File

@@ -1,5 +1,5 @@
import WebFont from "webfontloader"; import WebFont from "webfontloader";
import * as Hammer from "hammerjs"; // import * as Hammer from "hammerjs";
import { render } from "solid-js/web"; import { render } from "solid-js/web";
import { BoardStyle, PiecesStyle } from "./types"; import { BoardStyle, PiecesStyle } from "./types";
@@ -77,13 +77,11 @@ const main = async () => {
saveConfig("board"); saveConfig("board");
}, },
toggleAnonymous() { toggleAnonymous() {
setState("boardConfig", "anonymous", !state.boardConfig.anonymous); setState("anonymous", !state.anonymous);
board.updateConfig({ anonymous: state.boardConfig.anonymous }); board.anonymous = state.anonymous;
if (state.pgn !== "") { if (state.pgn !== "") {
const pgn = state.boardConfig.anonymous const pgn = state.anonymous ? state.game.anonymousPGN : state.game.pgn;
? state.game.anonymousPGN
: state.game.pgn;
window.location.hash = `pgn/${compressPGN(pgn)}`; window.location.hash = `pgn/${compressPGN(pgn)}`;
} }
}, },
@@ -189,7 +187,7 @@ const main = async () => {
state.gameConfig.titleScreen state.gameConfig.titleScreen
); );
const name = state.game.getFileName(state.boardConfig.anonymous); const name = state.game.getFileName(state.anonymous);
download(data, name, state.gameConfig.format.toLowerCase()); download(data, name, state.gameConfig.format.toLowerCase());
}, },

View File

@@ -20,7 +20,6 @@ const initialBoardConfig: BoardConfig = {
showChecks: true, showChecks: true,
showCoords: true, showCoords: true,
flipped: false, flipped: false,
anonymous: false,
}; };
const initialGameConfig: GameConfig = { const initialGameConfig: GameConfig = {
@@ -44,13 +43,13 @@ export type State = {
layout: "single" | "double" | "triple"; layout: "single" | "double" | "triple";
activeTab: TabName; activeTab: TabName;
playing: boolean; playing: boolean;
anonymous: boolean;
}; };
const initialState: State = { const initialState: State = {
boardConfig: { boardConfig: {
...initialBoardConfig, ...initialBoardConfig,
...saved.boardConfig, ...saved.boardConfig,
anonymous: false,
}, },
gameConfig: { ...initialGameConfig, ...saved.gameConfig }, gameConfig: { ...initialGameConfig, ...saved.gameConfig },
game: new Game(), game: new Game(),
@@ -62,6 +61,7 @@ const initialState: State = {
layout: mobile ? "single" : "triple", layout: mobile ? "single" : "triple",
activeTab: "load", activeTab: "load",
playing: false, playing: false,
anonymous: false,
}; };
const [state, setState] = createStore(initialState); const [state, setState] = createStore(initialState);

View File

@@ -111,7 +111,6 @@ export type BoardConfig = {
showChecks: boolean; showChecks: boolean;
showCoords: boolean; showCoords: boolean;
flipped: boolean; flipped: boolean;
anonymous: boolean;
}; };
export type Size = "XS" | "S" | "M" | "L" | "XL"; export type Size = "XS" | "S" | "M" | "L" | "XL";

View File

@@ -11,14 +11,14 @@ const Info: Component<{ handlers: Handlers }> = () => {
<div className="info__players"> <div className="info__players">
<p> <p>
<button className="info__color info__color--white"></button> <button className="info__color info__color--white"></button>
<Show when={!state.boardConfig.anonymous} fallback="Anonymous"> <Show when={!state.anonymous} fallback="Anonymous">
{state.game.header.WhitePretty}{" "} {state.game.header.WhitePretty}{" "}
</Show> </Show>
<span className="info__rating">{state.game.header.WhiteElo}</span> <span className="info__rating">{state.game.header.WhiteElo}</span>
</p> </p>
<p> <p>
<button className="info__color info__color--black"></button> <button className="info__color info__color--black"></button>
<Show when={!state.boardConfig.anonymous} fallback="Anonymous"> <Show when={!state.anonymous} fallback="Anonymous">
{state.game.header.BlackPretty}{" "} {state.game.header.BlackPretty}{" "}
</Show> </Show>
<span className="info__rating">{state.game.header.BlackElo}</span> <span className="info__rating">{state.game.header.BlackElo}</span>
@@ -35,11 +35,7 @@ const Info: Component<{ handlers: Handlers }> = () => {
<div className="info__site"> <div className="info__site">
<Show when={state.game.header.Site}> <Show when={state.game.header.Site}>
<p> <p>
<Show <Show when={!state.anonymous || !isLink(state.game.header.Site)}>
when={
!state.boardConfig.anonymous || !isLink(state.game.header.Site)
}
>
<Show <Show
when={isSafeLink(state.game.header.Site)} when={isSafeLink(state.game.header.Site)}
fallback={state.game.header.Site} fallback={state.game.header.Site}

View File

@@ -34,7 +34,7 @@
} }
.load__pgn-file-info { .load__pgn-file-info {
font-size: 1.5rem; font-size: 1.3rem;
} }
.load__pgn-file-info p { .load__pgn-file-info p {

View File

@@ -36,3 +36,18 @@
text-decoration: underline; text-decoration: underline;
cursor: pointer; cursor: pointer;
} }
@media screen and (max-width: 1024px) {
.moves {
text-align: left;
}
.move {
display: inline-block;
}
.move__id,
.move__ply {
display: inline;
margin-right: 0.6rem;
width: auto;
}
}

View File

@@ -79,7 +79,7 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
classList={{ classList={{
options__button: true, options__button: true,
"options__button--last": true, "options__button--last": true,
"options__button--active": state.boardConfig.anonymous, "options__button--active": state.anonymous,
}} }}
onClick={props.handlers.toggleAnonymous} onClick={props.handlers.toggleAnonymous}
title="TOGGLE ANONYMOUS" title="TOGGLE ANONYMOUS"
@@ -191,9 +191,7 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
class="share__btn" class="share__btn"
onClick={() => { onClick={() => {
navigator.clipboard.writeText( navigator.clipboard.writeText(
state.boardConfig.anonymous state.anonymous ? state.game.anonymousPGN : state.pgn
? state.game.anonymousPGN
: state.pgn
); );
blinkCopy("pgn"); blinkCopy("pgn");
}} }}
@@ -217,9 +215,7 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
const data = new Blob([state.pgn], { const data = new Blob([state.pgn], {
type: "application/vnd.chess-pgn;charset=utf-8", type: "application/vnd.chess-pgn;charset=utf-8",
}); });
const name = state.game.getFileName( const name = state.game.getFileName(state.anonymous);
state.boardConfig.anonymous
);
download(data, name, "pgn"); download(data, name, "pgn");
}} }}
> >
@@ -229,7 +225,7 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
class="share__btn" class="share__btn"
onClick={() => { onClick={() => {
const title = state.game.getTitle({ const title = state.game.getTitle({
anonymous: state.boardConfig.anonymous, anonymous: state.anonymous,
}); });
const md = `[${title}](${window.location.href})`; const md = `[${title}](${window.location.href})`;