From 98cc05990de9974e07b59f7ea5d74e3143f7abf2 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Sat, 21 Nov 2026 01:56:13 +0900 Subject: [PATCH 1/3] refactor: rename StageText to MarkedText, as part descriptions will use it too Co-Authored-By: Claude Opus 5.5 --- src/common/markedText.test.ts | 33 ++++++++++++++++ .../stageText.ts => common/markedText.ts} | 26 ++++++------- .../MarkedText.tsx} | 28 ++++++------- src/components/controlLooks.ts | 2 +- src/pages/tutorial/stage.tsx | 6 +-- src/tutorial/stageText.test.ts | 39 ++----------------- 6 files changed, 68 insertions(+), 66 deletions(-) create mode 100644 src/common/markedText.test.ts rename src/{tutorial/stageText.ts => common/markedText.ts} (67%) rename src/{pages/tutorial/StageText.tsx => components/MarkedText.tsx} (85%) diff --git a/src/common/markedText.test.ts b/src/common/markedText.test.ts new file mode 100644 index 0000000..5d3c09a --- /dev/null +++ b/src/common/markedText.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from "vitest"; +import { parseMarkedText } from "./markedText"; + +describe("parseMarkedText", () => { + it("cuts a text where it marks names, values and controls", () => { + expect(parseMarkedText("Turn {Start} [ON] and press .")).toEqual([ + { type: "text", text: "Turn " }, + { type: "name", name: "Start" }, + { type: "text", text: " " }, + { type: "value", value: [true], notation: "onOff" }, + { type: "text", text: " and press " }, + { type: "control", control: "check" }, + { type: "text", text: "." }, + ]); + }); + + it("reads a value of 0s and 1s bit by bit", () => { + expect(parseMarkedText("[0011]")).toEqual([ + { + type: "value", + value: [false, false, true, true], + notation: "digits", + }, + ]); + }); + + it.each(["", "[2]", "{Start", "Start}"])( + "refuses a mark it does not know: %s", + (text) => { + expect(() => parseMarkedText(text)).toThrow(); + }, + ); +}); diff --git a/src/tutorial/stageText.ts b/src/common/markedText.ts similarity index 67% rename from src/tutorial/stageText.ts rename to src/common/markedText.ts index 1cd9870..2589789 100644 --- a/src/tutorial/stageText.ts +++ b/src/common/markedText.ts @@ -1,8 +1,8 @@ -import type { BitNotation } from "../common/bitLabel"; import type { SimulationValue } from "../store/simulation"; +import type { BitNotation } from "./bitLabel"; -/** Things on the screen a stage text points at, drawn as they look there */ -export const stageTextControls = [ +/** Things on the screen a text points at, drawn as they look there */ +export const markedTextControls = [ "check", "constApply", "pinApply", @@ -13,20 +13,20 @@ export const stageTextControls = [ "nextStep", "enter", ] as const; -export type StageTextControl = (typeof stageTextControls)[number]; +export type MarkedTextControl = (typeof markedTextControls)[number]; -export type StageTextSegment = +export type MarkedTextSegment = | { type: "text"; text: string } /** a pin or a part, by the name the editor shows */ | { type: "name"; name: string } | { type: "value"; value: SimulationValue; notation: BitNotation } - | { type: "control"; control: StageTextControl }; + | { type: "control"; control: MarkedTextControl }; -function isControl(key: string): key is StageTextControl { - return stageTextControls.some((control) => control === key); +function isControl(key: string): key is MarkedTextControl { + return markedTextControls.some((control) => control === key); } -function parseValue(token: string): StageTextSegment { +function parseValue(token: string): MarkedTextSegment { if (token === "ON" || token === "OFF") { return { type: "value", value: [token === "ON"], notation: "onOff" }; } @@ -43,12 +43,12 @@ function parseValue(token: string): StageTextSegment { const markup = /\{([^{}]+)\}|\[([^[\]]+)\]|<([A-Za-z]+)>/g; /** - * A stage text cut where it marks a name as `{Start}`, a value as `[ON]` or `[0011]`, + * A text cut where it marks a name as `{Start}`, a value as `[ON]` or `[0011]`, * or a control as `` * @throws if a mark is not one of these, so that a typo shows in the tests */ -export function parseStageText(text: string): StageTextSegment[] { - const segments: StageTextSegment[] = []; +export function parseMarkedText(text: string): MarkedTextSegment[] { + const segments: MarkedTextSegment[] = []; let rest = 0; const pushText = (end: number) => { const plain = text.slice(rest, end); @@ -64,7 +64,7 @@ export function parseStageText(text: string): StageTextSegment[] { else if (value !== undefined) segments.push(parseValue(value)); else if (control !== undefined && isControl(control)) { segments.push({ type: "control", control }); - } else throw new Error(`${whole} is not a control a stage text can show`); + } else throw new Error(`${whole} is not a control a text can show`); rest = match.index + whole.length; } pushText(text.length); diff --git a/src/pages/tutorial/StageText.tsx b/src/components/MarkedText.tsx similarity index 85% rename from src/pages/tutorial/StageText.tsx rename to src/components/MarkedText.tsx index f935ceb..664d6ca 100644 --- a/src/pages/tutorial/StageText.tsx +++ b/src/components/MarkedText.tsx @@ -6,21 +6,21 @@ import { } from "@mui/icons-material"; import { Box, Button, type ButtonProps, ToggleButton } from "@mui/material"; import type { ReactNode } from "react"; +import { + type MarkedTextControl, + type MarkedTextSegment, + parseMarkedText, +} from "../common/markedText"; +import { useMessages } from "../i18n"; import { autoToggleButtonLook, checkButtonLook, pinApplyButtonLook, valueApplyButtonLook, withLookSx, -} from "../../components/controlLooks"; -import { ValueView } from "../../components/ValueView"; -import { visuallyHiddenSx } from "../../components/visuallyHidden"; -import { useMessages } from "../../i18n"; -import { - parseStageText, - type StageTextControl, - type StageTextSegment, -} from "../../tutorial/stageText"; +} from "./controlLooks"; +import { ValueView } from "./ValueView"; +import { visuallyHiddenSx } from "./visuallyHidden"; // The real controls with their looks, smaller and not to be pressed. The label is read // out from a hidden copy, as the control itself is hidden from screen readers. @@ -77,7 +77,7 @@ function InlineButton({ look, label }: { look: ButtonProps; label: string }) { ); } -function ControlView({ control }: { control: StageTextControl }) { +function ControlView({ control }: { control: MarkedTextControl }) { const messages = useMessages(); const roundIcon = (icon: ReactNode) => ( ( +/** A text with the names, values and controls it marks drawn as on the screen */ +export function MarkedText({ text }: { text: string }) { + return parseMarkedText(text).map((segment, index) => ( // biome-ignore lint/suspicious/noArrayIndexKey: the segments of a text keep their order )); diff --git a/src/components/controlLooks.ts b/src/components/controlLooks.ts index 0d44078..0b4bc8f 100644 --- a/src/components/controlLooks.ts +++ b/src/components/controlLooks.ts @@ -6,7 +6,7 @@ import type { } from "@mui/material"; import { theme } from "../style"; -// The looks of controls a stage text draws too, so that the two cannot drift apart +// The looks of controls a marked text draws too, so that the two cannot drift apart export const checkButtonLook = { variant: "contained", diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 062ea4e..faa1058 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -26,6 +26,7 @@ import { import { BitNotationContext } from "../../components/bitNotation"; import { ConfirmDialog } from "../../components/ConfirmDialog"; import { checkButtonLook } from "../../components/controlLooks"; +import { MarkedText } from "../../components/MarkedText"; import { PartDescription, PartDescriptionView, @@ -66,7 +67,6 @@ 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 }) { return ( @@ -255,7 +255,7 @@ function StageView({ stage }: { stage: TutorialStage }) { {stageTexts.goal.map((paragraph) => ( - + ))} @@ -278,7 +278,7 @@ function StageView({ stage }: { stage: TutorialStage }) { {stageTexts.steps.map((step) => ( - + ))} diff --git a/src/tutorial/stageText.test.ts b/src/tutorial/stageText.test.ts index 4c8fda6..194db13 100644 --- a/src/tutorial/stageText.test.ts +++ b/src/tutorial/stageText.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from "vitest"; +import { type MarkedTextSegment, parseMarkedText } from "../common/markedText"; import { languages, messagesByLanguage } from "../i18n/messages"; import { definitions } from "../store/intrinsics/definitions"; import { @@ -8,43 +9,11 @@ import { tutorialStageIds, tutorialStages, } from "./stages"; -import { parseStageText, type StageTextSegment } from "./stageText"; - -describe("parseStageText", () => { - it("cuts a text where it marks names, values and controls", () => { - expect(parseStageText("Turn {Start} [ON] and press .")).toEqual([ - { type: "text", text: "Turn " }, - { type: "name", name: "Start" }, - { type: "text", text: " " }, - { type: "value", value: [true], notation: "onOff" }, - { type: "text", text: " and press " }, - { type: "control", control: "check" }, - { type: "text", text: "." }, - ]); - }); - - it("reads a value of 0s and 1s bit by bit", () => { - expect(parseStageText("[0011]")).toEqual([ - { - type: "value", - value: [false, false, true, true], - notation: "digits", - }, - ]); - }); - - it.each(["", "[2]", "{Start", "Start}"])( - "refuses a mark it does not know: %s", - (text) => { - expect(() => parseStageText(text)).toThrow(); - }, - ); -}); /** What a stage text marks other than names, which a language may translate */ function marksOf(text: string) { - return parseStageText(text) - .flatMap((segment: StageTextSegment) => { + return parseMarkedText(text) + .flatMap((segment: MarkedTextSegment) => { if (segment.type === "value") { return [segment.value.map((bit) => (bit ? 1 : 0)).join("")]; } @@ -99,7 +68,7 @@ describe("the names in stage texts", () => { const names = tutorialStageIds.flatMap((id) => [...texts.stageTexts[id].goal, ...texts.stageTexts[id].steps].flatMap( (text) => - parseStageText(text).flatMap((segment) => + parseMarkedText(text).flatMap((segment) => segment.type === "name" ? [segment.name] : [], ), ), From 4095e1e69790f9555c737c5071972586dbe7aed2 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Sat, 21 Nov 2026 02:00:08 +0900 Subject: [PATCH 2/3] feat: mark names, values and buttons in part descriptions, and say how parts work on many bits The descriptions of parts and their pins now draw names, values and the "Apply", "Add" and "Remove" buttons as the stage texts do. And, Or, Not, Xor, True and False described only one-bit values, and FlipFlop wrote its first output as 0 whatever its width. The pin note spoke of one field, while a split pin has a field for each pin and a "Remove" button too. Co-Authored-By: Claude Opus 5.5 --- src/common/markedText.ts | 2 + src/common/markedTextTestUtils.ts | 14 +++++ src/components/MarkedText.tsx | 15 ++++++ src/components/PartDescription.test.ts | 51 ++++++++++++++++--- src/components/PartDescription.tsx | 9 +++- src/components/controlLooks.ts | 6 +++ src/i18n/en.ts | 34 +++++++------ src/i18n/ja.ts | 35 +++++++------ .../components/NodePinPropertyEditor.tsx | 7 ++- src/tutorial/stageText.test.ts | 16 +----- 10 files changed, 129 insertions(+), 60 deletions(-) create mode 100644 src/common/markedTextTestUtils.ts diff --git a/src/common/markedText.ts b/src/common/markedText.ts index 2589789..fd3fae2 100644 --- a/src/common/markedText.ts +++ b/src/common/markedText.ts @@ -6,6 +6,8 @@ export const markedTextControls = [ "check", "constApply", "pinApply", + "pinAdd", + "pinRemove", "auto", "play", "edit", diff --git a/src/common/markedTextTestUtils.ts b/src/common/markedTextTestUtils.ts new file mode 100644 index 0000000..e9260e3 --- /dev/null +++ b/src/common/markedTextTestUtils.ts @@ -0,0 +1,14 @@ +import { type MarkedTextSegment, parseMarkedText } from "./markedText"; + +/** What a text marks other than names, which a language may translate */ +export function marksOf(text: string) { + return parseMarkedText(text) + .flatMap((segment: MarkedTextSegment) => { + if (segment.type === "value") { + return [segment.value.map((bit) => (bit ? 1 : 0)).join("")]; + } + if (segment.type === "control") return [`<${segment.control}>`]; + return []; + }) + .toSorted(); +} diff --git a/src/components/MarkedText.tsx b/src/components/MarkedText.tsx index 664d6ca..96dd7e0 100644 --- a/src/components/MarkedText.tsx +++ b/src/components/MarkedText.tsx @@ -16,6 +16,7 @@ import { autoToggleButtonLook, checkButtonLook, pinApplyButtonLook, + pinFieldButtonLook, valueApplyButtonLook, withLookSx, } from "./controlLooks"; @@ -128,6 +129,20 @@ function ControlView({ control }: { control: MarkedTextControl }) { return ( ); + case "pinAdd": + return ( + + ); + case "pinRemove": + return ( + + ); case "auto": return ( diff --git a/src/components/PartDescription.test.ts b/src/components/PartDescription.test.ts index 9243bac..e14f358 100644 --- a/src/components/PartDescription.test.ts +++ b/src/components/PartDescription.test.ts @@ -1,29 +1,40 @@ import { describe, expect, it } from "vitest"; -import { messagesByLanguage } from "../i18n/messages"; +import { parseMarkedText } from "../common/markedText"; +import { marksOf } from "../common/markedTextTestUtils"; +import { languages, messagesByLanguage } from "../i18n/messages"; import { and, - and_n, broadcast, decompose, + definitions, display, } from "../store/intrinsics/definitions"; +import { ccIntrinsicComponentTypes } from "../store/intrinsics/types"; import { pinNotesOf } from "./PartDescription"; const { en, ja } = messagesByLanguage; +const allDefinitions = Object.values(definitions); + +function textsOf(language: (typeof languages)[number]) { + const messages = messagesByLanguage[language]; + return [ + ...Object.values(ccIntrinsicComponentTypes).map( + (type) => messages.parts.summaries[type], + ), + ...allDefinitions.flatMap((definition) => pinNotesOf(messages, definition)), + ]; +} describe("pinNotesOf", () => { it("tells how to set a pin whose bit width the player chooses", () => { expect(pinNotesOf(en, broadcast)).toEqual([ - 'The number in the Out pin is its number of bits. To change it, click the pin while editing, change the field and press "Apply".', + "The number in the {Out} pin is its number of bits. To change it, click the pin while editing, change the number in the field and press .", ]); }); - it("tells how to add pins where a pin can be split", () => { - expect(pinNotesOf(en, and_n)).toEqual([ - 'The number in the In pin is its number of bits. To change it, click the pin while editing, change the field and press "Apply". Each field added with "Add" becomes another In pin.', - ]); + it("tells how to add and remove pins where a pin can be split", () => { expect(pinNotesOf(ja, decompose)).toEqual([ - "Out のピンの中の数字は、そのピンのビット数。編集中にピンをクリックし、出てきた欄で変えて「適用」を押す。「追加」で欄を増やすと、Out のピンも増える。", + "{Out} のピンの中の数字は、そのピンのビット数。編集中にピンをクリックすると、{Out} のピンごとの欄が上から順に並ぶ。でいちばん下に欄を足し、でいちばん下の欄を消せる。欄の数字を書きかえてを押すと、{Out} のピンが欄のとおりになる。", ]); }); @@ -32,3 +43,27 @@ describe("pinNotesOf", () => { expect(pinNotesOf(en, display)).toEqual([]); }); }); + +describe("the part descriptions", () => { + it("mark the same values and controls in every language", () => { + const japanese = textsOf("ja"); + for (const [index, english] of textsOf("en").entries()) { + expect(marksOf(japanese[index] ?? "")).toEqual(marksOf(english)); + } + }); + + it.each(languages)("name only parts and pins in %s", (language) => { + const known = new Set( + allDefinitions.flatMap((definition) => [ + definition.name, + ...definition.allPins.map((pin) => pin.name), + ]), + ); + const names = textsOf(language).flatMap((text) => + parseMarkedText(text).flatMap((segment) => + segment.type === "name" ? [segment.name] : [], + ), + ); + expect(names.filter((name) => !known.has(name))).toEqual([]); + }); +}); diff --git a/src/components/PartDescription.tsx b/src/components/PartDescription.tsx index afe4d5d..f04987d 100644 --- a/src/components/PartDescription.tsx +++ b/src/components/PartDescription.tsx @@ -4,6 +4,7 @@ import type { CCComponent } from "../store/component"; import { IntrinsicComponentDefinition } from "../store/intrinsics/base"; import { definitionByComponentId } from "../store/intrinsics/definitions"; import { type TruthTable, truthTableOf } from "../store/intrinsics/truthTable"; +import { MarkedText } from "./MarkedText"; import { TruthTableView } from "./TruthTableView"; export function partSummary( @@ -62,10 +63,14 @@ export function PartDescriptionView({ > {name} - {summary && {summary}} + {summary && ( + + + + )} {notes.map((note) => ( - {note} + ))} {table && ( diff --git a/src/components/controlLooks.ts b/src/components/controlLooks.ts index 0b4bc8f..aef57b3 100644 --- a/src/components/controlLooks.ts +++ b/src/components/controlLooks.ts @@ -24,6 +24,12 @@ export const pinApplyButtonLook = { size: "small", } as const satisfies ButtonProps; +/** Of "Add" and "Remove", which change how many fields the pin editor has */ +export const pinFieldButtonLook = { + variant: "outlined", + size: "small", +} as const satisfies ButtonProps; + export const autoToggleButtonLook = { size: "small", } as const satisfies Partial; diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 9be7f8e..74c7201 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -94,7 +94,7 @@ const stageTexts: Record = { " turns {Up} [ON] until {Count} reaches [1001], then [OFF] for two time steps to see that {Count} stays at [1001] and {Carry} stays [OFF], and then [ON] again to see that {Count} goes back to [0000].", ], steps: [ - 'The {Const}, {Broadcast} and {And} on the left send [0001] to {B} of "{Adding four digits}" when {Up} is [ON], and [0000] when it is [OFF]. A {Broadcast} spreads a one-bit value over several bits: [1111] for [ON], [0000] for [OFF]. An {And} given values of several bits makes each bit [1] only where both are [1].', + 'The {Const}, {Broadcast} and {And} on the left send [0001] to {B} of "{Adding four digits}" when {Up} is [ON], and [0000] when it is [OFF]. A {Broadcast} spreads a one-bit value over two or more bits: [1111] for [ON], [0000] for [OFF]. An {And} given values of two or more bits makes each bit [1] only where both are [1].', "Make {Carry}. From [0000] to [1001], only [1001] has [1] in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the {Decompose} at the bottom with an {And}, join its output and {Up} with another {And}, and connect that to {Carry}.", "Place a {Broadcast} and click the pin on its right. The box that appears is the bit width, the number of bits of the output. Change its 1 to 4 and press , and the output has four bits. Do this before connecting it.", "Go back to [0000] when {Carry} is [ON]. {S} is not connected to the {FlipFlop} yet. Connect the output of the {And} that goes to {Carry} to a {Not} as well to turn it over, spread it to four bits with that {Broadcast}, join it and {S} with an {And}, and connect the {And} to the input of the {FlipFlop}.", @@ -128,32 +128,34 @@ export const en = { }, parts: { summaries: { - AND: "ON only when both inputs are ON.", - OR: "ON when at least one input is ON.", - NOT: "Turns ON into OFF, and OFF into ON.", - XOR: "ON when exactly one input is ON.", - TRUE: "Always ON.", - FALSE: "Always OFF.", + AND: "[ON] only when both inputs are [ON]. Given values of two or more bits, it makes each bit [1] only where both are [1].", + OR: "[ON] when at least one input is [ON]. Given values of two or more bits, it makes each bit [1] where at least one is [1].", + NOT: "Swaps [ON] and [OFF]. Given a value of two or more bits, it swaps [1] and [0] in each bit.", + XOR: "[ON] when exactly one input is [ON]. Given values of two or more bits, it makes each bit [1] where exactly one is [1].", + TRUE: "Always [ON]. In a value of two or more bits, every bit is [1].", + FALSE: "Always [OFF]. In a value of two or more bits, every bit is [0].", DECOMPOSE: - "Splits a value of several bits, the higher digits to the upper pins.", + "Splits a value of two or more bits, the higher digits to the upper pins.", AGGREGATE: "Joins values into one, the upper pins as the higher digits.", FLIPFLOP: - "Outputs what it received at the time step before (0 at the first time step).", + "Outputs what it received at the time step before. At the first time step, it outputs [OFF], or a value whose bits are all [0] if it has two or more bits.", CONST: "Always outputs the value written in it.", - BROADCAST: "Repeats a one-bit value over several bits.", - ANDN: "ON only when every bit of In is 1.", - ORN: "ON when any bit of In is 1.", + BROADCAST: "Repeats a one-bit value over two or more bits.", + ANDN: "[ON] only when every bit of {In} is [1].", + ORN: "[ON] when any bit of {In} is [1].", SEVEN_SEGMENT: - "Turns the 4-bit value of In into the shape of a hexadecimal character, 0 to F. Out is a 28-bit value of a picture 4 pixels wide and 7 high, with 1 for the character. While editing, the gear button sets its pixel order.", + "Turns the 4-bit value of {In} into the shape of a hexadecimal character, 0 to F. {Out} is a 28-bit value of a picture 4 pixels wide and 7 high, with [1] for the character. While editing, the gear button sets its pixel order.", DISPLAY: - "While playing, shows the value of Pixels as a picture, one bit per pixel (1 is black, 0 is white). From the highest digit, the pixels go from the top left row by row in row-major order, or column by column in column-major order. While editing, the gear button sets the resolution and the pixel order.", + "While playing, shows the value of {Pixels} as a picture, one bit per pixel ([1] is black, [0] is white). From the highest digit, the pixels go from the top left row by row in row-major order, or column by column in column-major order. While editing, the gear button sets the resolution and the pixel order.", INPUT: - "Adds an input to the component it is placed in. Where that component is placed as a part, the input is a pin on its left. While playing, its value can be changed on the placed Input.", + "Adds an input to the component it is placed in. Where that component is placed as a part, the input is a pin on its left. While playing, its value can be changed on the placed {Input}.", OUTPUT: "Adds an output to the component it is placed in. Where that component is placed as a part, the output is a pin on its right. While playing, it shows the value it receives.", } satisfies Record, pinBitWidth: (pinName: string, canAddPins: boolean) => - `The number in the ${pinName} pin is its number of bits. To change it, click the pin while editing, change the field and press "Apply".${canAddPins ? ` Each field added with "Add" becomes another ${pinName} pin.` : ""}`, + canAddPins + ? `The number in an {${pinName}} pin is its number of bits. Click the pin while editing, and a field for each {${pinName}} pin appears, from the top. adds a field at the bottom, and removes the bottom one. Change the numbers in the fields and press , and the {${pinName}} pins follow the fields.` + : `The number in the {${pinName}} pin is its number of bits. To change it, click the pin while editing, change the number in the field and press .`, about: (name: string) => `About ${name}`, ofStage: "Available parts", }, diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 9fe1461..f8ae22a 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -12,30 +12,33 @@ export const ja: Messages = { }, parts: { summaries: { - AND: "両方が ON のときだけ ON。", - OR: "少なくとも一方が ON なら ON。", - NOT: "ON と OFF を逆にする。", - XOR: "片方だけが ON のとき ON。", - TRUE: "いつも ON。", - FALSE: "いつも OFF。", - DECOMPOSE: "何ビットもある値を、上の桁から順に、上のピンへ分ける。", + AND: "両方が [ON] のときだけ [ON]。2ビット以上の値では、ビットごとに、両方が [1] のビットだけ [1] になる。", + OR: "少なくとも一方が [ON] なら [ON]。2ビット以上の値では、ビットごとに、少なくとも一方が [1] のビットが [1] になる。", + NOT: "[ON] と [OFF] を逆にする。2ビット以上の値では、ビットごとに [1] と [0] を逆にする。", + XOR: "片方だけが [ON] のとき [ON]。2ビット以上の値では、ビットごとに、片方だけが [1] のビットが [1] になる。", + TRUE: "いつも [ON]。2ビット以上の値では、すべてのビットが [1] になる。", + FALSE: "いつも [OFF]。2ビット以上の値では、すべてのビットが [0] になる。", + DECOMPOSE: "2ビット以上の値を、上の桁から順に、上のピンへ分ける。", AGGREGATE: "上のピンを上の桁として、値を1つにまとめる。", - FLIPFLOP: "1つ前のステップで受け取った値を出す(最初のステップでは 0)。", + FLIPFLOP: + "1つ前のステップで受け取った値を出す。最初のステップでは [OFF] を、2ビット以上の値ならすべてのビットが [0] の値を出す。", CONST: "中に書いた値をいつも出す。", - BROADCAST: "1ビットの値を、同じ値が並んだ何ビットもの値に広げる。", - ANDN: "In のビットがすべて 1 のときだけ ON。", - ORN: "In のどれかのビットが 1 なら ON。", + BROADCAST: "1ビットの値を、同じ値が並んだ2ビット以上の値に広げる。", + ANDN: "{In} のビットがすべて [1] のときだけ [ON]。", + ORN: "{In} のどれかのビットが [1] なら [ON]。", SEVEN_SEGMENT: - "In の4ビットの値を、16進数の1文字(0〜F)の形にする。Out は、横4・縦7ピクセルの絵を表す28ビットの値で、文字の部分が 1。ピクセルの並び順は、編集中に歯車のボタンで変えられる。", + "{In} の4ビットの値を、16進数の1文字(0〜F)の形にする。{Out} は、横4・縦7ピクセルの絵を表す28ビットの値で、文字の部分が [1]。ピクセルの並び順は、編集中に歯車のボタンで変えられる。", DISPLAY: - "再生中、Pixels の値を、1ビットを1ピクセルとして絵にする(1 は黒、0 は白)。上の桁から順に、行優先なら左上から横に1行ずつ、列優先なら縦に1列ずつ並ぶ。解像度とピクセルの並び順は、編集中に歯車のボタンで変えられる。", + "再生中、{Pixels} の値を、1ビットを1ピクセルとして絵にする([1] は黒、[0] は白)。上の桁から順に、行優先なら左上から横に1行ずつ、列優先なら縦に1列ずつ並ぶ。解像度とピクセルの並び順は、編集中に歯車のボタンで変えられる。", INPUT: - "置いた先のコンポーネントに、入力を1つ足す。そのコンポーネントを部品として置くと、左側のピンになる。再生中は、置いた Input の上で値を変えられる。", + "置いた先のコンポーネントに、入力を1つ足す。そのコンポーネントを部品として置くと、左側のピンになる。再生中は、置いた {Input} の上で値を変えられる。", OUTPUT: "置いた先のコンポーネントに、出力を1つ足す。そのコンポーネントを部品として置くと、右側のピンになる。再生中は、受け取った値を見せる。", }, pinBitWidth: (pinName, canAddPins) => - `${pinName} のピンの中の数字は、そのピンのビット数。編集中にピンをクリックし、出てきた欄で変えて「適用」を押す。${canAddPins ? `「追加」で欄を増やすと、${pinName} のピンも増える。` : ""}`, + canAddPins + ? `{${pinName}} のピンの中の数字は、そのピンのビット数。編集中にピンをクリックすると、{${pinName}} のピンごとの欄が上から順に並ぶ。でいちばん下に欄を足し、でいちばん下の欄を消せる。欄の数字を書きかえてを押すと、{${pinName}} のピンが欄のとおりになる。` + : `{${pinName}} のピンの中の数字は、そのピンのビット数。編集中にピンをクリックし、出てきた欄の数字を書きかえてを押す。`, about: (name) => `${name} について`, ofStage: "使える部品", }, @@ -235,7 +238,7 @@ export const ja: Messages = { "は、{Up} を [ON] にして {Count} を [1001] まで進めたあと、2ステップだけ {Up} を [OFF] にして、{Count} が [1001] のまま止まり、{Carry} が [OFF] のままかを調べます。そのあと {Up} をまた [ON] にして、[0000] に戻るかを調べます。", ], steps: [ - "左の {Const}・{Broadcast}・{And} は、{Up} が [ON] のときは [0001] を、[OFF] のときは [0000] を「{4桁の足し算}」の {B} に送っています。{Broadcast} は、1ビットの値を、同じ値が並んだ何ビットもの値に広げます([ON] なら [1111]、[OFF] なら [0000])。{And} に何ビットもの値をつなぐと、ビットごとに、両方が [1] のビットだけ [1] になります。", + "左の {Const}・{Broadcast}・{And} は、{Up} が [ON] のときは [0001] を、[OFF] のときは [0000] を「{4桁の足し算}」の {B} に送っています。{Broadcast} は、1ビットの値を、同じ値が並んだ2ビット以上の値に広げます([ON] なら [1111]、[OFF] なら [0000])。{And} に2ビット以上の値をつなぐと、ビットごとに、両方が [1] のビットだけ [1] になります。", "{Carry} を作ります。[0000] から [1001] のうち、8の位と1の位がどちらも [1] なのは [1001] だけです。一番下の {Decompose} の右側の、一番上(8の位)と一番下(1の位)のピンを {And} でまとめ、その出力と {Up} をもう1つの {And} でまとめて、{Carry} につなぎます。", "{Broadcast} を置き、右側のピンをクリックします。出てきた欄はビット幅、つまり出力のビット数です。1 を 4 に書きかえてを押すと、出力が4ビットになります。線をつなぐ前にしておきます。", "{Carry} が [ON] のときに [0000] に戻す部分を作ります。{S} はまだ {FlipFlop} につながっていません。{Carry} につないだ {And} の出力を {Not} にもつないで反対にし、その {Broadcast} で4ビットに広げ、{S} と {And} でまとめて、{FlipFlop} の入力につなぎます。", diff --git a/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx b/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx index 1e43c37..3b8c7f4 100644 --- a/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx +++ b/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx @@ -6,6 +6,7 @@ import invariant from "tiny-invariant"; import { rect } from "../../../../common/rect"; import { pinApplyButtonLook, + pinFieldButtonLook, withLookSx, } from "../../../../components/controlLooks"; import { useMessages } from "../../../../i18n"; @@ -158,9 +159,8 @@ export function CCComponentEditorNodePinPropertyEditor() { componentPinAttributes.bitWidthPolicy.isSplittable && ( <>