File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed
Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import ShowOneHand from "./ShowOneHand";
44import "./index.css" ;
55import { PROGRAM_POSITIONS } from "../../Utils/maps" ;
66import React , { PropsWithChildren , Suspense } from "react" ;
7- import exportPBN from "../../Utils/PBN" ;
7+ import { exportPBNs } from "../../Utils/PBN" ;
88import Board from "../../models/Board" ;
99
1010interface ShowCardsProps extends PropsWithChildren {
@@ -21,7 +21,7 @@ export default function ShowCards(props: ShowCardsProps) {
2121 const allHands = board . getAllHands ( ) ;
2222 return (
2323 < div className = "board-container" >
24- < div className = "board-number" > < div > { board . boardnum } </ div > { dds && < button className = "export" onClick = { ( ) => exportPBN ( board ) } > export to PBN</ button > } </ div >
24+ < div className = "board-number" > < div > { board . boardnum } </ div > { dds && < button className = "export" onClick = { ( ) => exportPBNs ( [ board ] ) } > export to PBN</ button > } </ div >
2525 < div className = "predicted" > { children } </ div >
2626 { dds &&
2727 < div className = "double-dummy" >
Original file line number Diff line number Diff line change @@ -29,11 +29,9 @@ export function convertAllHandsToPBN(allHands: Hand[]) {
2929 return str ;
3030}
3131
32- export default function exportPBN ( board : Board ) {
32+ export function getPBN ( board : Board ) {
3333 const date = new Date ( ) ;
34- const pbn = `% PBN 2.1
35- % EXPORT
36- %Content-type: text/x-pbn; charset=ISO-8859-1
34+ const pbn = `
3735[Event ""]
3836[Site ""]
3937[Date "${ date . getFullYear ( ) } .${ date . getMonth ( ) + 1 } .${ date . getDate ( ) } "]
7371W C 0
7472[OptimumScore ""]
7573`
74+ board . pbn = pbn ;
75+ return pbn ;
76+ }
77+
78+ export function exportPBNs ( boards : Board [ ] ) {
79+ let print = `% PBN 2.1
80+ % EXPORT
81+ %Content-type: text/x-pbn; charset=ISO-8859-1
82+ ` ;
83+ boards . forEach ( ( board ) => {
84+ if ( ! board . pbn ) {
85+ board . pbn = getPBN ( board ) ;
86+ }
87+ print += board . pbn ;
88+ } )
7689
7790 // download
78- const blob = new Blob ( [ pbn ] , { type : 'text/plain' } ) ;
91+ const blob = new Blob ( [ print ] , { type : 'text/plain' } ) ;
7992 const url = URL . createObjectURL ( blob ) ;
8093 // 创建一个临时的 <a> 标签,设置 href 属性为刚刚创建的 URL
8194 const link = document . createElement ( 'a' ) ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export default class Board {
2727 Ehand : Hand ;
2828 Whand : Hand ;
2929 ddsTricks ?: string | ( string | number ) [ ] [ ] ;
30+ pbn ?: string ;
3031
3132 constructor ( boardnum : number ) {
3233 this . boardnum = boardnum ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { createContext } from "react";
22import ShowAllBoards from "../../Components/ShowAllBoards/ShowAllBoards" ;
33import Analysis from "../Analysis/Analysis" ;
44import Board from "../../models/Board" ;
5+ import { exportPBNs } from "../../Utils/PBN" ;
56
67interface ShowResultsProps {
78 all_boards : Board [ ] ;
@@ -20,6 +21,7 @@ function ShowResults(props: ShowResultsProps) {
2021 const { all_boards, dds, ...rest } = props ;
2122 return (
2223 < ShowResultsContext . Provider value = { { all_boards, dds } } >
24+ { all_boards . length > 0 && < button onClick = { ( ) => exportPBNs ( all_boards ) } > export all in pbn format</ button > }
2325 { dds && < Analysis /> }
2426 < ShowAllBoards { ...rest } />
2527 </ ShowResultsContext . Provider >
You can’t perform that action at this time.
0 commit comments