Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { englishSimulationErrorTexts } from "../store/simulationErrorTexts";
import type { TutorialStageId } from "../tutorial/stages";

const bitWidths = (widths: readonly number[]) => `${widths.join("/")} bit`;
const listOf = (names: readonly string[]) =>
Expand All @@ -8,6 +9,32 @@ const listOf = (names: readonly string[]) =>
const themOf = (names: readonly string[]) =>
names.length === 1 ? "it" : "them";

type StageTexts = { title: string; goal: string; steps: readonly string[] };

const stageTexts: Record<TutorialStageId, StageTexts> = {
and: {
title: "Both switches",
goal: "Make the lamp Out light up only when both switches A and B are ON. The stage is cleared when the circuit works as in the table below.",
steps: [
"Pick a part in the Parts list and drag it onto the editor on the right.",
"The small squares on the edges of a part are its pins. A pin on the left side is an input, which receives ON or OFF, and a pin on the right side is an output, which sends ON or OFF. Drag between an output pin and an input pin to connect them with a wire.",
"Once Out and every input pin of the parts you placed are connected, the play button at the bottom right can be pressed. It cannot be pressed while a part has a free input pin.",
"After pressing it, click the switches A and B to turn them ON and OFF, and watch the lamp Out. To fix the circuit, the pencil button in the same place takes you back to editing.",
"When it works as in the table, press Check.",
],
},
"a-only": {
title: "Only switch A",
goal: "Make the lamp Out light up only when switch A is ON and B is OFF. This time, one part alone is not enough.",
steps: [],
},
xor: {
title: "Only one switch",
goal: 'Make the lamp Out light up when exactly one of the switches A and B is ON. It does not light up when both are ON. "Only switch A" is ready to use as a part.',
steps: [],
},
};

export const en = {
languageName: "English",
common: {
Expand Down Expand Up @@ -107,6 +134,7 @@ export const en = {
stages: "Stages",
parts: "Parts",
goalHeading: "Goal",
stepsHeading: "Steps",
check: "Check",
passed: "Cleared! The circuit works for every combination of the inputs.",
next: "Next stage",
Expand All @@ -129,20 +157,7 @@ export const en = {
confirm: "Reset",
},
resetStageFailed: "Could not reset the stage.",
stageTexts: {
and: {
title: "Both switches",
goal: "Make the lamp Out light up only when both switches A and B are ON. Drag parts from the Parts list onto the editor, and drag from pin to pin to connect them. The play button at the bottom right lets you try the switches. When it works, press Check.",
},
"a-only": {
title: "Only switch A",
goal: "Make the lamp Out light up only when switch A is ON and B is OFF. This time, one part alone is not enough.",
},
xor: {
title: "Only one switch",
goal: 'Make the lamp Out light up when exactly one of the switches A and B is ON. It does not light up when both are ON. "Only switch A" is ready to use as a part.',
},
},
stageTexts,
},
componentProperties: {
title: (componentName: string) => `${componentName} Properties`,
Expand Down
12 changes: 11 additions & 1 deletion src/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const ja: Messages = {
stages: "課題の一覧",
parts: "部品",
goalHeading: "目標",
stepsHeading: "手順",
check: "確かめる",
passed: "クリア!どの入力の組み合わせでも正しく動きます。",
next: "次の課題へ",
Expand All @@ -122,15 +123,24 @@ export const ja: Messages = {
stageTexts: {
and: {
title: "両方のスイッチ",
goal: "スイッチ A と B が両方 ON のときだけ、ランプ Out がつくようにしましょう。「部品」の一覧から部品をエディタにドラッグして置き、ピンからピンへドラッグしてつなぎます。右下の再生ボタンで、スイッチを切り替えて試せます。できたら「確かめる」を押してください。",
goal: "スイッチ A と B が両方 ON のときだけ、ランプ Out がつくようにしましょう。下の表のとおりに動けばクリアです。",
steps: [
"「部品」の一覧から部品を選び、右のエディタにドラッグして置きます。",
"部品の端にある小さな四角を「ピン」といいます。左側のピンは ON か OFF を受け取る「入力」、右側のピンは ON か OFF を送り出す「出力」です。出力のピンと入力のピンのあいだをドラッグして、線でつなぎます。",
"Out と、置いた部品の入力のピンがすべてつながると、右下の再生ボタンが押せるようになります。入力のピンが空いている部品が残っていると押せません。",
"再生ボタンを押したら、スイッチ A と B をクリックして ON と OFF を切り替え、ランプ Out を見ます。回路を直すときは、同じ場所の鉛筆のボタンで編集に戻ります。",
"表のとおりに動いたら、「確かめる」を押します。",
],
},
"a-only": {
title: "A だけのスイッチ",
goal: "スイッチ A が ON で、B が OFF のときだけ、ランプ Out がつくようにしましょう。今度は、部品を1つ置くだけではできません。",
steps: [],
},
xor: {
title: "片方だけのスイッチ",
goal: "スイッチ A と B のどちらか片方だけが ON のときに、ランプ Out がつくようにしましょう。両方 ON のときはつきません。「A だけのスイッチ」を部品として使えます。",
steps: [],
},
},
},
Expand Down
193 changes: 108 additions & 85 deletions src/pages/tutorial/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function StageView({ stage }: { stage: TutorialStage }) {
const nextStage = tutorialStages[stageIndex + 1];
const titleOf: StageTitleOf = (id) => texts.stageTexts[id].title;
const goalTable = truthTableOfCheck(stage.check);
const stageTexts = texts.stageTexts[stage.id];

const [store, setStore] = useState(() =>
getTutorialStageStore(stage, titleOf),
Expand Down Expand Up @@ -160,92 +161,114 @@ function StageView({ stage }: { stage: TutorialStage }) {
minHeight: 0,
}}
>
<Stack spacing={2} sx={{ p: 2, overflowY: "auto" }}>
<Link
component={RouterLink}
to="/tutorial"
underline="hover"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
<ArrowBack fontSize="small" />
{texts.stages}
</Link>
<div>
<Typography color="textSecondary" variant="body2">
{texts.stageNumber(stageIndex + 1)}
</Typography>
<Typography variant="h2" typography="h5" sx={{ fontWeight: "bold" }}>
{texts.stageTexts[stage.id].title}
</Typography>
</div>
<div>
<SectionHeading>{texts.goalHeading}</SectionHeading>
<Typography>{texts.stageTexts[stage.id].goal}</Typography>
{goalTable && (
<Box sx={{ mt: 1 }}>
<TruthTableView table={goalTable} />
</Box>
)}
</div>
<Button
variant="contained"
onClick={check}
sx={{ background: theme.colors.tutorial }}
>
{texts.check}
</Button>
{result?.type === "passed" && (
<>
<Alert severity="success">{texts.passed}</Alert>
<Button
variant="outlined"
component={RouterLink}
to={nextStage ? `/tutorial/${nextStage.id}` : "/tutorial"}
<Box sx={{ display: "flex", flexDirection: "column", minHeight: 0 }}>
<Stack spacing={2} sx={{ p: 2, overflowY: "auto", flexGrow: 1 }}>
<Link
component={RouterLink}
to="/tutorial"
underline="hover"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
<ArrowBack fontSize="small" />
{texts.stages}
</Link>
<div>
<Typography color="textSecondary" variant="body2">
{texts.stageNumber(stageIndex + 1)}
</Typography>
<Typography
variant="h2"
typography="h5"
sx={{ fontWeight: "bold" }}
>
{nextStage ? texts.next : texts.backToStages}
</Button>
</>
)}
{result && result.type !== "passed" && (
<Alert severity="error">
{describeFailure(result, store, messages)}
</Alert>
)}
<div>
<SectionHeading>{messages.parts.ofStage}</SectionHeading>
<Stack spacing={1.5}>
{stage.parts.map((partId) => (
<PartDescription
key={partId}
component={
nullthrows(definitionByComponentId.get(partId)).component
}
/>
))}
{stage.givenParts.map((id) => (
<PartDescriptionView
key={id}
name={titleOf(id)}
summary={null}
table={truthTableOfCheck(
nullthrows(findTutorialStage(id)).check,
)}
/>
))}
</Stack>
</div>
<Box sx={{ flexGrow: 1 }} />
{hasResetFailed && (
<Alert severity="error">{texts.resetStageFailed}</Alert>
)}
<Button
variant="text"
color="error"
onClick={() => setIsConfirmingReset(true)}
>
{texts.resetStage}
</Button>
</Stack>
{stageTexts.title}
</Typography>
</div>
<div>
<SectionHeading>{texts.goalHeading}</SectionHeading>
<Typography>{stageTexts.goal}</Typography>
{goalTable && (
<Box sx={{ mt: 1 }}>
<TruthTableView table={goalTable} />
</Box>
)}
</div>
{stageTexts.steps.length > 0 && (
<div>
<SectionHeading>{texts.stepsHeading}</SectionHeading>
<Box component="ol" sx={{ m: 0, pl: 3 }}>
{stageTexts.steps.map((step) => (
<Typography key={step} component="li" sx={{ mb: 0.5 }}>
{step}
</Typography>
))}
</Box>
</div>
)}
<div>
<SectionHeading>{messages.parts.ofStage}</SectionHeading>
<Stack spacing={1.5}>
{stage.parts.map((partId) => (
<PartDescription
key={partId}
component={
nullthrows(definitionByComponentId.get(partId)).component
}
/>
))}
{stage.givenParts.map((id) => (
<PartDescriptionView
key={id}
name={titleOf(id)}
summary={null}
table={truthTableOfCheck(
nullthrows(findTutorialStage(id)).check,
)}
/>
))}
</Stack>
</div>
<Box sx={{ flexGrow: 1 }} />
{hasResetFailed && (
<Alert severity="error">{texts.resetStageFailed}</Alert>
)}
<Button
variant="text"
color="error"
onClick={() => setIsConfirmingReset(true)}
>
{texts.resetStage}
</Button>
</Stack>
<Divider />
{/* Outside the scrolling, so that Check and its result stay in view */}
<Stack spacing={1} sx={{ p: 2 }}>
<Button
variant="contained"
onClick={check}
sx={{ background: theme.colors.tutorial }}
>
{texts.check}
</Button>
{result?.type === "passed" && (
<>
<Alert severity="success">{texts.passed}</Alert>
<Button
variant="outlined"
component={RouterLink}
to={nextStage ? `/tutorial/${nextStage.id}` : "/tutorial"}
>
{nextStage ? texts.next : texts.backToStages}
</Button>
</>
)}
{result && result.type !== "passed" && (
<Alert severity="error">
{describeFailure(result, store, messages)}
</Alert>
)}
</Stack>
</Box>
<Divider orientation="vertical" />
<StoreScope store={store}>
<Box sx={{ overflowY: "auto" }}>
Expand Down
Loading