diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 8d7d181..ebcc296 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -37,14 +37,16 @@ const stageTexts: Record = { goal: [ "Make the lamp {Out} turn [ON] only when switch {A} is [ON] and {B} is [OFF]. This time, one component alone is not enough.", ], - steps: [], + steps: ["Turn {B} over with a {Not}, then connect it and {A} to an {And}."], }, xor: { title: "ON when just one is ON", goal: [ 'Make the lamp {Out} turn [ON] when exactly one of the switches {A} and {B} is [ON]. It stays [OFF] when both are [ON]. "{ON when only A is ON}" is ready to use as a component.', ], - steps: [], + steps: [ + 'Place two "{ON when only A is ON}", and connect {A} and {B} to one as they are, and to the other the other way round. Join their two {Out}s with an {Or} and connect it to the lamp {Out}.', + ], }, "half-adder": { title: "Adding one digit", @@ -52,25 +54,27 @@ const stageTexts: Record = { "From here on, think of [ON] as [1] and [OFF] as [0], and the tables of the stages' circuits write them that way too. Then {A} + {B} is 0, 1 or 2. Binary writes numbers with only 0 and 1: just as 9 + 1 carries over and becomes 10 in everyday numbers, 1 + 1 carries over and becomes 10 in binary. So 0, 1 and 2 are [00], [01] and [10] in two digits. A digit of a binary number is called a bit.", "Output the left digit (the twos digit) to {C} and the right digit (the ones digit) to {S}. {C} is called the carry and {S} the sum, and this circuit is called a half adder.", ], - steps: [], + steps: ["{C} can be made with an {And}, and {S} with an {Xor}."], }, "full-adder": { title: "Adding with a carry", goal: [ - 'Output {A} + {B} + {Cin} as a two-digit binary number to {C} and {S}. {Cin} is the carry coming up from the next lower digit. The answer is 0 to 3, and 3 is [11] in binary. "{Adding one digit}" is ready to use as a component: add {A} and {B} with one, then add {Cin} to its {S} with another. This circuit is called a full adder.', + 'Output {A} + {B} + {Cin} as a two-digit binary number to {C} and {S}. {Cin} is the carry coming up from the next lower digit. The answer is 0 to 3, and 3 is [11] in binary. "{Adding one digit}" is ready to use as a component. This circuit is called a full adder.', + ], + steps: [ + 'Add {A} and {B} with one "{Adding one digit}", then add {Cin} to its {S} with another and output that {S} to {S}. Join the two {C}s with an {Or} and output it to {C}.', ], - steps: [], }, "four-bit-adder": { title: "Adding four digits", goal: [ - "{A} and {B} are four-digit binary numbers. Output {A} + {B} in four digits to {S}, and its fifth digit, the sixteens digit, to {C}: {C} is [1] when {A} + {B} is 16 or more. The table shows some examples.", + "{A} and {B} are four-digit binary numbers. Output {A} + {B} in four digits to {S}, and its fifth digit, the sixteens digit, to {C}: {C} is [1] when {A} + {B} is 16 or more.", + "While playing, click a digit of {A} or {B} to switch it between [0] and [1]. The sum {S} is shown as one character on the {Display} at the top right. The {7seg} before it turns the binary number into the shape of a numeral. To write 10 to 15 with one character, A (10), b (11), C (12), d (13), E (14) and F (15) are used. This way of writing is called hexadecimal. The table below shows some examples of {A} + {B}.", ], steps: [ 'Place four "{Adding with a carry}". From the top, the pins on the right of {Decompose} and on the left of {Aggregate} are the eights, fours, twos and ones digits.', "For each digit, connect that digit's pin on the upper {Decompose}, which {A} goes into, and on the lower one, which {B} goes into, to the {A} and {B} of one \"{Adding with a carry}\". Connect the {S} of that adder to the same digit's pin of {Aggregate}.", "Connect the {C} of each digit's adder to the {Cin} of the adder one digit up. The ones digit's adder gets {False} on its {Cin}, and the {C} of the eights digit's adder goes to the output {C} on the right.", - "While playing, click a digit of {A} or {B} to switch it between [0] and [1]. The sum {S} is shown as one character on the {Display} at the top right. The {7seg} before it turns the binary number into the shape of a numeral. To write 10 to 15 with one character, A (10), b (11), C (12), d (13), E (14) and F (15) are used. This way of writing is called hexadecimal.", ], }, counter: { @@ -253,6 +257,8 @@ export const en = { stages: "Stages", goalHeading: "Goal", stepsHeading: "Steps", + stepsClosed: + "Open this when you are stuck. It tells how to build the circuit.", digitsLegend: "The tables of the stages' circuits write ON as 1 and OFF as 0.", check: "Check", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 1babba6..d08391f 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -135,6 +135,8 @@ export const ja: Messages = { stages: "課題の一覧", goalHeading: "目標", stepsHeading: "手順", + stepsClosed: + "考えてもわからないときに開いてください。作り方が書いてあります。", digitsLegend: "課題の回路の表では、ON を 1、OFF を 0 と書いています。", check: "確かめる", checking: "確かめています…", @@ -181,14 +183,18 @@ export const ja: Messages = { goal: [ "スイッチ {A} が [ON] で、{B} が [OFF] のときだけ、ランプ {Out} が [ON] になるようにしましょう。今度は、コンポーネントを1つ置くだけではできません。", ], - steps: [], + steps: [ + "{B} を {Not} で反対にしてから、{A} と一緒に {And} につなぎます。", + ], }, xor: { title: "片方だけ ON で ON", goal: [ "スイッチ {A} と {B} のどちらか片方だけが [ON] のときに、ランプ {Out} が [ON] になるようにしましょう。両方 [ON] のときは [OFF] です。「{A だけ ON で ON}」をコンポーネントとして使えます。", ], - steps: [], + steps: [ + "「{A だけ ON で ON}」を2つ置き、{A} と {B} を、1つにはそのまま、もう1つには入れ替えてつなぎます。2つの {Out} を {Or} でまとめて、ランプ {Out} につなぎます。", + ], }, "half-adder": { title: "1桁の足し算", @@ -196,25 +202,27 @@ export const ja: Messages = { "ここからは [ON] を [1]、[OFF] を [0] と考え、課題の回路の表もそう書きます。すると、{A}+{B} は 0、1、2 のどれかです。2進数では、0 と 1 だけで数を書きます。ふだんの数で 9+1 が繰り上がって 10 になるように、2進数では 1+1 が繰り上がって 10 になります。そのため、0、1、2 は2桁で [00]、[01]、[10] です。2進数の1桁を「ビット」といいます。", "左の桁(2の位)を {C} に、右の桁(1の位)を {S} に出しましょう。{C} を「桁上がり」、{S} を「和」といい、この回路を「半加算器」といいます。", ], - steps: [], + steps: ["{C} は {And} で、{S} は {Xor} で作れます。"], }, "full-adder": { title: "桁上がりつきの足し算", goal: [ - "{A}+{B}+{Cin} の答えを、2桁の2進数で {C} と {S} に出しましょう。{Cin} は、下の桁から来る桁上がりです。答えは 0 から 3 で、3 は2進数で [11] です。「{1桁の足し算}」をコンポーネントとして使えます。1つで {A} と {B} を足し、もう1つでその {S} と {Cin} を足します。この回路を「全加算器」といいます。", + "{A}+{B}+{Cin} の答えを、2桁の2進数で {C} と {S} に出しましょう。{Cin} は、下の桁から来る桁上がりです。答えは 0 から 3 で、3 は2進数で [11] です。「{1桁の足し算}」をコンポーネントとして使えます。この回路を「全加算器」といいます。", + ], + steps: [ + "「{1桁の足し算}」の1つで {A} と {B} を足し、もう1つでその {S} と {Cin} を足して、その {S} を {S} に出します。2つの {C} は {Or} でまとめて、{C} に出します。", ], - steps: [], }, "four-bit-adder": { title: "4桁の足し算", goal: [ - "{A} と {B} は4桁の2進数です。{A}+{B} を4桁で {S} に、5桁目(16の位)を {C} に出しましょう。{A}+{B} が 16 以上なら、{C} は [1] です。表はその例です。", + "{A} と {B} は4桁の2進数です。{A}+{B} を4桁で {S} に、5桁目(16の位)を {C} に出しましょう。{A}+{B} が 16 以上なら、{C} は [1] です。", + "再生中は、{A} と {B} の桁をクリックして [0] と [1] を切り替えられます。答えの {S} は、右上の {Display} に1文字で表示されます。その手前の {7seg} が、2進数を数字の形に変えています。10 から 15 は1文字で書くために、A(10)、b(11)、C(12)、d(13)、E(14)、F(15)を使います。この書き方を16進数といいます。下の表は、{A}+{B} の例です。", ], steps: [ "「{桁上がりつきの足し算}」を4つ置きます。{Decompose} の右側のピンと {Aggregate} の左側のピンは、どちらも上から8の位・4の位・2の位・1の位です。", "桁ごとに、{A} につないだ上の {Decompose} と、{B} につないだ下の {Decompose} から、その桁のピンを1つの「{桁上がりつきの足し算}」の {A} と {B} につなぎます。その足し算の {S} は、{Aggregate} の同じ桁のピンにつなぎます。", "それぞれの桁の足し算の {C} を、1つ上の桁の足し算の {Cin} につなぎます。1の位の足し算の {Cin} には {False} を、8の位の足し算の {C} は右の出力 {C} につなぎます。", - "再生中は、{A} と {B} の桁をクリックして [0] と [1] を切り替えられます。答えの {S} は、右上の {Display} に1文字で表示されます。その手前の {7seg} が、2進数を数字の形に変えています。10 から 15 は1文字で書くために、A(10)、b(11)、C(12)、d(13)、E(14)、F(15)を使います。この書き方を16進数といいます。", ], }, counter: { diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 8b7ad9e..fb9711c 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -1,8 +1,10 @@ -import { ArrowBack } from "@mui/icons-material"; +import { ArrowBack, ExpandMore } from "@mui/icons-material"; import { Alert, Box, Button, + ButtonBase, + Collapse, Divider, Link, Stack, @@ -13,6 +15,7 @@ import { type ReactNode, useCallback, useEffect, + useId, useMemo, useRef, useState, @@ -81,6 +84,71 @@ function SectionHeading({ children }: { children: ReactNode }) { ); } +function StepList({ steps }: { steps: readonly string[] }) { + return ( + + {steps.map((step) => ( + + + + ))} + + ); +} + +/** Steps that are hints, kept closed until the player asks for them */ +function HintSteps({ steps }: { steps: readonly string[] }) { + const texts = useMessages().tutorial; + const [isOpen, setIsOpen] = useState(false); + const stepsId = useId(); + const noteId = useId(); + const toggle = () => setIsOpen((open) => !open); + return ( +
+ + + + {texts.stepsHeading} + + + {!isOpen && ( + // Also opens the steps, as the note is where the eye goes; the button + // above reads it out + + {texts.stepsClosed} + + )} + + + +
+ ); +} + function CheckFailure({ result, onReset, @@ -272,18 +340,17 @@ function StageView({ stage }: { stage: TutorialStage }) { )} - {stageTexts.steps.length > 0 && ( -
- {texts.stepsHeading} - - {stageTexts.steps.map((step) => ( - - - - ))} - -
- )} + {stageTexts.steps.length > 0 && + // The first stage's steps teach the editor, not the circuit, so + // they are no hints to hide + (stageIndex === 0 ? ( +
+ {texts.stepsHeading} + +
+ ) : ( + + ))}
{messages.parts.ofStage}