Skip to content

feat(tutorial): hand earlier stages' components over as finished parts - #100

Merged
Rn86222 merged 3 commits into
mainfrom
feat/given-parts
Nov 19, 2026
Merged

Rn86222 merged 3 commits into
mainfrom
feat/given-parts

Conversation

@Rn86222

@Rn86222 Rn86222 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Later stages are meant to build on earlier ones: a half adder becomes part of a full adder, and so on up to the stopwatch. A visitor may start from any stage, so a stage has to hand over the earlier parts already built. This PR adds that, and uses it by splitting the old second stage in two.

  • Solutions: every stage has a reference solution (solve), built with StageCircuit through the same stores the editor uses. A test runs every solution through Check and makes sure it only uses parts the stage offers.
  • Given parts: a stage lists earlier stages in givenParts. When the stage is laid out, their components are built from their solutions (and from the parts those are given), named after their stages, and offered in the side panel. "Available parts" lists them with their tables.
  • Stage 2 split:
    • "Only switch A" (A ON and B OFF) joins two parts from And, Or and Not.
    • "Only one switch" (XOR, keeping the id xor) is built from two "Only switch A" parts and Or. Its goal says the part is ready to use.
  • Inside a given part: the player may open it and change it.
    • Its Input and Output nodes are kept like the stage's own pins, and its properties button is hidden.
    • It offers the parts of its own stage, so a deleted gate can be put back, and no new pins.
  • Saves from before: a saved stage that lacks a part it now hands over gets the part added, and the player's circuit stays.
  • Part descriptions: PartDescription is split into the intrinsic lookup and PartDescriptionView, which given parts use with their stage's table.

Not in this PR

  • Each stage has its own store, so a given part is the reference solution, not the circuit the player built in the earlier stage. Opening it shows that stage's answer.
  • A given part is named in the language used when the stage was first opened, like the stage's own component. Now that stage 3's goal names the part, switching languages shows the mismatch. This is already on the list to fix.
  • Nodes and wires a stage places in its own component (Decompose, Display and so on) will come with the stage that needs them.
  • Stage 1's text, which is mostly how to use the editor, will be split into numbered steps next.

Testing

  • npx vitest run (190 tests), npx tsc -p . and npx biome check src pass. New tests cover:
    • every stage cleared by its solution, made only of the parts it offers
    • given parts coming from earlier stages only, laid out with a solution that passes their own stage
    • the pins of a given part kept, and what is offered inside it compared with the stage and the player's own components
    • a stage with a given part restored as saved, and a save without the part getting it added while keeping the player's component
  • Checked in the browser: the three stages in the list, clearing stages 2 and 3, stage 3 offering Or and "Only switch A" with their tables, and inside "Only switch A" the protected pins, the gates offered again and its layout.

🤖 Generated with Claude Code

Rn86222 and others added 3 commits November 19, 2026 23:41
Each stage now has a reference solution, built with StageCircuit through the same
stores the editor uses. A stage can list earlier stages in givenParts: their
components are laid out with their solutions and offered as parts. A saved stage
that lacks one is laid out anew.

The old second stage (exactly one switch from And, Or and Not) is split in two:
"Only switch A" joins two parts, and "Only one switch" builds on it as a given
part with Or. Given parts are listed with their tables under Available parts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom before

- The Input and Output nodes of a part handed over are kept like the stage's own,
  and its properties button is hidden.
- Editing a part handed over offers the parts of its own stage, so a deleted gate
  can be put back, and no new pins.
- Given parts are collected down every level.
- A save without a part that is now handed over gets the part added instead of
  being laid out anew, so the player's circuit stays.
- Solutions take intrinsic pins as objects, since those are named for display.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e hands over

Also name the missing pin when a solution asks for one, and drop comments that
only restated the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee with  Cloudflare Pages  Cloudflare Pages

Latest commit: db14e10
Status: ✅  Deploy successful!
Preview URL: https://99125c38.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev
Branch Preview URL: https://feat-given-parts.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev

View logs

@Rn86222
Rn86222 merged commit b85e166 into main Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant