From d09dc7fe6e1108ddb4af6842bddf70670a1669fa Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 23:14:25 +0900 Subject: [PATCH 1/6] feat(tutorial): show the table a stage asks for under its goal The part tables now come from one TruthTableView, shared with the stage page. Co-Authored-By: Claude Opus 5.5 --- src/components/PartDescription.tsx | 61 ++-------------------------- src/components/TruthTable.tsx | 64 ++++++++++++++++++++++++++++++ src/i18n/en.ts | 1 + src/i18n/ja.ts | 1 + src/pages/tutorial/stage.tsx | 16 +++++++- src/tutorial/check.test.ts | 38 +++++++++++++++++- src/tutorial/check.ts | 23 +++++++++++ 7 files changed, 144 insertions(+), 60 deletions(-) create mode 100644 src/components/TruthTable.tsx diff --git a/src/components/PartDescription.tsx b/src/components/PartDescription.tsx index 3f3e2c4..4767b94 100644 --- a/src/components/PartDescription.tsx +++ b/src/components/PartDescription.tsx @@ -1,10 +1,9 @@ import { Box, Typography } from "@mui/material"; -import { bitLabel } from "../common/bitLabel"; import { type Messages, useMessages } from "../i18n"; import type { CCComponent } from "../store/component"; import { definitionByComponentId } from "../store/intrinsics/definitions"; import { truthTableOf } from "../store/intrinsics/truthTable"; -import { theme } from "../style"; +import { TruthTableView } from "./TruthTable"; type Summaries = Messages["parts"]["summaries"]; @@ -23,68 +22,14 @@ export function PartDescription({ component }: { component: CCComponent }) { const summary = partSummary(messages, component); const definition = definitionByComponentId.get(component.id); const table = definition && truthTableOf(definition); - const columns = table - ? [ - ...table.inputs.map((name) => ({ key: `in-${name}`, name })), - ...table.outputs.map((name) => ({ key: `out-${name}`, name })), - ] - : []; - const cellSx = (column: number) => - ({ - px: 1, - py: 0.25, - textAlign: "center", - ...(table && - table.inputs.length > 0 && - column === table.inputs.length && { - borderLeft: 1, - borderColor: "divider", - }), - }) as const; return (
{component.name} {summary && {summary}} {table && ( - - - - {columns.map(({ key, name }, i) => ( - - {name} - - ))} - - - - {table.rows.map((row) => ( - - {[...row.inputs, ...row.outputs].map((value, i) => ( - - {bitLabel(value)} - - ))} - - ))} - + + )}
diff --git a/src/components/TruthTable.tsx b/src/components/TruthTable.tsx new file mode 100644 index 0000000..0cf74a8 --- /dev/null +++ b/src/components/TruthTable.tsx @@ -0,0 +1,64 @@ +import { Box } from "@mui/material"; +import { bitLabel } from "../common/bitLabel"; +import type { TruthTable } from "../store/intrinsics/truthTable"; +import { theme } from "../style"; + +export function TruthTableView({ table }: { table: TruthTable }) { + const columns = [ + ...table.inputs.map((name) => ({ key: `in-${name}`, name })), + ...table.outputs.map((name) => ({ key: `out-${name}`, name })), + ]; + const cellSx = (column: number) => + ({ + px: 1, + py: 0.25, + textAlign: "center", + ...(table.inputs.length > 0 && + column === table.inputs.length && { + borderLeft: 1, + borderColor: "divider", + }), + }) as const; + + return ( + + + + {columns.map(({ key, name }, i) => ( + + {name} + + ))} + + + + {table.rows.map((row) => ( + + {[...row.inputs, ...row.outputs].map((value, i) => ( + + {bitLabel(value)} + + ))} + + ))} + + + ); +} diff --git a/src/i18n/en.ts b/src/i18n/en.ts index badfef4..3ab5e77 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -106,6 +106,7 @@ export const en = { startOverFailed: "Could not start the tutorial over.", stages: "Stages", parts: "Parts", + goalTable: "The stage is cleared when the circuit works like this", check: "Check", passed: "Cleared! The circuit works for every combination of the inputs.", next: "Next stage", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 2cdf418..630d977 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -101,6 +101,7 @@ export const ja: Messages = { startOverFailed: "チュートリアルをやり直せませんでした。", stages: "課題の一覧", parts: "部品", + goalTable: "回路がこのように動けばクリアです", check: "確かめる", passed: "クリア!どの入力の組み合わせでも正しく動きます。", next: "次の課題へ", diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 25cb779..e562a59 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -19,13 +19,18 @@ import { import { valueLabel } from "../../common/bitLabel"; import { ConfirmDialog } from "../../components/ConfirmDialog"; import { PartDescription } from "../../components/PartDescription"; +import { TruthTableView } from "../../components/TruthTable"; import { type Messages, useMessages } from "../../i18n"; import type CCStore from "../../store"; import { definitionByComponentId } from "../../store/intrinsics/definitions"; import { SimulationNodeError } from "../../store/netlist"; import { StoreScope } from "../../store/react"; import { theme } from "../../style"; -import { type CheckResult, checkCombinational } from "../../tutorial/check"; +import { + type CheckResult, + checkCombinational, + truthTableOfCheck, +} from "../../tutorial/check"; import { markStageCleared } from "../../tutorial/progress"; import { getTutorialStageStore, @@ -79,6 +84,7 @@ function StageView({ stage }: { stage: TutorialStage }) { const stageIndex = tutorialStages.indexOf(stage); const nextStage = tutorialStages[stageIndex + 1]; const componentName = texts.stageTexts[stage.id].title; + const goalTable = truthTableOfCheck(stage.check); const [store, setStore] = useState(() => getTutorialStageStore(stage, componentName), @@ -155,6 +161,14 @@ function StageView({ stage }: { stage: TutorialStage }) { {texts.stageTexts[stage.id].goal} + {goalTable && ( +
+ + {texts.goalTable} + + +
+ )}