From 82d3cf35c3c6b85b48c94dd6301c8bf718669b8d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Sep 2025 20:52:43 +0900 Subject: feat(frontend): support swift language --- frontend/app/components/Gaming/CodePopover.tsx | 8 +- frontend/app/components/Gaming/ProblemColumn.tsx | 9 +- .../app/components/Gaming/ProblemColumnContent.tsx | 97 +++++++++++++++------- frontend/app/components/Gaming/RankingTable.tsx | 11 ++- frontend/app/components/GolfPlayApp.tsx | 1 + .../components/GolfPlayApps/GolfPlayAppGaming.tsx | 10 ++- frontend/app/components/GolfWatchApp.tsx | 2 + .../GolfWatchApps/GolfWatchAppGaming1v1.tsx | 14 ++-- .../GolfWatchAppGamingMultiplayer.tsx | 6 +- 9 files changed, 112 insertions(+), 46 deletions(-) (limited to 'frontend/app/components') diff --git a/frontend/app/components/Gaming/CodePopover.tsx b/frontend/app/components/Gaming/CodePopover.tsx index a574a77..91245df 100644 --- a/frontend/app/components/Gaming/CodePopover.tsx +++ b/frontend/app/components/Gaming/CodePopover.tsx @@ -2,15 +2,17 @@ import { Popover } from "@base-ui-components/react/popover"; import { faCode, faXmark } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { calcCodeSize } from "../../states/play"; +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import BorderedContainer from "../BorderedContainer"; import CodeBlock from "../Gaming/CodeBlock"; type Props = { code: string; + language: SupportedLanguage; }; -export default function CodePopover({ code }: Props) { - const codeSize = calcCodeSize(code); +export default function CodePopover({ code, language }: Props) { + const codeSize = calcCodeSize(code, language); return ( @@ -33,7 +35,7 @@ export default function CodePopover({ code }: Props) { /> - + diff --git a/frontend/app/components/Gaming/ProblemColumn.tsx b/frontend/app/components/Gaming/ProblemColumn.tsx index 3b7e58c..a355ac4 100644 --- a/frontend/app/components/Gaming/ProblemColumn.tsx +++ b/frontend/app/components/Gaming/ProblemColumn.tsx @@ -1,20 +1,27 @@ +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import TitledColumn from "../TitledColumn"; import ProblemColumnContent from "./ProblemColumnContent"; type Props = { title: string; description: string; + language: SupportedLanguage; sampleCode: string; }; export default function ProblemColumn({ title, description, + language, sampleCode, }: Props) { return ( - + ); } diff --git a/frontend/app/components/Gaming/ProblemColumnContent.tsx b/frontend/app/components/Gaming/ProblemColumnContent.tsx index b85cc6d..0904a98 100644 --- a/frontend/app/components/Gaming/ProblemColumnContent.tsx +++ b/frontend/app/components/Gaming/ProblemColumnContent.tsx @@ -1,14 +1,77 @@ +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import FoldableBorderedContainerWithCaption from "../FoldableBorderedContainerWithCaption"; import CodeBlock from "./CodeBlock"; import InlineCode from "./InlineCode"; +function PhpNotice() { + return ( + +
+

+ スコアはコード中の全 ASCII + 空白文字を除去した後のバイト数です。また、先頭や末尾に置かれた PHP + タグ (、 + ) はカウントされません。 +

+

+ 同じスコアを出した場合、より提出が早かったプレイヤーの勝ちとなります。 +

+

+ この環境の PHP バージョンは{" "} + 8.4.4 です。 mbstring + を除くほとんどの拡張は無効化されています。 + また、ファイルやネットワークアクセスはできません。 +

+

+ テストの成否は、標準出力へ出力された文字列を比較して判定されます。 + 末尾の改行はあってもなくても構いません。 + 標準エラー出力の内容は無視されますが、fatal error + 等で実行が中断された場合は失敗扱いとなります。 +

+

+ なお、 + は{" "} + {" "} + に設定されています。 +

+
+
+ ); +} + +function SwiftNotice() { + return ( + +
+

スコアはコード中の全 ASCII 空白文字を除去した後のバイト数です。

+

+ 同じスコアを出した場合、より提出が早かったプレイヤーの勝ちとなります。 +

+

+ この環境の PHP バージョンは{" "} + 6.1.2 です。 + ファイルアクセスやネットワークアクセスはできません。 +

+

+ テストの成否は、標準出力へ出力された文字列を比較して判定されます。 + 末尾の改行はあってもなくても構いません。 + 標準エラー出力の内容は無視されますが、fatal error + 等で実行が中断された場合は失敗扱いとなります。 +

+
+
+ ); +} + type Props = { description: string; + language: SupportedLanguage; sampleCode: string; }; export default function ProblemColumnContent({ description, + language, sampleCode, }: Props) { return ( @@ -19,39 +82,9 @@ export default function ProblemColumnContent({ - - - -
-

- スコアはコード中の全 ASCII - 空白文字を除去した後のバイト数です。また、先頭や末尾に置かれた PHP - タグ (、 - ) はカウントされません。 -

-

- 同じスコアを出した場合、より提出が早かったプレイヤーの勝ちとなります。 -

-

- この環境の PHP バージョンは{" "} - 8.4.4 です。 mbstring - を除くほとんどの拡張は無効化されています。 - また、ファイルやネットワークアクセスはできません。 -

-

- テストの成否は、標準出力へ出力された文字列を比較して判定されます。 - 末尾の改行はあってもなくても構いません。 - 標準エラー出力の内容は無視されますが、fatal error - 等で実行が中断された場合は失敗扱いとなります。 -

-

- なお、 - は{" "} - {" "} - に設定されています。 -

-
+
+ {language === "php" ? : } ); } diff --git a/frontend/app/components/Gaming/RankingTable.tsx b/frontend/app/components/Gaming/RankingTable.tsx index 3368f60..7359d40 100644 --- a/frontend/app/components/Gaming/RankingTable.tsx +++ b/frontend/app/components/Gaming/RankingTable.tsx @@ -1,6 +1,7 @@ import { useAtomValue } from "jotai"; import React from "react"; import { rankingAtom } from "../../states/watch"; +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import CodePopover from "./CodePopover"; function TableHeaderCell({ children }: { children: React.ReactNode }) { @@ -29,7 +30,11 @@ function formatUnixTimestamp(timestamp: number) { return `${year}-${month}-${day} ${hours}:${minutes}`; } -export default function RankingTable() { +type Props = { + problemLanguage: SupportedLanguage; +}; + +export default function RankingTable({ problemLanguage }: Props) { const ranking = useAtomValue(rankingAtom); return ( @@ -57,7 +62,9 @@ export default function RankingTable() { {formatUnixTimestamp(entry.submitted_at)} - {entry.code && } + {entry.code && ( + + )} ))} diff --git a/frontend/app/components/GolfPlayApp.tsx b/frontend/app/components/GolfPlayApp.tsx index e74edc7..6c77f8c 100644 --- a/frontend/app/components/GolfPlayApp.tsx +++ b/frontend/app/components/GolfPlayApp.tsx @@ -136,6 +136,7 @@ export default function GolfPlayApp({ game, player, initialGameState }: Props) { playerProfile={playerProfile} problemTitle={game.problem.title} problemDescription={game.problem.description} + problemLanguage={game.problem.language} sampleCode={game.problem.sample_code} initialCode={initialGameState.code} onCodeChange={onCodeChange} diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index 86b2379..9eab91e 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -8,6 +8,7 @@ import { statusAtom, } from "../../states/play"; import type { PlayerProfile } from "../../types/PlayerProfile"; +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import BorderedContainer from "../BorderedContainer"; import LeftTime from "../Gaming/LeftTime"; import ProblemColumn from "../Gaming/ProblemColumn"; @@ -22,6 +23,7 @@ type Props = { playerProfile: PlayerProfile; problemTitle: string; problemDescription: string; + problemLanguage: SupportedLanguage; sampleCode: string; initialCode: string; onCodeChange: (code: string) => void; @@ -34,6 +36,7 @@ export default function GolfPlayAppGaming({ playerProfile, problemTitle, problemDescription, + problemLanguage, sampleCode, initialCode, onCodeChange, @@ -44,11 +47,13 @@ export default function GolfPlayAppGaming({ const score = useAtomValue(scoreAtom); const status = useAtomValue(statusAtom); - const [codeSize, setCodeSize] = useState(calcCodeSize(initialCode)); + const [codeSize, setCodeSize] = useState( + calcCodeSize(initialCode, problemLanguage), + ); const textareaRef = useRef(null); const handleTextChange = (e: React.ChangeEvent) => { - setCodeSize(calcCodeSize(e.target.value)); + setCodeSize(calcCodeSize(e.target.value, problemLanguage)); if (!isFinished) { onCodeChange(e.target.value); } @@ -91,6 +96,7 @@ export default function GolfPlayAppGaming({ diff --git a/frontend/app/components/GolfWatchApp.tsx b/frontend/app/components/GolfWatchApp.tsx index a8b4630..41b5a01 100644 --- a/frontend/app/components/GolfWatchApp.tsx +++ b/frontend/app/components/GolfWatchApp.tsx @@ -137,6 +137,7 @@ export default function GolfWatchApp({ playerProfileB={playerProfileB} problemTitle={game.problem.title} problemDescription={game.problem.description} + problemLanguage={game.problem.language} sampleCode={game.problem.sample_code} /> ) : ( @@ -144,6 +145,7 @@ export default function GolfWatchApp({ gameDisplayName={game.display_name} problemTitle={game.problem.title} problemDescription={game.problem.description} + problemLanguage={game.problem.language} sampleCode={game.problem.sample_code} /> ); diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx index 54a5895..f06728d 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx @@ -7,6 +7,7 @@ import { latestGameStatesAtom, } from "../../states/watch"; import type { PlayerProfile } from "../../types/PlayerProfile"; +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import FoldableBorderedContainerWithCaption from "../FoldableBorderedContainerWithCaption"; import CodeBlock from "../Gaming/CodeBlock"; import LeftTime from "../Gaming/LeftTime"; @@ -24,6 +25,7 @@ type Props = { playerProfileB: PlayerProfile | null; problemTitle: string; problemDescription: string; + problemLanguage: SupportedLanguage; sampleCode: string; }; @@ -33,6 +35,7 @@ export default function GolfWatchAppGaming1v1({ playerProfileB, problemTitle, problemDescription, + problemLanguage, sampleCode, }: Props) { const gameStateKind = useAtomValue(gameStateKindAtom); @@ -50,8 +53,8 @@ export default function GolfWatchAppGaming1v1({ const scoreB = stateB?.score ?? null; const statusB = stateB?.status ?? "none"; - const codeSizeA = calcCodeSize(codeA); - const codeSizeB = calcCodeSize(codeB); + const codeSizeA = calcCodeSize(codeA, problemLanguage); + const codeSizeB = calcCodeSize(codeB, problemLanguage); const gameResultKind = checkGameResultKind(gameStateKind, stateA, stateB); @@ -125,15 +128,16 @@ export default function GolfWatchAppGaming1v1({ - + - + } @@ -142,7 +146,7 @@ export default function GolfWatchAppGaming1v1({ - + diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx index b1d6520..22c6df2 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx @@ -1,5 +1,6 @@ import { useAtomValue } from "jotai"; import { gamingLeftTimeSecondsAtom } from "../../states/watch"; +import type { SupportedLanguage } from "../../types/SupportedLanguage"; import LeftTime from "../Gaming/LeftTime"; import ProblemColumn from "../Gaming/ProblemColumn"; import RankingTable from "../Gaming/RankingTable"; @@ -10,6 +11,7 @@ type Props = { gameDisplayName: string; problemTitle: string; problemDescription: string; + problemLanguage: SupportedLanguage; sampleCode: string; }; @@ -17,6 +19,7 @@ export default function GolfWatchAppGamingMultiplayer({ gameDisplayName, problemTitle, problemDescription, + problemLanguage, sampleCode, }: Props) { const leftTimeSeconds = useAtomValue(gamingLeftTimeSecondsAtom)!; @@ -35,10 +38,11 @@ export default function GolfWatchAppGamingMultiplayer({ - + -- cgit v1.2.3-70-g09d2