diff --git a/src/common/appName.ts b/src/common/appName.ts new file mode 100644 index 0000000..403488f --- /dev/null +++ b/src/common/appName.ts @@ -0,0 +1 @@ +export const appName = "CreateCPU"; diff --git a/src/components/GlobalHeader.tsx b/src/components/GlobalHeader.tsx index 1f22926..d1dbd0e 100644 --- a/src/components/GlobalHeader.tsx +++ b/src/components/GlobalHeader.tsx @@ -8,6 +8,7 @@ import { } from "@mui/material"; import type { CSSProperties } from "react"; import { Link as RouterLink, useLocation } from "react-router"; +import { appName } from "../common/appName"; import { type Language, languages, @@ -55,7 +56,7 @@ export default function GlobalHeader({ style }: GlobalHeaderProps) { }} > - CreateCPU + {appName} {mode && ( = { and: { - title: "Both switches", + title: "ON when both are ON", goal: [ "Make the lamp {Out} turn [ON] only when both switches {A} and {B} are [ON]. The stage is cleared when the circuit works as in the table below.", ], @@ -33,16 +33,16 @@ const stageTexts: Record = { ], }, "a-only": { - title: "Only switch A", + title: "ON when only A is ON", goal: [ "Make the lamp {Out} turn [ON] only when switch {A} is [ON] and {B} is [OFF]. This time, one part alone is not enough.", ], steps: [], }, xor: { - title: "Only one switch", + 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]. "{Only switch A}" is ready to use as a part.', + '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 part.', ], steps: [], }, @@ -87,7 +87,7 @@ const stageTexts: Record = { ], }, "decimal-digit": { - title: "One decimal digit", + title: "0–9 counter", goal: [ "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal.", "Make {Count} go up by 1 only at the time steps when {Up} is [ON], and go back to [0000] after [1001]. [1001] is 9, 8 plus 1. At a time step when {Count} is [1001] and {Up} is [ON], make {Carry} turn [ON]: it tells the digit above to go up.", @@ -109,8 +109,8 @@ const stageTexts: Record = { " keeps {Start} [ON] until 59:59 has gone back to 00:00, then turns it [OFF] for two time steps to see that the stopwatch stops, and [ON] again to see that it goes on.", ], steps: [ - 'Place two "{One base-6 digit}" and two "{One decimal digit}". "{One base-6 digit}" is built like "{One decimal digit}", but counts 0 to 5 and carries over after 5, as decimal does after 9.', - 'Give each of the four parts one of {M10}, {M1}, {S10} and {S1}: "{One base-6 digit}" for {M10} and {S10}, and "{One decimal digit}" for {M1} and {S1}. Connect the {Count} of each to the output on the right named after its digit, and to the {7seg} of that digit. The {7seg}s are, from the top, for {M10}, {M1}, {S10} and {S1}.', + 'Place two "{0–5 counter}" and two "{0–9 counter}". "{0–5 counter}" is built like "{0–9 counter}", but goes back to 0 and carries over after 5 instead of 9.', + 'Give each of the four parts one of {M10}, {M1}, {S10} and {S1}: "{0–5 counter}" for {M10} and {S10}, and "{0–9 counter}" for {M1} and {S1}. Connect the {Count} of each to the output on the right named after its digit, and to the {7seg} of that digit. The {7seg}s are, from the top, for {M10}, {M1}, {S10} and {S1}.', "Connect {Start} to {Up} of the part connected to {S1}. Then connect {Carry} of the part for {S1} to {Up} of the part for {S10}, {Carry} for {S10} to {Up} for {M1}, and {Carry} for {M1} to {Up} for {M10}. A digit then goes on only when the digit one lower goes back to 0.", "Press the play button . If {Start} is [OFF] at the first time step, click it to turn it [ON]. Press , and the {Display} goes on like a clock, one time step a second. To see what comes after 59:59, stop , click the number at the bottom, enter 3600 and press the key. It goes to that time step at once and shows 59:59, and the right arrow shows 00:00.", ], @@ -165,9 +165,16 @@ export const en = { }, }, start: { + intro: (appName: string) => [ + "The brain of a computer or a smartphone, the CPU, is built from combinations of simple logic elements.", + `In ${appName}, you place small circuits on the screen, connect them and run them to learn about logic circuits.`, + "Try things out like a puzzle, and take a look inside a computer.", + ], title: "What would you like to do?", - tutorial: - "Build logic circuits step by step, starting from a pair of switches.", + tutorialAudience: "New here? Start here.", + tutorial: (stageCount: number) => + `Solve ${stageCount} stages in turn, building circuits as you go, and finish a stopwatch at the end.`, + freeAudience: "For those who know logic circuits", free: "Build any circuit you like.", }, home: { @@ -225,9 +232,13 @@ export const en = { timeStep: "Time step", }, tutorial: { - lead: "Going from the top is recommended, but you can start from any stage.", + lead: [ + "Starting at the first stage, build circuit after circuit, and finish a stopwatch in the last stage.", + "When a stage needs a circuit from an earlier one, it hands it to you as a finished part, so you can start from any stage.", + ], stageNumber: (number: number) => `Stage ${number}`, cleared: "Cleared", + upNext: "Continue here", startOver: "Start over from the beginning", startOverDialog: { title: "Start the tutorial over?", @@ -277,7 +288,7 @@ export const en = { }, resetStageFailed: "Could not reset the stage.", stageTexts, - partTitles: { "senary-digit": "One base-6 digit" } satisfies Record< + partTitles: { "senary-digit": "0–5 counter" } satisfies Record< TutorialPartId, string >, diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index f177ca7..9fe1461 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -47,8 +47,16 @@ export const ja: Messages = { }, }, start: { + intro: (appName) => [ + "パソコンやスマホの頭脳「CPU」は、単純な論理素子の組み合わせからできています。", + `${appName} では、画面上で小さな回路を並べてつなぎ、動かしながら論理回路について学べます。`, + "パズル感覚で試行錯誤しながら、コンピュータの中身をのぞいてみませんか?", + ], title: "何をしますか?", - tutorial: "2つのスイッチから始めて、課題に沿って論理回路を組み立てます。", + tutorialAudience: "はじめての方はこちら", + tutorial: (stageCount) => + `${stageCount}つの課題を順に解きながら回路を作り、最後にストップウォッチを完成させます。`, + freeAudience: "論理回路を知っている方向け", free: "好きな回路を自由に作ります。", }, home: { @@ -106,9 +114,13 @@ export const ja: Messages = { timeStep: "ステップ", }, tutorial: { - lead: "上から順に進めるのがおすすめですが、どの課題からでも始められます。", + lead: [ + "最初の課題から順に回路を組み立てていき、最後にストップウォッチを完成させます。", + "前の課題で作った回路が必要な課題では、その回路が完成した部品として渡されるので、どの課題からでも始められます。", + ], stageNumber: (number) => `課題 ${number}`, cleared: "クリア", + upNext: "続きはここから", startOver: "最初からやり直す", startOverDialog: { title: "チュートリアルを最初からやり直しますか?", @@ -146,10 +158,10 @@ export const ja: Messages = { confirm: "やり直す", }, resetStageFailed: "課題をやり直せませんでした。", - partTitles: { "senary-digit": "6進の1桁" }, + partTitles: { "senary-digit": "0〜5 のカウンタ" }, stageTexts: { and: { - title: "両方のスイッチ", + title: "両方 ON で ON", goal: [ "スイッチ {A} と {B} が両方 [ON] のときだけ、ランプ {Out} が [ON] になるようにしましょう。下の表のとおりに動けばクリアです。", ], @@ -162,16 +174,16 @@ export const ja: Messages = { ], }, "a-only": { - title: "A だけのスイッチ", + title: "A だけ ON で ON", goal: [ "スイッチ {A} が [ON] で、{B} が [OFF] のときだけ、ランプ {Out} が [ON] になるようにしましょう。今度は、部品を1つ置くだけではできません。", ], steps: [], }, xor: { - title: "片方だけのスイッチ", + title: "片方だけ ON で ON", goal: [ - "スイッチ {A} と {B} のどちらか片方だけが [ON] のときに、ランプ {Out} が [ON] になるようにしましょう。両方 [ON] のときは [OFF] です。「{A だけのスイッチ}」を部品として使えます。", + "スイッチ {A} と {B} のどちらか片方だけが [ON] のときに、ランプ {Out} が [ON] になるようにしましょう。両方 [ON] のときは [OFF] です。「{A だけ ON で ON}」を部品として使えます。", ], steps: [], }, @@ -216,7 +228,7 @@ export const ja: Messages = { ], }, "decimal-digit": { - title: "10進の1桁", + title: "0〜9 のカウンタ", goal: [ "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。", "{Up} が [ON] のステップだけ {Count} が 1 増え、[1001] の次は [0000] に戻るようにしましょう。[1001] は、8 と 1 を足した 9 です。{Count} が [1001] で {Up} が [ON] のステップでは、{Carry} が [ON] になるようにします。{Carry} は、上の桁に桁上がりを知らせる合図です。", @@ -238,8 +250,8 @@ export const ja: Messages = { "は、{Start} を [ON] にしたまま、59:59 の次に 00:00 に戻るまで進めます。そのあと2ステップだけ {Start} を [OFF] にして止まるかを、また [ON] にしてまた進むかを調べます。", ], steps: [ - "「{6進の1桁}」を2つと、「{10進の1桁}」を2つ置きます。「{6進の1桁}」は「{10進の1桁}」と同じつくりで、0 から 5 を数え、5 の次で 0 に戻って上の桁が上がります。10進数が 9 の次で桁が上がるのと同じです。", - "置いた4つの部品を、{M10}・{M1}・{S10}・{S1} に1つずつ割り当てます。{M10} と {S10} には「{6進の1桁}」を、{M1} と {S1} には「{10進の1桁}」を使います。それぞれの {Count} を、割り当てた桁と同じ名前の右の出力と、その桁の {7seg} につなぎます。{7seg} は、上から {M10}・{M1}・{S10}・{S1} 用です。", + "「{0〜5 のカウンタ}」を2つと、「{0〜9 のカウンタ}」を2つ置きます。「{0〜5 のカウンタ}」は「{0〜9 のカウンタ}」と同じつくりで、9 の次ではなく 5 の次で 0 に戻り、上の桁に桁上がりを知らせます。", + "置いた4つの部品を、{M10}・{M1}・{S10}・{S1} に1つずつ割り当てます。{M10} と {S10} には「{0〜5 のカウンタ}」を、{M1} と {S1} には「{0〜9 のカウンタ}」を使います。それぞれの {Count} を、割り当てた桁と同じ名前の右の出力と、その桁の {7seg} につなぎます。{7seg} は、上から {M10}・{M1}・{S10}・{S1} 用です。", "{S1} につないだ部品の {Up} に {Start} をつなぎます。次に、{S1} の部品の {Carry} を {S10} の部品の {Up} に、{S10} の {Carry} を {M1} の {Up} に、{M1} の {Carry} を {M10} の {Up} につなぎます。こうすると、1つ下の桁が 0 に戻るときだけ、その上の桁が進みます。", "再生ボタンを押します。最初のステップで {Start} が [OFF] なら、クリックして [ON] にします。を押すと、1秒に1ステップずつ、{Display} が時計のように進みます。59:59 の次を見るには、を止めて下の数字をクリックし、3600 と入れてキーを押します。そのステップまで一度に進んで 59:59 になり、右の矢印を押すと 00:00 に戻ります。", ], diff --git a/src/pages/start/index.tsx b/src/pages/start/index.tsx index 45a4749..f97885d 100644 --- a/src/pages/start/index.tsx +++ b/src/pages/start/index.tsx @@ -1,28 +1,43 @@ import { Card, CardActionArea, Container, Typography } from "@mui/material"; import { Link } from "react-router"; +import { appName } from "../../common/appName"; import { useMessages } from "../../i18n"; import { theme } from "../../style"; +import { tutorialStages } from "../../tutorial/stages"; export default function StartPage() { const messages = useMessages(); const choices = [ { to: "/tutorial", + audience: messages.start.tutorialAudience, title: messages.header.modes.tutorial, - body: messages.start.tutorial, + body: messages.start.tutorial(tutorialStages.length), color: theme.colors.tutorial, + textColor: theme.colors.tutorial, }, { to: "/free", + audience: messages.start.freeAudience, title: messages.header.modes.free, body: messages.start.free, color: theme.colors.primary, + // The primary colour is too light for small text on white + textColor: "primary.dark", }, ]; return (
- + + {appName} + + {messages.start.intro(appName).map((sentence) => ( + + {sentence} + + ))} + {messages.start.title}
{choices.map((choice) => ( @@ -44,6 +59,12 @@ export default function StartPage() { to={choice.to} sx={{ p: 3, flexGrow: 1, alignSelf: "stretch" }} > + + {choice.audience} + {choice.title} diff --git a/src/pages/tutorial/StageNumber.tsx b/src/pages/tutorial/StageNumber.tsx new file mode 100644 index 0000000..7f3e66f --- /dev/null +++ b/src/pages/tutorial/StageNumber.tsx @@ -0,0 +1,41 @@ +import { Box } from "@mui/material"; +import { visuallyHiddenSx } from "../../components/visuallyHidden"; +import { useMessages } from "../../i18n"; +import { theme } from "../../style"; + +export function StageNumber({ number }: { number: number }) { + const messages = useMessages(); + return ( + <> + + {messages.tutorial.stageNumber(number)} + + + {/* Trimmed to the digits, which otherwise sit low in their line */} + + {number} + + + + ); +} diff --git a/src/pages/tutorial/StageText.tsx b/src/pages/tutorial/StageText.tsx index ae1cb4e..f935ceb 100644 --- a/src/pages/tutorial/StageText.tsx +++ b/src/pages/tutorial/StageText.tsx @@ -14,6 +14,7 @@ import { withLookSx, } from "../../components/controlLooks"; import { ValueView } from "../../components/ValueView"; +import { visuallyHiddenSx } from "../../components/visuallyHidden"; import { useMessages } from "../../i18n"; import { parseStageText, @@ -35,15 +36,6 @@ const inlineSx = { pointerEvents: "none", } as const; -const visuallyHiddenSx = { - position: "absolute", - width: "1px", - height: "1px", - overflow: "hidden", - clip: "rect(0 0 0 0)", - whiteSpace: "nowrap", -} as const; - const iconSx = { display: "inline-flex", verticalAlign: "-0.25em", diff --git a/src/pages/tutorial/index.tsx b/src/pages/tutorial/index.tsx index 5f75562..ede4126 100644 --- a/src/pages/tutorial/index.tsx +++ b/src/pages/tutorial/index.tsx @@ -1,4 +1,4 @@ -import { CheckCircle } from "@mui/icons-material"; +import { ArrowForward, CheckCircle } from "@mui/icons-material"; import { Alert, Box, @@ -8,19 +8,41 @@ import { Container, Typography, } from "@mui/material"; -import { useState } from "react"; +import { type ReactNode, useState } from "react"; import { Link } from "react-router"; import { ConfirmDialog } from "../../components/ConfirmDialog"; import { useMessages } from "../../i18n"; import { theme } from "../../style"; -import { readClearedStages } from "../../tutorial/progress"; +import { nextStageOf, readClearedStages } from "../../tutorial/progress"; import { resetTutorial } from "../../tutorial/stageStore"; import { tutorialStages } from "../../tutorial/stages"; +import { StageNumber } from "./StageNumber"; + +function StageStatus({ + icon, + label, + color, +}: { + icon: ReactNode; + label: string; + color: string; +}) { + return ( + + {icon} + {label} + + ); +} export default function TutorialPage() { const messages = useMessages(); const texts = messages.tutorial; const [clearedStages, setClearedStages] = useState(readClearedStages); + const nextStage = nextStageOf(clearedStages); const [isConfirming, setIsConfirming] = useState(false); const [hasFailed, setHasFailed] = useState(false); @@ -38,45 +60,77 @@ export default function TutorialPage() { return (
- + {/* Wide enough for the longest title on one line in three columns */} + {messages.header.modes.tutorial} - {texts.lead} + {texts.lead.map((sentence) => ( + + {sentence} + + ))} {tutorialStages.map((stage, index) => (
  • - + + + {/* The status goes under the title rather than beside it, to leave the title room */} - - {texts.stageNumber(index + 1)} - - + {texts.stageTexts[stage.id].title} + {clearedStages.has(stage.id) && ( + } + label={texts.cleared} + color={theme.colors.primary} + /> + )} + {stage.id === nextStage && ( + } + label={texts.upNext} + color={theme.colors.tutorial} + /> + )} - {clearedStages.has(stage.id) && ( - - - {texts.cleared} - - )}
  • diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 683f8d7..062ea4e 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -65,6 +65,7 @@ import CCComponentEditor from "../edit/Editor"; import { OutlinedNodeIdsContext } from "../edit/Editor/outlinedNodes"; import type { OffersComponent } from "../edit/placement"; import SidePanel from "../edit/SidePanel"; +import { StageNumber } from "./StageNumber"; import { StageText } from "./StageText"; function SectionHeading({ children }: { children: ReactNode }) { @@ -236,18 +237,19 @@ function StageView({ stage }: { stage: TutorialStage }) { {texts.stages} -
    - - {texts.stageNumber(stageIndex + 1)} - - - {stageTexts.title} - -
    + + + {stageTexts.title} +
    {texts.goalHeading} diff --git a/src/tutorial/progress.test.ts b/src/tutorial/progress.test.ts index 9eb6352..70d067d 100644 --- a/src/tutorial/progress.test.ts +++ b/src/tutorial/progress.test.ts @@ -3,8 +3,10 @@ import { stubLocalStorage } from "../store/testUtils"; import { forgetClearedStages, markStageCleared, + nextStageOf, readClearedStages, } from "./progress"; +import { tutorialStageIds } from "./stages"; let saved: Map; beforeEach(() => { @@ -34,3 +36,15 @@ describe("tutorial progress", () => { expect(readClearedStages().size).toBe(0); }); }); + +describe("nextStageOf", () => { + it("is the first stage not cleared, even before one cleared out of order", () => { + expect(nextStageOf(new Set())).toBe("and"); + expect(nextStageOf(new Set(["and", "a-only"]))).toBe("xor"); + expect(nextStageOf(new Set(["and", "full-adder"]))).toBe("a-only"); + }); + + it("is none once every stage is cleared", () => { + expect(nextStageOf(new Set(tutorialStageIds))).toBeUndefined(); + }); +}); diff --git a/src/tutorial/progress.ts b/src/tutorial/progress.ts index ad0e2d5..ce50293 100644 --- a/src/tutorial/progress.ts +++ b/src/tutorial/progress.ts @@ -1,4 +1,8 @@ -import { isTutorialStageId, type TutorialStageId } from "./stages"; +import { + isTutorialStageId, + type TutorialStageId, + tutorialStageIds, +} from "./stages"; const progressStorageKey = "ccTutorialProgress"; @@ -37,3 +41,9 @@ export function forgetClearedStages(): void { console.warn("Could not forget the tutorial progress", error); } } + +export function nextStageOf( + cleared: ReadonlySet, +): TutorialStageId | undefined { + return tutorialStageIds.find((id) => !cleared.has(id)); +} diff --git a/src/tutorial/stageText.test.ts b/src/tutorial/stageText.test.ts index 36e445b..4c8fda6 100644 --- a/src/tutorial/stageText.test.ts +++ b/src/tutorial/stageText.test.ts @@ -1,6 +1,13 @@ import { describe, expect, it } from "vitest"; -import { messagesByLanguage } from "../i18n/messages"; -import { tutorialStageIds } from "./stages"; +import { languages, messagesByLanguage } from "../i18n/messages"; +import { definitions } from "../store/intrinsics/definitions"; +import { + isTutorialStageId, + tutorialPartIds, + tutorialParts, + tutorialStageIds, + tutorialStages, +} from "./stages"; import { parseStageText, type StageTextSegment } from "./stageText"; describe("parseStageText", () => { @@ -68,3 +75,35 @@ describe("the stage texts", () => { }, ); }); + +describe("the names in stage texts", () => { + // A part handed over is named by its title, so a renamed title must be renamed in the + // texts too + it.each(languages)("are pins, parts or titles in %s", (language) => { + const texts = messagesByLanguage[language].tutorial; + const known = new Set([ + ...Object.values(definitions).flatMap((definition) => [ + definition.name, + ...definition.allPins.map((pin) => pin.name), + ]), + ...[...tutorialStages, ...tutorialParts].flatMap(({ check }) => [ + ...check.inputs.map(({ name }) => name), + ...check.outputs, + ]), + ...[...tutorialStageIds, ...tutorialPartIds].map((id) => + isTutorialStageId(id) + ? texts.stageTexts[id].title + : texts.partTitles[id], + ), + ]); + const names = tutorialStageIds.flatMap((id) => + [...texts.stageTexts[id].goal, ...texts.stageTexts[id].steps].flatMap( + (text) => + parseStageText(text).flatMap((segment) => + segment.type === "name" ? [segment.name] : [], + ), + ), + ); + expect(names.filter((name) => !known.has(name))).toEqual([]); + }); +});